Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/42.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone 向NSMutableArray添加新对象_Iphone_Objective C_Nsmutablearray - Fatal编程技术网

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);
}