New features for iOS

Source: Internet
Author: User

1, the declaration attribute can be empty three kinds of wording:

1, @property (nonatomic, copy, nullable) NSString *name; 2, @property (nonatomic, copy) NSString *_nullable name1; 3, @property (nonatomic, copy) NSString *__nullable name2;

2, the declaration attribute can be empty three kinds of wording:

1, @property (nonatomic, copy, nonnull) NSString *name4; 2, @property (nonatomic, copy) NSString *_nonnull name5; 3, @property (nonatomic, copy) NSString *__nonnull name6;

Note: The above three kinds of writing the first one to use the most, the latter two basic not how to use

3. Between Ns_assume_nonnull_begin and Ns_assume_nonnull_end, all object properties and methods defined by default are nonnull

* * * * __nullablename2; Ns_assume_nonnull_end

///4, the usage in the method is as follows:

-(nonnull NSString *) Test: (Nullable NSString *) str; -(NSString * _nonnull) Test1: (NSString * _nonnull) str;
5, the use of null_resettable:

If you use Null_resettable, you must override the Get method or the Set method, and the process of passing the value to null is as follows (a setter or getter implements one)
@property (nonatomic, copy, null_resettable) NSString *name;//Implementing Setter Methods- (void) SetName: (NSString *) name{if(Name = =Nil) {Name=@"123"; } _name=name;}//Implement Getter-(NSString *) name{if(_name = =Nil) {_name=@"123"; }    return_name;}
6. Declare the type of object in the array: Add < data type *> after type, and then warn, crash if insert non-string type in data
@property (nonatomic, strong) nsmutablearray<nsstring *> *dataarray;
7, __kindof use: __kindof: Represents the current class or its subclasses,
__KINDOF writing format: Put in front of the type, indicating the type of decoration (__kindof person *),
__kindof: When called, it is clear that the return type is known.
Note: Of course, you can also write + (instancetype) person; The return value is instancetype.
Example: Create a new Person class
//. h in@interfacePerson:nsobject+ (__kindof person *) person;+ (Person *) Person1;@end//. M Medium@implementation Person//indicates that the return data type is person or its child class object+ (__kindof person *) person{return[[Self alloc] init];}+ (Person *) person1{return[[Self alloc] init];}@end//Create person Subclass Sonperson@interfaceSonperson:person@end//at this point Sonperson calls the parent class method + (__kindof person *) The person returns the Sonperson object//Normal returnSonperson *son =[Sonperson person];//The object returned is the person objectSonperson *son1 = [Sonperson Person1];
8, __covariant (covariant), __contravariant (contravariant) __covariant (covariant): For the generic data strong-turn type, can be strong, the subclass can be turned to the parent class __contravariant (contravariant): For the generic data strong-to type, can go down strongly, the parent class can be turned into a subclass instance: Create the language class, while creating iOS, Java Two classes inherit from language, in the Create Person class, where the person class code:
#import<Foundation/Foundation.h>#import "Language.h"#import "IOS.h"//declaring generics@interfacePerson<__contravariant objecttype>: NSObject//language@property (nonatomic) ObjectType language;//ID: Any object can be passed in//language: When called outside, there is no hint//ios*You can only pass objects later .-(ObjectType) language;- (void) SetLanguage: (ObjectType) language; @end //Controller inPerson<language *> *p =[[Person alloc] init]; person<ios *> *iosp =[[Person alloc] init];//if the subclass wants to assign a value to the parent class, the covariantIOSP =p;//generics are not deterministic, that is, ID typeIosp.language = [[IOS alloc] init];

PS: Temporary is some simple application

New features for iOS

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.