@property parameters
copy:nsstring;
Strong: General Objects
Weak:ui controls
Assign: Basic data type
Instancetype
Instancetype on a type representation, as with an ID , can represent any object type
Instancetype can only be used on return value types and cannot be used as an ID on parameter types
One benefit of instancetype than ID: The compiler detects the true type of instancetype
Instancetype:
Instancetype is primarily used when a class method instantiates an object, letting the compiler proactively infer the actual type of the object
to avoid the useof ID, it will cause unnecessary trouble in development, reduce the chance of error!
Instancetype was the Apple that started the main push in iOS7.
C++11 Auto
in the Swift language, the majority of classes are instantiated without the need to specify a type
Instancetype can only be used for return value use!!! Cannot be used as a parameter
1 #import<Foundation/Foundation.h>2 3 @interfaceHmappinfo:nsobject4 5@property (nonatomic, copy) NSString *name;6@property (nonatomic, copy) NSString *icon;7 8 /**9 @propertyTen One 1. Generate Getter Methods A 2. Generating Setter Methods - 3. Generate underlined member variables (record attribute contents) - the the ReadOnly property does not produce an underlined member variable! - */ -@property (Nonatomic, Strong,ReadOnly) UIImage *image; - + /** - Instancetype is primarily used when a class method instantiates an object, letting the compiler proactively infer the actual type of the object + A to avoid the use of ID, it will cause unnecessary trouble in development, reduce the chance of error! at - Instancetype was the apple that started the main push in iOS7. - - c++11 Auto - in the swift language, the majority of classes are instantiated without the need to specify a type - in Instancetype can only be used for return value use!!! Cannot be used as a parameter - */ to + /** Usually when writing a model instantiation method, the following two methods need to be implemented*/ - /** Instantiate a model using a dictionary*/ the-(Instancetype) Initwithdict: (Nsdictionary *) dict; * /** Class method to instantiate an object quickly*/ $+ (Instancetype) appinfowithdict: (Nsdictionary *) dict;Panax Notoginseng - /** Returns an array of data models in all plist*/ the+ (Nsarray *) applist; + A @end
1 #import "HMAppInfo.h"2 3 @implementationHmappinfo4 //a composition directive that actively specifies the name of the member variable used by the attribute5 @synthesizeImage =_image;6 7 /**8 Precautions for using KVC9 Ten Key-value names in 1> plist must be consistent with properties in the model One properties in the 2> model may not all appear in plist A */ --(UIImage *) Image - { the if(_image = =Nil) { -_image =[UIImage ImageNamed:self.icon]; - } - return_image; + } - +-(Instancetype) Initwithdict: (Nsdictionary *) Dict A { at //Self is the object -Self =[Super init]; - if(self) { - //assign a value to a property in a dictionary, all the methods related to the Plist key value are here! - //self.name = dict[@ "name"]; - //Self.icon = dict[@ "icon"]; in - //Kvc-key Value Coding key value encoding to //is a method of indirectly modifying/reading object Properties + //KVC is called Cocoa's big trick! - //Parameters: the //1. Values * //2. Property name $ //[Self setvalue:dict[@ "name"] forkeypath:@ "name"];Panax Notoginseng //[Self setvalue:dict[@ "icon"] forkeypath:@ "icon"]; - //Setvaluesforkeyswithdictionary is essentially invoking the above two lines of code the [self setvaluesforkeyswithdictionary:dict]; + } A returnSelf ; the } + -+ (Instancetype) appinfowithdict: (Nsdictionary *) Dict $ { $ //Self is class - return[[Self alloc] initwithdict:dict]; - } the -+ (Nsarray *) ApplistWuyi { theNsarray *array = [Nsarray arraywithcontentsoffile:[[nsbundle mainbundle] Pathforresource:@"app.plist"Oftype:nil]]; - Wu //Create a temporary array -Nsmutablearray *arraym =[Nsmutablearray array]; About $ //iterate through the array and convert the model in turn - for(Nsdictionary *dictinchArray) { - [Arraym addobject:[hmappinfo appinfowithdict:dict]; - } A + returnArraym; the } - $ @end
OC Syntax Related