Simplify your nil checking code
In Objective-C, any message sent to a nil object will return nil, so this if statement:
if(myObject != nil && myObject.aProperty != nil) { ... }
can be reduced to:
if(myObject.aProperty != nil) { ... }
or even shorter:
if(myObject.aProperty) { ... }
Similarly, to check if an array is not empty, we just need to write
if(myArray.count) { ... }
instead of
if(myArray != nil && myArray.count > 0) { ... }
Written by Toan Nguyen
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#