First introduce yourself, Nanchang University software engineering professional graduates, from the university to the program ape, because in the school only learn the Java language and b/s architecture development, and then out of the internship and work is to engage in Java Web development.
But as a fruit powder, now want to turn to IOS Development, recently began to self-study, write something down
/9/
Day 1
Install the virtual machine and install the MAC OS X system (Bitter I'm still using Lenovo Y-470)
began to look at the C Language Foundation, because the university has learned a little, is relatively easy
/9/
Day 2
Since there is no pointer in Java, start looking at pointers related knowledge
/9/
Day 3
1) The pointer is used as a parameter to pass it to its corresponding address value .
2) The array name represents the first address of the array, and when the array is a parameter, the system is converted to a pointer, so try to use pointers as parameters
3) array receive string: variable string
pointer receive string: Immutable string ( the string is in the constant area of memory ) // feels like a string in Java
4) pointers to functions are used when passing functions as arguments // Java -like callback functions
/9/
Day 4
Start learning OC (objective-c)
the notation of classes in OC
@interface < #class name#>: < #superclass #>
attributes and repeated declarations (+ representing class methods,- representing object methods)
@end
@implementation class name
implementation of the method
-( return value type ) method name :( parameter 1 type ) parameter 1 method name/ * Best Write parameter description */ :( parameter 2 type ) parameter 2 ..... {< /c7>
}
Advocate to write a method name as well as a sentence to make people understand
Personal just open feeling method name is very long, do not adapt, later with more feel very good!
@end
you need to call the method in OC to write a [], then the left to write the user, the right to write the method name
The properties and methods of the object that you want to manipulate in OC, you must use the pointer
/9/
Day 5
Common errors
1) Only declarations, not implemented
2) Missing @end
3) member variable not in {}
4) No initialization in Declaration
The most common exception information
Unrecognized selector sent to instance
Sent a meaningless message to the instance / object
Example:nsstring
Definition and initialization
NSString *str = @ "Huihui";
Method
[NSString stringWithFormat: ...]; // class method
[STR length]; // object Methods
Encapsulation idea, the same as Java , attribute variables are generally used directly by the outside world, but provide set,get method for others to use
the Set method is named setxxx://xxx represents the property name, with the same set in front of Java and then the hump
Get method named xxx //xxx table property name, unlike Java, in OC directly with the property name to do get method name
The Self keyword is equivalent to this in Java
/9/
Day 6
The three main features of object-oriented language: encapsulation, inheritance, polymorphism. This is very simple for me, the original Java interest is derived from the object-oriented thinking
Said in front of the package, and then OC inheritance
Total Parent class NSObject
The basic methods commonly used are new,description( Java -like toString method), etc.
OC in order to cater to Java programmers, joined the dot syntax, haha ^_^ praise a
Object . Properties (only for attributes)
The essence is that the compiler calls the set method in the background , theget method
Corresponding to the Java in the automatic generation of Set,get method, OC is ofcourse, but also better, you do not need to see the set in the class file ,get method (unless you rewrite him to do certain things)
This kind of file is very concise, do not want Java class file has a big lump is set,get method
@property type variable name ;
As above, simply add @property
ID Universal pointer equivalent to nsobject *
The constructor method starts with init and calls the Super init method in the method
(instancetype) Initwith ... {
if (self = [Super Init]) {
...
}
return self ;
}
The Alloc method is to create an object that is not initialized
Init Initialization Object
Generally not new , first alloc and then init
/9/
Day 7
Custom Construction Methods
1) Generally in the development, need to give class an object method and class method, easy to use
Object Method init start
Class method method name begins with the class name (lowercase first letter)
Use self as much as possible in the construction method to improve extensibility
2) If Class A is imported in class b , and class B is also imported in Class A
This can cause circular references
Workaround: Import the class (. h file, which is the declaration file ) with @class without #import reference
But @class just tell the compiler that something is a class, and if you need to import its members and methods, use #import to import
A Java programmer learns the path of iOS development (i)