标签:
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 <Foundation/Foundation.h> @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 <Foundation/Foundation.h> 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
标签:
原文地址:http://blog.csdn.net/u010236550/article/details/46362057