标签:style blog http io ar color os 使用 sp
1
2
|
+ (NSValue *)valueWithRange:(NSRange)range - (NSRange)rangeValue |
1
2
3
4
5
6
7
8
9
10
11
12
13
|
NSRange rangeA ; rangeA.location = 0 ; rangeA.location = 10 ; // 创建NSRange的值对象 NSValue *rangeValue = [NSValue valueWithRange:rangeA] ; // 重新获取值对象包含的值 NSRange rangeB = [rangeValue rangeValue] ; NSLog(@ "%d,%d" ,rangeB.location , rangeB.length) ; // 10,10 |
1
2
3
|
+ (NSValue *)valueWithBytes:( const void *)value objCType:( const char *)type - (id)initWithBytes:( const void *)value objCType:( const char *)type - ( void )getValue:( void *)buffer |
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
|
// 结构体定义 typedef struct { int a ; float b ; }DataItem ; DataItem dataElemA ; dataElemA.a = 10 ; dataElemA.b = 10.005 ; NSValue *value = [NSValue valueWithBytes:&dataItem objCType:@encode(DataItem)] ; DataItem dataElemB ; [value getValue:&dataElemB] ; NSLog(@ "%d,%0.3f" ,dataElemB.a,dataElemB.b); // 10,10.005 |
1
2
3
4
5
6
7
8
9
10
11
12
13
|
/* INCORRECT! */ char *myCString = "This is a string." ; NSValue *theValue = [NSValue valueWithBytes:myCString objCType:@encode( char *)]; char *cc = ( char *)malloc( sizeof ( char *)*200) ; [theValue getValue:cc]; prinf( "%s" , cc) ; // This free(cc) |
1
2
3
|
char *myCString = "This is a string." ; NSString myNsString = [NSString stringWithCString:myCString encoding:NSUTF8StringEncoding] ; |
1
2
3
4
5
6
7
8
9
10
11
12
13
|
char *myCString = "This is a string." ; NSValue *theValue = [NSValue valueWithBytes:&myCString objCType:@encode( char **)]; char **cc = ( char **) malloc ( sizeof ( char **)*200) ; [theValue getValue:cc]; printf ( "----%s----" , *cc); // This is a string. free (cc) ; cc = NULL ; |
1
2
|
+ (NSValue *)valueWithPointer:( const void *)aPointer - ( void *)pointerValue |
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
|
DataItem *dd = (DataItem*) malloc ( sizeof (DataItem)) ; dd->a = 1 ; dd->b = 2 ; NSValue *pValue = [NSValue valueWithPointer:dd] ; DataItem *dc = (DataItem*)[pValue pointerValue] ; NSLog(@ "%d,%0.3f" ,dc->a,dc->b); free (dd) ; dd = NULL ; dc = NULL ; |
1
2
|
+ (NSValue *)valueWithCGPoint:(CGPoint)point - (CGPoint)CGPointValue |
1
2
3
4
5
6
7
8
9
|
CGPoint origin = CGPointMake(10.0 , 10.0) ; NSValue *ptValue = [NSValue valueWithCGPoint:origin] ; NSArray *ptArr = [NSArray arrayWithObject:ptValue]; NSValue *ptValueB = [ptArr objectAtIndex:0] ; CGPoint originB = [ptValueB CGPointValue] ;
|
标签:style blog http io ar color os 使用 sp
原文地址:http://www.cnblogs.com/iOS-mt/p/4106624.html