Iphone 向NSMutableArray添加新对象
我有一个名为Iphone 向NSMutableArray添加新对象,iphone,objective-c,nsmutablearray,Iphone,Objective C,Nsmutablearray,我有一个名为Profile的自定义类和一个NSMutableArray,我添加了Profile对象,以防在迭代中来回移动 代码如下: @try { currentProfile = (Profile *) [cache objectAtIndex:(int)currentPosition-1]; } @catch (NSException * e) { Profile *cached = [[Profile alloc] init]; [cached loadProfil
Profile
的自定义类和一个NSMutableArray
,我添加了Profile对象,以防在迭代中来回移动
代码如下:
@try {
currentProfile = (Profile *) [cache objectAtIndex:(int)currentPosition-1];
}
@catch (NSException * e) {
Profile *cached = [[Profile alloc] init];
[cached loadProfile:currentPosition orUsingUsername:nil appSource:source];
cached.position = NULL;
[cache addObject:cached];
currentProfile = cached;
[cached release];
}
//And the "log" i use to show the error
Profile *temp;
for (int i=0; i<[cache count]; i++) {
temp = (Profile *) [cache objectAtIndex:(int)currentPosition-1];
NSLog(@"%@ - %d e %d", temp.name, temp.position, temp.realId);
}
[temp release];
@试试看{
currentProfile=(Profile*)[cache objectAtIndex:(int)currentPosition-1];
}
@捕获(N例外*e){
Profile*cached=[[Profile alloc]init];
[缓存的loadProfile:currentPosition或UsingUserName:nil appSource:source];
cached.position=NULL;
[cache addObject:cached];
currentProfile=cached;
[缓存释放];
}
//以及我用来显示错误的“日志”
外形*温度;
对于(int i=0;i您可能希望在循环中使用变量i
,而不是currentPosition
for (int i=0; i<[cache count]; i++) {
temp = (Profile *) [cache objectAtIndex:i];
NSLog(@"%@ - %d e %d", temp.name, temp.position, temp.realId);
}
^^你回答得更快,不需要两次相同的帖子,所以删除mine@Jason看看,他们有一些有用的通知工具:)上帝,谢谢你!!这很快而且非常有用。我觉得自己很愚蠢=(
for (Profile *temp in cache) {
NSLog(@"%@ - %d e %d", temp.name, temp.position, temp.realId);
}