I was just looking through my code and wondering about the standards of obj.c in xcode. We have all these NS(insert object type) which overlap with the original C, C++ objects. I wanted to clarify between different alternatives of snippets of code. Even better than explaining each one would be a link to a guide or reference containing all these.
object.property = blah; or [object setProperty:blah];
float aFloat = 0.01;(or double) or CGFloat aFloat = 0.01
int anInt = 1 or NSInteger anInt = 1
@"%d", anInt or @"%i", anInt
Thanks
The first one (dot notation vs method calls) is purely a thing of taste.
man printfsays that%dand%iboth are placeholders for signed decimal, hence ObjC being strict superset of C doesn’t change their meaning.Types with
NSorCGprefixes are platform dependent and are actuallytypedef‘ed from standard C types. If you decide to compile for different platforms (say 32/64 bit) using NS/CG types will fall back to default types of the platform you’re compiling for. Take for exampleNSInteger(snippet from NSObjCRuntime.h):It shows that if you’re not compiling for iOS, the NSInteger will stand for
long, otherwise – it will be simpleint.Personal opinion
I always use
%dsince I saw it first in some ObjC tutoria. Never looked back on other placeholders for integers (unless%lld). I use the dot notation only if receiver type is known at compile time. Sometimes you may have to write this:The result of those calls is the same, but the first line forces compiler look for
framevariable under id-typed structure.And I always try to use the NS/CG variable types since they make code look more ObjC-ish than C-ish.