// main.m
#import <Foundation/Foundation.h>
@interface TestObject : NSObject
{
@public
int x;
int y;
}
@end
@implementation TestObject
@end
typedef struct TestStruct
{
int x;
int y;
}
TestStruct;
int main(int argc, const char * argv[])
{
@autoreleasepool {
TestStruct ts1 = {100, 50};
NSLog(@"ts1: %p, %d, %d", &ts1, ts1.x, ts1.y);
TestStruct ts2 = ts1;
NSLog(@"ts2: %p, %d, %d", &ts2, ts2.x, ts2.y);
TestObject* to1 = [[[TestObject alloc] init] autorelease];
NSLog(@"to1: %p, %d, %d", to1, to1->x, to1->y);
TestObject* to2 = to1;
NSLog(@"to2: %p, %d, %d", to2, to2->x, to2->y);
}
return 0;
}
ts1: 0x7fff63463898, 100, 50 ts2: 0x7fff63463890, 100, 50 to1: 0x7fc342d00370, 0, 0 to2: 0x7fc342d00370, 0, 0
#import <Foundation/Foundation.h>
@interface TestObject : NSObject
{
@public
int x;
int y;
}
@end
@implementation TestObject
- (NSString*)description
{
return [NSString stringWithFormat:@"%@: %p, x: %d, y: %d", [self class], self, x, y];
}
@end
typedef struct TestStruct
{
int x;
int y;
}
TestStruct;
int main(int argc, const char * argv[])
{
@autoreleasepool
{
TestObject* to1 = [[[TestObject alloc] init] autorelease];
to1->x = 100; to1->y = 50;
TestObject* to2 = [[[TestObject alloc] init] autorelease];
to2->x = 200; to2->y = 400;
TestObject* to3 = [[[TestObject alloc] init] autorelease];
to3->x = 300; to3->y = 500;
//创建包含to1, to2, to3的数组array1
NSArray* array1 = [NSArray arrayWithObjects:to1, to2, to3, nil];
NSLog(@"array1: %p, \n%@", array1, array1);
//array2是array1调用copy的结果
NSArray* array2 = [array1 copy];
NSLog(@"array2: %p, \n%@", array2, array2);
[array2 release];
//mutableArray2是array1调用mutableCopy的结果
NSMutableArray* mutableArray2 = [array1 mutableCopy];
NSLog(@"mutableArray2: %@, %p, \n%@", [mutableArray2 class], mutableArray2, mutableArray2);
[mutableArray2 removeLastObject];
NSLog(@"After remove last object of mutableArray2");
NSLog(@"array1: %p, \n%@", array1, array1);
NSLog(@"array2: %p, \n%@", array2, array2);
NSLog(@"mutableArray2: %p, \n%@", mutableArray2, mutableArray2);
//mutableArray3是mutableArray2调用mutableCopy的结果
NSMutableArray* mutableArray3 = [mutableArray2 mutableCopy];
NSLog(@"mutableArray3: %p, \n%@", mutableArray3, mutableArray3);
[mutableArray2 release];
//array4是mutableArray3调用copy的结果
NSArray* array4 = [mutableArray3 copy];
NSLog(@"array4: %@, %p, \n%@", [array4 class], array4, array4);
[mutableArray3 release];
[array4 release];
}
return 0;
}
2012-03-22 19:20:49.548 ObjectCopy[18042:403] array1: 0x7f9071414820, ( "TestObject: 0x7f90714141b0, x: 100, y: 50", "TestObject: 0x7f90714141c0, x: 200, y: 400", "TestObject: 0x7f9071414230, x: 300, y: 500" ) 2012-03-22 19:20:49.550 ObjectCopy[18042:403] array2: 0x7f9071414820, ( "TestObject: 0x7f90714141b0, x: 100, y: 50", "TestObject: 0x7f90714141c0, x: 200, y: 400", "TestObject: 0x7f9071414230, x: 300, y: 500" ) 2012-03-22 19:20:49.551 ObjectCopy[18042:403] mutableArray2: __NSArrayM, 0x7f9072800000, ( "TestObject: 0x7f90714141b0, x: 100, y: 50", "TestObject: 0x7f90714141c0, x: 200, y: 400", "TestObject: 0x7f9071414230, x: 300, y: 500" ) 2012-03-22 19:20:49.552 ObjectCopy[18042:403] After remove last object of mutableArray2 2012-03-22 19:20:49.552 ObjectCopy[18042:403] array1: 0x7f9071414820, ( "TestObject: 0x7f90714141b0, x: 100, y: 50", "TestObject: 0x7f90714141c0, x: 200, y: 400", "TestObject: 0x7f9071414230, x: 300, y: 500" ) 2012-03-22 19:20:49.553 ObjectCopy[18042:403] array2: 0x7f9071414820, ( "TestObject: 0x7f90714141b0, x: 100, y: 50", "TestObject: 0x7f90714141c0, x: 200, y: 400", "TestObject: 0x7f9071414230, x: 300, y: 500" ) 2012-03-22 19:20:49.553 ObjectCopy[18042:403] mutableArray2: 0x7f9072800000, ( "TestObject: 0x7f90714141b0, x: 100, y: 50", "TestObject: 0x7f90714141c0, x: 200, y: 400" ) 2012-03-22 19:20:49.557 ObjectCopy[18042:403] mutableArray3: 0x7f90729000d0, ( "TestObject: 0x7f90714141b0, x: 100, y: 50", "TestObject: 0x7f90714141c0, x: 200, y: 400" ) 2012-03-22 19:20:49.558 ObjectCopy[18042:403] array4: __NSArrayI, 0x7f9071416e70, ( "TestObject: 0x7f90714141b0, x: 100, y: 50", "TestObject: 0x7f90714141c0, x: 200, y: 400" )
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有