Learning Object-C from scratch --- learning Cantonese from scratch on the first day
Start learning object-c from "hello world"
//// Main. m // Demo1 /// Created by lee on 14/10/27. // Copyright (c) 2014 lee. all rights reserved. // # import <Foundation/Foundation. h> int main (int argc, const char * argv []) {@ autoreleasepool {// insert code here... NSLog (@ "Hello, World! ");} Return 0 ;}
1. object-c Annotation
Object-c has two main annotation Methods: one is (// annotation, single line annotation), and the other is (/**/, multi-line annotation)
2. # import <Foundation/Foundation. h>
Importing system files mainly involves some basic classes and Methods
3. @ autoreleasepool {} is used to create an automatic release pool.
The automatic release pool is a memory recovery mechanism in OC. Generally, some temporary variables can be added to the automatic release pool for unified recovery and release. When the automatic release pool is destroyed, all objects in the pool call release once, that is, the counter is reduced by 1, but the automatically released pool is destroyed, and the objects in the pool are not necessarily destroyed.
4. NSLog (); outputs functions on the console
NSLog is equivalent to printf in C language and is often used for text output.
5. @ "hello world"
The @ symbol before the string is called the constant NSString object. In object-c, the classes used to process strings are NSString and NSMutableString. The main difference between these classes is that the content and length of strings cannot be dynamically changed after NSString is created, while NSMutableString can dynamically change the content and length of the string.
6. return 0;
It indicates the termination of the main function and returns a state value of 0. According to the Convention, 0 indicates that the program ends normally.
How to Learn object-c
Buy this document. It would be easier if you have learned java. Fuel
What is the best way to learn object-c? I hope to explain in detail the learning steps of object-c and the books or websites used for learning.
Object-c is developed based on the c language. Both languages are relatively low-level. It is easier to learn one of them. It can be seen from the literal that object-c has the object concept, which is the object-oriented version of c. If you want to step by step, you can first learn the c language and then learn object c. This also makes the transition easier. If you study it directly, you must first learn the basics of C language. The object-c recommended book "Objective-C basic tutorial". If you want to develop ios programs later, we recommend reading "Basic tutorial for iPhone 4 and iPad development".