Foundation 框架定義常用結構體,結構體采用object-c 定義:常用NSSRange,NSPoint,NSSize,NSRect等
一、NSRange 創建范圍結構體。
方法:NSMakeRange(參1,參2)。location和length。
二、集合數據類型。
1,NSPoint 創建一個點。
方法:NSMakePoint(參1,參2)。x和y。
2,NSSize 創建長和寬。
方法:NSMakeSize(參1,參2)。width和height。
下面是我的測試學習代碼:
// // FoundtionOftenStruct.h // Array_01 // // Created by selfimprovement on 15-6-4. // Copyright (c) 2015年 FoundationFramework. All rights reserved. // #import@interface FoundtionOftenStruct : NSObject { } //聲明一個動態的方法,沒有返回值 -(void)testNsRange;//NSRange表示一個范圍 -(void)testNsPoit;//NSPoint表示一個點 -(void)testNsSize;//NSSize表示大小 -(void)testNsRect;//NSRect表示矩形 @end
// // FoundtionOftenStruct.m // Array_01 // // Created by selfimprovement on 15-6-4. // Copyright (c) 2015年 FoundationFramework. All rights reserved. // #import "FoundtionOftenStruct.h" @implementation FoundtionOftenStruct -(void)testNsRange{ NSString *strRange = @"0,1,2,3,4,5,6,7,8,9"; NSRange range1 = [strRange rangeOfString:@",2,"]; if (range1.length > 0) { NSLog(@"range is%@",NSStringFromRange(range1)); } } -(void)testNsPoit{ NSPoint point =CGPointMake(10, 5); NSLog(NSStringFromPoint(point)); } -(void)testNsSize{ NSSize size = CGSizeMake(10, 5); NSLog(NSStringFromSize(size)); } -(void)testNsRect{ NSRect rect = CGRectMake(1, 3, 10, 20); NSLog(NSStringFromRect(rect)); } @end
// // main.m // Array_01 // // Created by selfimprovement on 15-6-1. // Copyright (c) 2015年 FoundationFramework. All rights reserved. // #import "FoundtionOftenStruct.h" #importint main(int argc, const char * argv[]) { @autoreleasepool { FoundtionOftenStruct *rangeStruct = [FoundtionOftenStruct alloc]; rangeStruct.testNsRange; rangeStruct.testNsPoit; rangeStruct.testNsRect; rangeStruct.testNsSize; } return 0; }
測試效果:
2015-06-04 15:12:56.567 Array_01[914:303] range is{3, 3}
2015-06-04 15:12:56.582 Array_01[914:303] {10, 5}
2015-06-04 15:12:56.586 Array_01[914:303] {{1, 3}, {10, 20}}
2015-06-04 15:12:56.587 Array_01[914:303] {10, 5}
Program ended with exit code: 0