After understanding the differences between different mobile apps, I decided to go for iphone native app development for numerous reasons. There is only a small problem – I don’t know Objective-C …yet. I took a course in C many years ago and I used C in my database class two years ago. Other than those two encounters with C, I have been using Java for back-end support.
Learning a new programming language is part of the professional growth as a developer and it’s interesting since you are learning another way to present the same logic. When I first looked at Objective-C code, it looked like a new animal, but after reading up some fundamentals online, I actually found a lot of similarities. After all, the main thing of programming is just problem solving regardless of the programming language.
Even though Xcode is not the only IDE available, I would suggest you to start with it. It generates the required ios certificate for development, provides templates for different applications and easy-to-use simulator. It’s the most common used of IDE for ios development so in the learning materials.
Objective-C is a superset of C language so it complies C code. However, C is not object-oriented but Objective-C is with Smalltalk-style messaging. Even if you are new to C programming, you probably heard of these two main specialties of it: memory allocation and pointer.
For those who have C programming experience, the object-oriented Smalltalk-style messaging syntax is probably what makes it look unfamiliar to you. Object-oriented programming is a big topic but an object can be considered as a struct with methods in C. Every object inherits NSObject.
To syntax for initializing an object is:
ClassName *obj = [[ClassName alloc] init];
Objective-C uses square brackets for method call and method call is considered as sending messages to the class. “[ClassName alloc]” allocates memory for the new object from the heap and returns a pointer to the new object then it’s passed in method init for initialization.
Let’s look at these two ways to initialize a new NSDate object:
NSDate *now = [NSDate date];
and
NSDate *now = [[NSDate alloc] init];
The first way is using a NSDate method named date to return a new NSDate object. The second way is the standard way of initializing a new object. The other interesting thing of Objective-C is that parameters are considered as part of the method name in Objective-C, for example, ordinalityOfUnit:inUnit:forDate.
NSDate *now = [[NSDate alloc] init]; NSCalendar *calendar = [NSCalendar currentCalendar]; NSUInteger day = [calendar ordinalityOfUnit:NSDayCalendarUnit inUnit:NSMonthCalendarUnit forDate:now];
That’s all for the first blog post on Objective-C and I will post more about it as I continue to learn more:)
