nil

Objective C iPhone when to set object references to nil

Hello, I have been developing with objective C and the Cocoa framework for quite some time now. However it is still not absolutely clear to me, when am I supposed to set object references to nil. I know it is recommended to do so right before releasing an object that has a delegate and you should also do so in the viewDidUnload method f...

Dealing with expected nils

I expect to see a nil returned with the following embedded Ruby: <%=h [@inventory.origin.code] %> it returns a "NoMethodError nil object". However when an object is in fact present, it functions just fine (as expected). Therefore I created this test (following this advice): <b>origin_id:</b> <% if (@inventory.origin.code.nil? or @...

Replacement for use of nil in dictionaries in objective-C

Hey stackfolk, I'm working in the IPhone SDK, and am pretty new to objective-c. Right now I'm working with NSUserDefaults to save and restore setting on my IPhone app. In order to save the classes that have been created, I encode them into dictionary form, and then save the NSdictionary. My problem is that I can't find a reasonable w...

problem with if statement in Ruby on rails

I know this is probably rather trivial but i have had a lookt at previous questions and i've tried them but they still issued an error unfortunately :s My issue is the following, i have an html.erb file and i want a certain body text to be display given a condition or another if it is false i have <% if [email protected] do %> more cod...

RoR / Ruby delete nil elements from nested array

in a previous question i asked how to split an array into two equal pieces in ruby on rails. this is how i did it: >> a = [1,2,3,4,5] => [1, 2, 3, 4, 5] >> a.in_groups_of( (a.size/2.0).ceil ) if a.size > 0 => [[1, 2, 3], [4, 5, nil]] now i've got a nested array that contains nil elements if the size of the array is odd. how can i remo...

What describes nil best? What's that really?

Currently I understand it as a kind of "empty object". But what's it really? ...

Complete a Ruby Array

My application needs to deal with arrays of fixed size. The problem is that sometimes elements are nil but nil is a forbidden value. I think an easy way is to replace nil values with an the closest non-nil value (right before or right after). The nil values can be first, last or even multiples. Here are some examples of what I'm looking...

How to draw nil using cgcontext

I want to draw nil instead of the colors, because in the end I want the code to erase a section of the UIImageView in order that you can see what is behind the UIImageView. - (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event { UITouch *touch = [touches anyObject]; CGPoint currentPoint = [touch locationInView:self.v...

Check if a BOOL is set (can't be done with ==nil)

how do i check if a BOOL is set in objective-c (iphone)? i know that it can be done with an int or float this way: NSNumber *Num = [prefs floatForKey:@"key"]; for example ...

Objective-C: NSLog prints (null) for a var assigned to nil?

I'm curious why a variable overtly assigned to nil, prints as (null) with NSLog: NSString *myVar = nil; NSLog(@"%@", myVar); # RESULT: ' (null) ' This is of course quite confusing given all the different kinds of "nothingness" to figure out in Objective-C, and had me trying to test various IF NULL syntaxes. ...

Return nil on NSInteger return type method

I have the following UITableView DataSource method: - (NSInteger)tableView:(UITableView *)tableView sectionForSectionIndexTitle:(NSString *)title atIndex:(NSInteger)index On some items (i.e. section index titles) I just want to return "nothing", so that the table view won't jump to any section. I tried to return nil, but I get the "R...

how to add nil to nsmutablearray?

NSArray *array = [[NSArray alloc] initWithObjects:@"ΕΛΤΑ", @"ΕΛΤΑ COURIER", @"ACS", @"ACS ΕΞΩΤΕΡΙΚΟ", @"DHL", @"INTERATTICA", @"SPEEDEX", @"UPS", @"ΓΕΝΙΚΗ ΤΑΧΥΔΡΟΜΙΚΗ", @"ΜΕΤΑΦΟΡΙΚΕΣ ΕΞΩΤΕΡΙΚΟΥ", nil]; This is working because it has nil at the end. But I add objects l...

Treating nils in sort function

Hello, I don't know how to handle nils my sort function gets. When I have this checking in it, table.sort crashes after some calls. if a == nil then return false elseif b == nil then return true end With this error:invalid order function for sorting. But according to the documenatiton, sort function should return false, if a ...

Optional relationships in Core Data (deleting and checking)

Hi, I have a Core Data model with 2 entities: Game and ScoreTable. A Game has an optional relationship with ScoreTable. I usually check if a game has a ScoreTable by doing: NSManagedObject *scoreTable = [myGame valueForKey: @"scoreTable"]; if (scoreTable == nil) { // wtv } And when I want to delete a ScoreTable from a Game I'll j...

I want to use a controller with an expected nil; how do I handle this?

I have created a site which utilizes subdomains and searches whether or not the user is at: subdomain.domain.com or domain.com. If the user is in subdomain.domain.com, /views/layouts/application.html.erb appears, if the user is in domain.com /views/layouts/promo_site.html.erb appears. To accomplish this I closely followed Robby on Rails ...

Using ruby 'or equals' ||= on methods that return a hash or nil

I have a method that returns a hash, or nil: def person_of_age(age) some_hash = @array_of_hashes.select { |h| h.age == age }.last return some_hash end I want to use this hash like so: my_height = 170 my_age = 30 if my_height < self.person_of_age(my_age)['height'] puts "You are shorter than another person I know of the same age!"...

List without nil in Lisp

Hi! Allknowing that in lisp list must contain nil, but expression like (print (cons 1 (cons 3 2))) dont throw any errors and prints (1 3 . 2) Is it correct? I use GNU Clisp. Help me please ...

Objective-C how to check if a string is null

SO I wish to check to see if the item in my array [clientDataArray objectForKey:@"ClientCompany"] is nil. temp = [clientDataArray objectForKey:@"ClientCompany"]; if (temp != [NSNull null]) infofieldCompany.text = temp; So far I have been able to achieve this through the above code, but it does give me the warnings warning: '...

Are NULL and nil equivalent?

Actually my question here is: are null and nil equivalent or not? I have an example but I am confused when they are equal when they are not. NSNull *nullValue = [NSNull null]; NSArray *arrayWithNull = [NSArray arrayWithObject:nullValue]; NSLog(@"arrayWithNull: %@", arrayWithNull); id aValue = [arrayWithNull objectAtIndex:0]; if (aValu...

What's the effect in Ruby when you initialize with nil: x = String(nil)

What's the effect in Ruby when you pass nil to the constructor as in: s = String(nil) or a = Array(nil) Does this mean that s or a is nil or that s or a is an unpopulated object of type String or type Array? ...