Usually, I would access such variables as properties that are lazy loaded, in which case the accessing code is simply:
self.x … and the accessor is - (NSString *) x { if (!_x) { _x = @“yo”; } return _x; } - Raheel On April 24, 2014 at 7:36:57 AM, Alex Zavatone (z...@mac.com) wrote: I was just asked yesterday if there is any shorthand in Objective-C for "if this thing = nil, then instantiate a new instance from the class" Something like this: NSString x; if ([x isEqualtoString:nil]) { x = @"yo"; } Feel free to replace NSString with any class. And we messed around a bit looking for any shorthand and though it looked like a terrible idea since the comparison is done against integers using the ternary operator, I'd like to know exactly why it's a terrible idea. NSString x; x = (x) ?: @"yo"; Thanks in advance. - Alex _______________________________________________ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: https://lists.apple.com/mailman/options/cocoa-dev/ahmadraheel%40gmail.com This email sent to ahmadrah...@gmail.com _______________________________________________ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com