Thoughts on studying objective-c in winter vacation

Source: Internet
Author: User
Tags shallow copy

Bought this "learn Objective-c on Mac", a start to buy looks very thin, 250 pages, after reading, found that the language has a lot of common place, the new features are from C + + and Java similar to come over, is changed a name, feel after seeing the harvest pretty big, Although only touched a little fur.

1.C language knowledge

2. Learn about Xcode's use of

3. Understand some new grammar and new features.

---------------------------------------------------------------------------------------------

1. Formal agreement and informal agreement (replaced by @optional formal agreement) and file loading save

@required must be realized

@optional Selective implementation

Example 1.

@protocol nscopying//Deep copy replication

-(ID) Copywithzone: (nszone*) zone;

@end

Copy of Nsarray is shallow copy

@protocol nscoding//encoding and decoding

-(void) Encodewithcoder: (nscoder*) Acoder;

-(ID) Initwithcoder: (nscoder*) decoder;

Nscoding can be used to encode any object as NSData nsdata available [data writetofile: "Tmp.txt" atomically:true] to the hard disk

Example 1:

@interface a:nsobject<nscopying,nscoding> {nsstring*name;} @property (copy) Nsstring*name; @end @implementation A @synthesize name; -(ID) Copywithzone: (nszone*) zone {A *a; a=[[[self class]allocwithzone:zone]init]; a.name=self.name; return A;}-(void) Encodewithcoder: (nscoder*) Acoder {[Acoder codewithobject:name forkey:@ ' name '];}-(ID) Initwithcoder: (NSCoder*) Decoder {if (self=[super init]) {nsstring*n=[decoder decodeobjectforkey:@ "name"];} return self;}

Encoded as NSData by the Nskeyedarchiver class

Nsdata*data=[nskeyedarchiver Archiveddatawithrootobject: Object]; Automatic Call Encodewithcoder

A *a=[nskeyedunarchiver Unarchiveobjectwithdata:data]; Decoding

------------------------------------------------------------------------------------------------------------

Property list Nsarray nsdictionary nsstring nsnumber nsdate nsdata

1.NSArray

+ (ID) Arraywithobject: ... End With Nil

-(unsigned) count;

-(ID) Objectatindex: (unsigned) index;

Nsmutablearray

+ (ID) arraywithcapacity: (int);

-(void) AddObject: (NSObject);

-(void) Removeobjectatindex: (int) index;

2.NSDictionary

+ (ID) Dicitonarywithobjectsandkeys: (ID) firstobject, (nsstring*) Firstkey ...;

-(ID) Objectforkey: (ID) key;

Nsmutabledictionary

+ (ID) dicitonarywithcapacity: (int) n;

-(void) SetObject: (ID) object forkey: (ID) key;

-(void) Removeobjectforkey: (ID) key;

3.NSNumber

Package standard Type

Nsnumber*a=[nsnumber Numberwithint:10];

4.NSDate

+ (nsdate*) date;

+ (nsdate*) Datewithtimeintervalsincenow: (int) A;

5.NSData

+ (nsdata*) Datawithbytes: (nsobject) Length: (int);

-(int) length;

-(nsobject) bytes;

--------------------------------------------------------------------------------------------------------

Predicate:

Predicates are actually a simple way to give a constraint that can be substituted for and if

Nspredicate:

+ (nspredicate) Predicatewithformat: ....

-(nsarray*) filteredarrayusingpredicate:predicate;

Example: @interface a:nsobject {nsstring*name;} @property nsstring*name; @end @implementation A @synthesize name; @end @interface B; NSObject {nsmutablearray*a;} @end @implementation B-(void) AddA (nsstring*n) {a*object; object.name=n; A.add (object);} @end int main () {b* bobject=[[b alloc]init]; Bobject.adda ("A"); Bobject.adda ("B"); Bobject.adda ("C"); Bobject.adda ("D") ; Nspredicate*predicate=[nspredicate predicatewithformat:@ "name=%@", "A"]; Nsarray*result=[bobject Filteredarrayusingpredicate:predicate]; }

Predicates are also given a number of operators (operators that can inherit C)

Example: A class that inherits an example

Nspredicate*predicate=[nspredicate predicatewithformat:@ "(name== ' A ') and (name== ' B ')"];

Array operator name Between{min,max};

Name in{"A", "B"};

The use of self:

Nsarray*a=[nsarray arraywithobject:@ "A", "B", nil];

Nspredicate*predicate=[nspredicate Predicatewithformat: @SELF in "' A ', ' B '"];

nsarray* B=[a Filteredarrayusingpredicate:predicate];

String operators:

Beginswith

ENDSWITH

CONTAINS

[C] Ignore case

[d] Ignore accent

[CD] is ignored

Example: Beginswith[c]

Like operator

A can be included in the middle of like ' *a* '

Like '?? A * ' preceded by two characters

Related Article

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.