Hi guys!
I'm using Swift in developing applications for iOS. Currently, I'm interested in learning Objective-C to build applications. However, when I create a project with Obj-C, I found out that, there are some differences between using "Obj-C in iOS Dev" and "Obj-C in MacOS CommandLine". For instance: declaring method;
- iOS Dev Environment:
- -(void)getFunc {..}
- macOS Dev Environment:
- void getFunc() {...}
You can see here, there are -(void) and void only.
Anyway, can you recommend some documents to study Objective-C?
Thank you for spending time for my post! Have a great day!
Best regard from Vietnam!
Objective-C takes the C language and adds support for object-oriented programming.
The function example you showed for iOS is an example of an Objective-C method. A method is a function that is part of a class. Objective-C methods put the return type in parentheses, (void)
. Objective-C has two types of methods: instance and class. An instance method starts with -
while a class method starts with +
. You showed an example of an instance method.
The function example you showed for Mac is an example of a C function. Objective-C supports C functions. C functions do not put the return type in parentheses. C does not have classes so it does not have methods.
Apple provides the following guide to Objective-C:
The following book teaches Objective-C for people who already know Swift:
https://www.hackingwithswift.com/store/objective-c-for-swift-developers