小编Had*_*adi的帖子

alloc + init内存使用机制

我只是想知道一个对象何时被alloc分配,并且分配了一块内存,为什么init不使用那段内存并更改对象的地址?

NSDate *t = nil;
NSLog(@"t = %p",t); // t = 0x0 

t = [NSDate alloc];
NSLog(@"t = %p",t); // t = 0x100107af0

t = [t init];
NSLog(@"t = %p",t); // t = 0x1001035a0
Run Code Online (Sandbox Code Playgroud)

objective-c foundation

8
推荐指数
1
解决办法
151
查看次数

静态NSMutableArray和多线程用法的含义

static以下代码究竟做了什么,何时应该或更好地使用Static:

// Returns an array of 30 odd numbers
- (NSArray *)odds
{
static NSMutableArray *odds;
odds = [[NSMutableArray alloc] init];
int i = 1;
while ([odds count] < 30) {
[odds addObject:[NSNumber numberWithInt:i]];
i += 2;
}
return odds;
}
Run Code Online (Sandbox Code Playgroud)

objective-c

-6
推荐指数
1
解决办法
525
查看次数

标签 统计

objective-c ×2

foundation ×1