Foundation Framework:
- NSString (c string preceded by @)
NSString *myString = @"My String\n";
NSString *anotherString = [NSString stringWithFormat:@"%d %@", 1, @"String"];
NSString *fromCString = [NSString stringWithCString:"A C string" encoding:NSUTF8StringEncoding];
NSString *string = [NSString string]; NSString 类声明 string 类方法 ?
NSNumber
NSNumber *myIntValue = @32;
NSNumber *myDoubleValue = @3.22346432;
NSNumber *myBoolValue = @YES;
NSNumber *myCharValue = @‘V‘;
NSNumber *myFloatValue = @3.2F
NSArray, NSSet and NSDictionary the contents of a class cannot change over time.
- Nsarray (You can save instances of different classes!) )
- Although the Nsarray is immutable, the elements it saves are mutable. (It can be understood that the pointer variable is saved.) )
定义:
-
-
nsarray *somearray = @[< span class= "n" >firstobject, secondobject, thirdobject
-
nsarray *< span class= "n" >somearray = [nsarray arraywithobjects:firstobject, Secondobject, thirdobject, nil
- "member functions":
- Number of array elements: [Somearray Count]
- Find element: [somearray containsobject:somestring]
- Access element: [somearray Objectatindex:0] (this method returns an exception if the array is empty)
- Access element:somearray[0] (actual override of last method)
- < Span class= "p" > < span class= "n" > output element to NSLog function: NSLog (@ "first item is:%@" , [ Somearray objectatindex:0
NSArray *sortedStrings = [unsortedstrings sortedarrayusingselector:@selector(compare:)]; (Because Nsarray is immutable, So the method returns a new sorted array)
- nsmutablestring
NSMutableString *mutableString = [NSMutableString stringWithString:@"Hello"];
- [STRING0 appendString:@ "world!" ]
- [STRING0 iskindofclass:[nsmutablestring class]] Determines whether this class or instance of a subclass of this class
- [STRING0 ismemberofclass:[nsmutablestring class]] Determines whether an instance of this class
- Nsmutablearray
NSMutableArray *mutableArray = [NSMutableArray array];
[mutableArray addObject:@"gamma"];
[mutableArray replaceObjectAtIndex:0 withObject:@"epsilon"]; or mutablearray[0] = @ "Epsilon";
[mutableArray sortusingselector: @selector ( Caseinsensitivecompare:
- @selector (localizedcompare:) Normal sort
- @selector (caseinsensitivecompare:) Sort in ascending and case-insensitive order
- Nsset (a single object is added only once, similar to the set in the STL)
NSSet *simpleSet = [NSSet setWithObjects:@"Hello, World!", @42, aValue, anObject, nil];
- Nsdictionary (feeling is the map in STL)
- //nsdictionary Create //nsdictionary Simplicity
- Query object:
NSNumber *storedNumber = dictionary[@"magicNumber"]; or nsnumber *storednumber = [dictionary Objectforkey:@ "MagicNumber"];
- Variability: Using
NSMutableDictionary subclasses?
- Add, remove
- (Although other objects can also be used as keys, be aware that each key is copied for use by the dictionary and must be supported
NSCopying .) However, if you want to use key-value encoding, you must use a string key for the Dictionary object. To learn more, see thekey-value Coding ProgrammingGuide (Key-value coding programming guidelines). )
- NSNull (Singleton Class)
- Nil means no object, [NSNull null] is the null value.
NSArray *array = @[ @"string", @42, [NSNull null] ];
- For statement, NSLog function
The foundation framework for IOS Programming learning notes