OC study notes (a)

A move ios internship can only learn from scratch. .

Our first task is familiar oc week of use, there is not complicated to lists, we will remember a few key, which is the oc something unique.

1.oc message mechanism

oc unlike other languages, there is a strong dynamic characteristics, [object message] Such a message sent to the object will be determined at runtime.

2. Modify the project template

Project templates and modify the contents of the main function
/Applications/Xcode.app/Contents/Developer/Library/Xcode/Templates/Project Templates / Mac / Application / Command Line Tool.xctemplate /

description file header information to modify OC
/ Applications / the Templates Xcode.app/Contents/Developer/Library/Xcode/Templates/File / the Source / Class.xctemplate the Cocoa

the Xcode document mounting location. 1:
/Applications/Xcode.app/Contents/Developer/Documentation/DocSets
Note: before the best copy the default document deleted, because if there is a high and low version version of the document at the same time, the low version does not show
Xcode documentation installation position 2:
/ the users / your user name / Library / Developer / Shared / documentation / DocSets
if the folder can not create your own

3.NSString

Creating strings: NSString * str = @ "lnj";

或者:NSString *str = [NSString stringWithFormat:@"age = %i, height = %f\n", 30, 1.75];

Calculating the string length: NSUInteger len = [str length]

4. polymorphic support

For example: Animal * a1 = [Dog new];

Note that java and different polymorphic, if you want to subclass-specific method calls must be cast to the subclass can call

The instance variables modifier

@public
> public may be modified in other class member variables accessed
> may also be modified public access to the member variable class
> may be public access to the parent class member variables modified in the subclass

@private
> not in other classes are private access member variables modified
> may be present in the access class is modified private member variable
is private modified> subclass can not access the parent class member variables

@protected
> not other classes access is protected modified member variable
> You can access this class is modified protected member variables
are protected modified> can be accessed in a subclass the parent class member variables

Note: All default instance variables are protected

@package
> between the public and private
if other packages are accessible in the private so that
if the current code is located in the seed packet access is a public

6. dot syntax

It can be used to invoke getter / setter methods directly

7. The method of construction

- (instanceType) the init: list of parameters 
{ 
    Self = [Super the init]; // Self nil == == 0 
    IF (Self) {
         // initialize subclass 
    } 
    return Self; 
}

8. The method of class factory

The method of quickly creating a class of objects, called class factory method
class factory methods are mainly used to initialize the object allocation of storage space and storage space this
specification:
1. The method must be + class
2. Class name Method name starts with the first letter lowercase
3. there must be a return value, the return value is the id / instancetype

 

Guess you like

Origin www.cnblogs.com/scaq/p/11257880.html