nil

Clojure nil vs Java null?

Forgive me if I'm being obtuse, but I'm a little bit confused by the documentation about nil in Clojure. It says: nil has the same value as Java null. Does this mean that they're the same thing or are they different somehow? And does a NullPointerException mean that a Java null was encountered or would I also get this if nil was ...

Is It Necessary to Set Pointers to nil in Objective-C After release?

Title says it all I guess. Is there anything wrong with doing something like NSString * string = [ [ NSString alloc ] init ]; ... [ string release ]; or is there any value (other than best practice) in also adding string = nil; ? ...

A concise explanation of nil v. empty v. blank in Ruby on Rails

I find myself repeatedly looking for a clear definition of the differences of nil?, blank?, and empty? in Ruby on Rails. Here's the closest I've come: blank? objects are false, empty, or a whitespace string. For example, "", " ", nil, [], and {} are blank. nil? objects are instances of NilClass. empty? objects are class-specific, and...

Is there a way to trap messages sent to nil in Objective-C?

I've just been bitten by an annoying bug that was made obscure by the "send message to nil is ok" behaviour in Objective-C. I've seen http://stackoverflow.com/questions/156395/sending-a-message-to-nil, and the consensus seems to be 'thats how we roll' in Objective-C. Now, maybe I don't have enough experience in Objective-C, but it seem...

Attribute in Rails model appears to be nil when it's not

I have a very annoying and hard to figure out bug in my rails project. After having created a bunch of models and their relations, I want to list them. But I keep getting an Error "can't dup NilClass". That is, until I restart the server. Then I can list them just fine. Debugging this issue, it turns out that the Error gets raised in ...

what does sending a message to nil mean, and why is it a special case?

I just started reading the Objective-c tutorials, and there is a section on sending a message to nil. What does this mean? I can't seem to follow it. ...

Simple jQuery Question - Nil Values

I have a form and I'm using jQuery to validate that the have entered in the correct information into the textboxs. That works fine, because I have this code: var name = $("#business_name").val(); if (name == "") { $('#namelabel').show() $("#business_name").focus(); return false; } that tests to see if ...

Objective-C Difference between setting nil and releasing

I've learned that in dealloc you do [object release]; but in viewDidUnload (in a UIViewController subclass) you do self.object = nil. What is really the difference because self.object = nil (we're assuming object is a (nonatomic, retain) property) retains nil (which does nothing) and then releases the old value and then the reference cou...

Objective C : Release, Dealloc, and the Self reference.

So I thought I had all these questions all figured out. Then all of a sudden i get an error (a crash) i can't figure out. THen after doing research to remedy the crash, i notice everything that I thought i knew about these critical areas are somewhat wrong. Below are 8 questions im just going to shoot out there in hopes of somebody answ...

Objective C - Which syntax?

What syntax do you think is better/more readable? if(!myViewController.view.superview) or: if(myViewController.view.superview == nil) Thanks!! ...

IBOutlet instances are (null) after loading from NIB

I am working on an iPhone app and am getting (null) references to IBOutlet fields in my controller. I have a UIViewController subclass that is set as the File's Owner in my XIB. I have a set of UI elements that are wired into the controller. After loading from NIB and attempting to set properties on those UI elements, I find that they ar...

In Objective-C why should I check if self = [super init] is not nil?

Hey guys, I have a general question about writing init methods in Objective-C. I see it everywhere (Apple's code, books, open source code, etc.) that an init method should check if self = [super init] is not nil before continuing with initialisation. The default Apple template for an init method is: - (id) init { self = [super in...

setting objects to nil when releasing NSArray

When I get a memory warning I am releasing a bunch of objects stored in an NSMutableArray. [_children release]; I also need to recurse through objects at some point (potentially after a mem warning has happened), so I need to check if the objects are still around, which I do with comparison to nil- which isn't going to work because re...

UIViewController not working for the first time

MyController *myViewController = [[MyController alloc] initWithNibName:@"myView" bundle:nil]; The nib file myView.nib has 2 uiimageviews and 2 uilabels. When I first init myViewController, all the 4 subviews are set as 0x0. The second time I dont get such a behavior. ...

Ruby on Rails prevent nil error when it is assumed record may not exist

I am building a simple book check out application. One of the things that I need to do is determine if a book is checked out. I have my associations between my people and book classes setup through a book_check_out class. My goal is to use the checked_out property of book to determine if a book is presently checked out. However, in my pr...

Can't convert nil to string -- edited to restate all the failing attempts

At a point in my code, I expect current_part to sometimes be nil, and I want to run some code (inside an if block) when that's not the case. Using script/server --debugger, I've established that current_part is in fact nil at that point when the following errors occur. All the following versions generate the can't convert nil into Stri...

iPhone properties getting set to nil

I set a property with this declaration: @property (nonatomic,retain) NSDictionary *itemData; to a dictionary with 1 key - val pair. The table view in my view then gets the one value for the dictionary fine as a section header. But when I go back to access that very same value, it is nil. Any suggestions? I have been working on this f...

When to use nil and NULL in Objective C ?

This is a sample code: NSDictionary *myDictionary = [NSDictionary dictionary]; NSNumber *myNumber = [myDictionary valueForKey: @"MyNumber"]; NSLog(@"myNumber = %@", myNumber); // output myNumber = (null) if (myNumber == nil) NSLog(@"test 1 myNumber == nil"); if (myNumber == NULL) NSLog(@"test 2 myNumber == NULL"); if ([myN...

Can I get warnings for sending nil objects messages?

I'm aware that it's perfectly fine to send messages to nil objects in Objective-C. However, I am curious if there is any runtime support for flagging such situations. I can see this being useful in testing/debugging situations. ...

Ruby on rails session = nil

Hi, In a controller I have 2 actions def action1 session[:test]="test" render :text => session[:test] # output test end def action2 render :text => session[:test] # output nil end I perform first action1 so the session is set Then I perform action2 but session[:test] is nil So what am I doing wrong? ...