Earlier quoted context omitted.
Maybe I'm misunderstanding, but how much effort are you talking about here? Skipping @synthesize on properties or using literal syntax where/when it makes sense wouldn't cause much additional cognitive load and you don't have to convert old code to use the new sugar.
It's not as simple as that when you're planning for the long term. Firstly you need to examine the changes and make sure that they aren't going to create any compatability problems, of the type "if you activate this option, then you can no longer link to libraries that don't use this option". Garbage collection in particular had a lot of those sorts of problems. But even if you can convince yourself that it is just s…
Objective-C literals for NSDictionary, NSArray, and NSNumber
41–50 of 58 posts
Re: Objective-C literals for NSDictionary, NSArray, and NSNumber
#42Earlier quoted context omitted.
Is it possible to see this straight C translation? Using Clang for example. I'm sort of aware of the "objc_msgSend" business, but would like to see more. Talking of OpenStep, after seeing some of those NeXT videos on HN the other day, I found a torrent of OpenStep 4.2 incl the dev tools. It's a VMware image and boots and runs just fine. Pretty nifty. Then I noticed OpenStep 5.0 redirects to Mac OS X on Wikipedia!
Quick example of calling a method that doesn't take any arguments and returns an object: id foo = [self bar]; is the same as: id foo = self.bar; which is also the same as: id foo = [self performSelector:@selector(bar)]; or: IMP barImp = [self methodForSelector:@selector(bar)]; id foo = barImp(self, @selector(bar); [1] and finally: id foo = ((id)(id, SEL)objc_msgSend)(self, @selector(bar)); [2, 3, 4] 1. Because we're…
objc_msgSend(self, @selector(bar));
And: objc_msgSend(self, @selector(performSelector:), @selector(bar));
?Re: Objective-C literals for NSDictionary, NSArray, and NSNumber
#43Earlier quoted context omitted.
Obj-C is essentially a preprocessor on top of a C compiler. Whether that C compiler is C89, C99, or C++11 is up to you. Obj-C also includes the Foundation classes that were originally introduced with the OpenStep SDK in 1994 (NSObject, NSString, NSNumber, NSArray, NSRunLoop, NSAutoreleasePool, etc.).
Is it possible to see this straight C translation? Using Clang for example. I'm sort of aware of the "objc_msgSend" business, but would like to see more. Talking of OpenStep, after seeing some of those NeXT videos on HN the other day, I found a torrent of OpenStep 4.2 incl the dev tools. It's a VMware image and boots and runs just fine. Pretty nifty. Then I noticed OpenStep 5.0 redirects to Mac OS X on Wikipedia!
Re: Objective-C literals for NSDictionary, NSArray, and NSNumber
#44I'm glad to see these additions, but the syntax for an NSArray literal bugs me. When I want an array literal in C, I'd write ... int foo[] = { 1, 2, 3, 4, 5}; ... but in Objective-C, for an NSArray literal I'd write ... NSArray *bar = @[o1, o2, o3]; Why did they choose '[' over '{'? Oddly enough, NSDictionary uses '{'. I feel like the syntax for an NSString literal is more natural (as a C developer). NSString *baz =…
Re: Objective-C literals for NSDictionary, NSArray, and NSNumber
#45Earlier quoted context omitted.
> ...so it only is available to those in Apple's Developer Program. correction: Apple's Mac developer program. I'm an iOS developer and I don't see Xcode 4.4 in my dashboard.
This is the second time (to my knowledge, may have been going on for a while) that an Xcode beta has been made available to only one of the two (Mac and iOS) developer programs. The Xcode 4.3 beta was only available to iOS developers -- despite containing bug fixes and improvements useful to developers on both platforms. Now the Xcode 4.4 beta is only available to Mac developers. I really don't see the logic in withh…
Interestingly now Xcode 4.3 is out of beta the iOS 5.1 SDK is still only available with Xcode 4.3 DP3 (although realistically there's not much public new stuff in iOS 5.1 since presumably it's all under wraps for the iPad 3).
Re: Objective-C literals for NSDictionary, NSArray, and NSNumber
#46Re: Objective-C literals for NSDictionary, NSArray, and NSNumber
#47The excessively verbose collection syntax is my #1 pain point with Obj-C. Looking forward to kicking the tires on this one.
It's never before fully struck me how cleanly the "Objective-C is too verbose" complaint really breaks down to two separate issues: one of them being that method names are long (which is arguably a plus) and the other being mostly comprised of the stuff that's apparently mostly taken care of with this release. Actually, I suppose there used to be a third, too: (auto)release/retain statements all over the place. As so…
Re: Objective-C literals for NSDictionary, NSArray, and NSNumber
#48Earlier quoted context omitted.
You can use C99 struct literals: return (struct x){a,b}; Small structs may be passed in registers. http://stackoverflow.com/a/3355560/27009
IIRC passing Obj-C object pointers in C structs is disallowed or discouraged by ARC.
Re: Objective-C literals for NSDictionary, NSArray, and NSNumber
#49I'm glad to see these additions, but the syntax for an NSArray literal bugs me. When I want an array literal in C, I'd write ... int foo[] = { 1, 2, 3, 4, 5}; ... but in Objective-C, for an NSArray literal I'd write ... NSArray *bar = @[o1, o2, o3]; Why did they choose '[' over '{'? Oddly enough, NSDictionary uses '{'. I feel like the syntax for an NSString literal is more natural (as a C developer). NSString *baz =…
id foo = @{ @2, @5 };
an NSArray containing two NSNumbers, or an NSValue containing a struct with two pointers (which happen to be NSNumber *s)?
I'd guess there were other edge cases they didn't want to deal with, so they didn't do literal NSValues for this release.
Or it could be that it's because []-style arrays are popular these days.
Or some of both; in picking which {} to change to @[], they reasoned that lots of people have experience with []-style arrays.
Re: Objective-C literals for NSDictionary, NSArray, and NSNumber
#50Earlier quoted context omitted.
Quick example of calling a method that doesn't take any arguments and returns an object: id foo = [self bar]; is the same as: id foo = self.bar; which is also the same as: id foo = [self performSelector:@selector(bar)]; or: IMP barImp = [self methodForSelector:@selector(bar)]; id foo = barImp(self, @selector(bar); [1] and finally: id foo = ((id)(id, SEL)objc_msgSend)(self, @selector(bar)); [2, 3, 4] 1. Because we're…
Those first two and following aren't equivalent, are they? Wouldn't they compile, respectively, to: objc_msgSend(self, @selector(bar)); And: objc_msgSend(self, @selector(performSelector:), @selector(bar)); ?
They would both become:
objc_msgSend(self, @selector(bar));
However, your examples are basically explicitly passing a message (1 and 2), vs dynamically building a message to pass (3).For the second to work, the objc_msgCall function would really be:
objc_msgSend(self, @selector(performSelector:), @selector(bar));
(The first example is saying to self to call the selector (method) named 'bar'. The second example is telling self to call the method 'performSelector:' with an argument of 'bar'.)The runtime may or may not be smart enough to optimize this out. It has never been a bottleneck for me to bother looking into it, and I haven't come across anything to indicate one way or the other.