In the past if you wanted to include data in your command line app, you could either include it in a separate file or do some linker trickery to embed it. Personally, I never really got into the linker trickery (though it’s probably the better solution of the two). For a while, though, Xcode has… Continue reading Info.plist for command line tools
You probably know CGRectMake, but did you know it’s not the only way to make rectangles? It’s not even the best way, really. There’s also C99 initializer syntax. The main advantage to the C99 syntax is that it gives you some very Objective-C like syntax, where the fields are close to the values rather than… Continue reading C99 initializers
In my previous entry, I discussed when id will be promoted to instancetype. But now that I’ve explained this, I’d like to explain why you should understand this but not rely on it. Instead, you should use instancetype directly. Let me start with this bold statement, then I’ll back up and explain it: Use instancetype… Continue reading Why you should use instancetype instead of id
instancetype is a special type that can be returned from an Objective-C method. It specifies that the return is an object of the same type as the receiving class. In some cases, the compiler promotes an id return to an instancetype: For instance, despite the definition of [[NSString alloc] init], the compiler knows that it… Continue reading When is id promoted to instancetype?
Properties were new in Objective-C 2.0, introduced in 2006. While pretty uncontroversial, along with them came dot syntax. Dot syntax is much more controversial. In this article, I’ll discuss the advantages of @property which make it worth using, and discuss “dot syntax.”
I’d like to propose a new language feature for Objective-C, a property attribute that would indicate that a property should only be set from the main thread. Let me be clear: Objective-C does not do this. But wouldn’t it be cool if it did? @interface CustomView:UIView @property (mainthreadonly) NSString *title; @end
I haven’t seen this discussed anywhere, but you can eliminate a level of indentation when using @synchronized and @autoreleasepool blocks in a loop or conditionally. This falls naturally as a result of the way the C language works, and how these blocks work, but it took me a while to realize it.
Which modern Objective-C feature can you use where? Check the Objective-C Feature Availability Index (via 0xced).
It took me a while to learn Objective-C. I started at the most basic level, wondering at the language. What are these brackets? What’s with the @ signs? What’s the difference between a – and a +? These aren’t hard things to learn, but understanding the reasoning behind them helps. And then there’s a point… Continue reading Learning a new programming language