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 […]
Category archives: Technology
When is id promoted to instancetype?
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 […]
A primer on @property and dot syntax
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.”
Objective-C property proposal: mainthreadonly
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?
1 2 3 |
@interface CustomView:UIView @property (mainthreadonly) NSString *title; @end |
Trimming a level of indent with @synchronized and @autoreleasepool
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.
Reachability
Apple has a sample code package called Reachability. It wraps an iOS framework called SystemConfiguration, and can be used to determine network status, and catch events about networking going up and down. In the past, it’s been an ugly chunk of sample code, but it’s pretty respectable now. One thing Reachability is not, however, is […]
View Controller Lifecycle in iOS 6
I previously wrote about breaking the old pattern of writing viewDidUnload. The other half of that is the new reality, which Joe Conway’s written about in View Controller Lifecycle in iOS 6.
How to avoid starting view controllers in the wrong orientation on startup
This is a bit obscure, but I ran into it earlier this week. Why would a view controller appear in the wrong orientation on startup?
Make your library enforce ARC
If you have an open source library that requires Automatic Reference Counting (ARC), you may have issues with your users trying to build it without ARC turned on. Luckily, it’s pretty simple to enforce ARC. I’m going to discuss how to do so, and why it’s a good idea.
You don’t have to have 16:9 on day 1
You don’t have to build with armv7s right away. And despite user demands, you also don’t have to support 16:9 right away either. It’s fine to get real hardware into your hands. More than fine; it’s being responsible. Apple has you covered with letter boxing; let the 16:9 screen be their problem until you’re really […]