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"#import測试效果:int 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