IOS learning notes OC-API-common structures, 2015-03-24oc-api-
A title common struct 2 API 1 nsange indicates A range A instantiation of nsange rg = {3, 5 }; // The first parameter is the starting position. The second parameter is the length. B is instantiated. nsange rg2 = NSMakeRange (). C. Print the nsange. You can use the NSLog method in Foundation (@ "rg2 is % @", NSStringFromRange (rg2); // note that NSLog (@ "rg2 is % @", r, because rg2 is not an object (accurately speaking, % @ is a pointer) cannot be used directly) instead, the struct 2 NSPoint indicates A coordinate A instance NSPoint p = NSMakePoint (10, 15); B instance NSPoint p2 = CGPointMake (10, 15 ); common C print NSLog (NSStringFromPoint (p2); 3 NSSize indicates A size area A instantiate NSSize s = NSMakeSize (10, 15); B instantiate CGSize s2 = CGSizeMake (10, 15). This method is more common for C printing NSLog (NSStringFromSize (s2); 4 NSRect indicates A rectangular coordinate length and width A instantiation NSRect r = NSMakeRect (10, 5,100,200 ); B instantiate NSRect r2 = CGRectMake (10, 5,100,200); more common C prints NSLog (NSStringFromRect (r2); three adaption scenarios 1. nsange A intercepts string B and searches string C to obtain the subset of the array
//// Main. m // OC-API-struct // Created by wangtouwang on 15/3/24. // Copyright (c) 2015 wangtouwang. all rights reserved. // # import <Foundation/Foundation. h> // test the nsangevoid test1 () {// capture the string NSString * str1 = @ "My name is jack, age = 18"; nsange range = NSMakeRange (3, 4 ); NSLog (@ "% @", [str1 substringWithRange: range]); // search string range = [str1 rangeOfString: @ "na"]; // obtain the subset NSLog of the array (@ "% @", NSStringFromRange (range); NSArray * array = [[NSArray alloc] initWithObjects: @ "", @ "B", @ "C", @ "D", @ "E", @ "F", nil]; array = [array subarrayWithRange: range]; NSLog (@ "% @", array);} int main (int argc, const char * argv []) {@ autoreleasepool {// test1 ();} return 0 ;}