Using the new factory method might seem appealing: you no longer have to type [[MyClass alloc] init], you no longer need to write custom factory methods to your class, in short less code. And this is not a bad thing, less code to write means less code to maintenance, test, etc. new unfortunately has a […]
Tag: Objective-C
if-let statement in Objective-C
I just found an equivalent to Swift’s if-let construct, and thought to share it 🙂 Swift: [swift gutter=”false”] if let result = computeResult() { // do something with result } [/swift] Objective-C: [objc gutter=”false”] for(SomeClass *result = [self computeResult]; result != nil; result = nil) { // do something with result } [/objc] You no […]
A promise implementation for objective-c: CKPromise
Now that we went through all promise technical details in the past articles: Promises and ObjectiveC: no more callback hell, Promises: basics, and Promises: advanced, it’s time to discuss about one of the available implementations, and for subjective reasons I chose CKPromise. Other good implementations that I know of are PromiseKit and RXPromise. CKPromise focuses only on […]
Promises: advanced
In the previous article we discussed about the basics of promises: what are and how can be used. Today I will bring into discussion the most powerful feature of promises: chaining. But first I just want to take a short detour and mention that as the standard for promises emerged on the Javascript platform, it allows completion […]
Promises: basics
In my previous article, I introduced the concept of promise, a technique that allows us to write async code in a more sync-ish manner. In this article and the following ones I will try to dive into the definition and expectancies of a promise. So what is a promise? A promise represents the eventual result of an asynchronous operation. This […]
Promises and ObjectiveC: no more callback hell
If you worked with asynchronous tasks in iOS apps, chances are that you have run into problems when implementing chains of async operations, like when it comes to talking to a server API. Let’s take an example. Supposing you have to implement a library app and you need to add support for inserting a new book. And supposing […]
Setters in Cocoa
Which of the three setters is better: [objc gutter=”false”] – (void)setName:(NSString*)value{ if(value != name){ [name release]; name = [value retain]; } } – (void)setName:(NSString*)value{ id old = name; name = [value retain]; [old release]; } – (void)setName:(NSString*)value{ [name autorelease]; name = [value retain]; } [/objc] Personally I’d use the third variant, but I’m open to […]
Recent Comments