Category category
A, class purpose definitions and class definitions are similar. The implementation method in the. h file is declared in the. m file.
b, define the class purpose file naming rules: Class name + class name, such as "NSString + Revert".
@interface nsstring (Extension)-(BOOL) validateemail; @end
@implemention nsstring (Extension)- (BOOL) validateemail{ // Implementation method }
Limitations of class names
The class can also override the methods of an existing class. After overwrite, the original method cannot be called.
Class cannot extend instance properties for a class.
// declaration of the class item @interface nsstring (Extension) // Overwrite Method -(int) intvalue; @end
Six, the common processing method of digital object
NSNumber
//Create NSNumber (wrapper base data type)--PackagingNSNumber *intnumber = [NSNumber numberwithint: -]; NSNumber*floatnumber = [NSNumber numberwithfloat: $]; NSNumber*longnumber = [NSNumber numberwithlong:125125325]; NSNumber*boolnumber =[NSNumber Numberwithbool:yes]; Nsarray*array =@[intnumber, Floatnumber, Longnumber, Boolnumber]; NSLog (@ "Array= %@ ", array);//UnpackingintIntvalue =[Intnumber intvalue];floatFloatvalue =[Floatnumber Floatvalue];LongLongvalue =[Longnumber Longvalue];BOOLBoolvalue =[Boolnumber boolvalue];//NSNumber Optimized SyntaxNSNumber *intnumber1 = @ A;//equivalent to [NSNumber numberwithint:100]NSNumber *floatnumber1 = @2.32f; NSNumber*longnumber1 = @34903521123; NSNumber*boolnumber1 =@YES; NSNumber*charnumber1 = @ ' s ';
Nsvalue -The structure can be packaged, Nsvalue It's NSNumber . the parent class
Nsrange rang = {Ten, -}//Sealing PackageNsvalue *rangvalue =[Nsvalue Valuewithrange:rang];//UnpackingNsrange rang2 =[Rangvalue Rangevalue]; NSLog (@ "(%ld,%ld) ", rang2.location,rang2.lenght);//to package a custom struct bodystructwxpoint{floatx; floaty;}structWxpoint p = { -, -}; Nsvalue*pointvalue = [Nsvalue value:&p withobjctype: @encode (structWxpoint)];//Unpacking a custom structurestructwxpoint p2; [Pointvalue GetValue:&P2]; Nslong (@ "p2.x=%f,p2.y=%f ", p2.x,p2.y);
NSNULL the Use
Nsarray *nilarray = @[nil,nil,nil]; // error, nil cannot be deposited into an array or dictionary nullnull*nullarray ==%@ ", nullarray); for (ID in nullarray) { if(item = = [NSNull]) { NSLog (@ " This location is an empty element ");}}
Date Class NSDate
//Date CreatedNSDate*date1 =[NSDate Date]; NSDate*date2 =[[NSDate alloc] init]; NSLog (@ "Date2:%@ ", date2);//The date after which a value is accumulated on the basis of the current point in time, in secondsNSDate *date3 = [NSDate datewithtimeintervalsincenow: -* -* -]; NSLog (@ "Date3:%@ ", date3); NSDate*date4 = [NSDate datewithtimeintervalsincenow:- -* -* -]; NSLog (@ "Date4:%@ ", date4);//Timestamp: The size of the number of seconds from a date to 1970, called the timestamp for that date. NSDate *date1970 = [NSDate dateWithTimeTntervalSince1970:0]; NSLog (@ "date1970:%@ ", date1970); NSDate*time = [NSDate dateWithTimeTntervalSince1970:11025412687]; NSLog (@ "Time:%@ ", time);//gets the timestamp of the dateNSDate *timenow =[NSDate Date]; Nstimeinterval time1970=[TimeNow Timeintervalsince1970]nslog (@ "time1970=%LF ", time1970);//Comparison of dates//1, compare by calling the Compare method of the Date objectNscomparisonresult result =[Date3 Compare:date2];if(Result = =nsorderedascending) {NSLog (@ "Date3>date2 ");}Else{NSLog (@ "Date3<date2 ");}//2. By comparing timestampsif([Date3 timeIntervalSince1970] >[Date2 timeIntervalSince1970]) {NSLog (@ "Date3>date2 ");} Else{NSLog (@ "Date3<date2 ");}
Date Formatting class NSDateFormatter
//Date Object-? stringNSDate*nowdate =[NSDate Date]; NSString*timestr =nowdate.description; NSLog (@ "%@ ", timestr); NSDateFormatter* Dateformatter =[[NSDateFormatter alloc] init];//Set Date format[Dateformatter setdateformat:@ "yyyy years mm DD Day hh mm min ss seconds"]; NSString*datestring =[Dateformatter stringfromdate:nowdate]; NSLog (@ "Current time:%@ ", datestring);//Setting the time zoneNstimezon *time = [Nstimezone timezonewithname:@ "america/New_York "];//To configure the time zone to a Dateformatter object[Dateformatter Settimezone:timezone]; NSString*datestring2 =[Dateformatter stringfromdate:nowdate]; NSLog (@ "After formatting 2:%@ ", datestring2);//string--? Date ObjectNSString *str = @ "March 22, 2015 -: .: A"; NSDateFormatter* DateFormatter2 =[[NSDateFormatter alloc] init]; [DateFormatter2 setdateformat:@ "yyyy years mm DD Day hh mm min ss seconds"]; NSDate*date11 =[DateFormatter2 Datefromstring:str]nslog (@ "%@ ", DATE11);
Object-c Learning (eight)--foundation Framework (iv)