我在我的代碼中有一個NSMutableArray
,我想訪問該數組的最後一個元素並將該元素保存在整數n
變量中。但n
不給我正確的價值,當我NSLog
它,它給了我一個垃圾值。NSMutableArray不會返回值並分配給變量
for(int i=0;i<[array3 count];i++)
{
if(i==([array3 count]-1))
{
n = [array3 objectAtIndex:i];
}
}
NSLog(@"The id is=%d",n);
NSError *error;
NSString *aDocumentsDirectory = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject];
NSString *dataPath = [aDocumentsDirectory stringByAppendingPathComponent:[NSString stringWithFormat:@"%d",n]];
[[NSFileManager defaultManager] createDirectoryAtPath:dataPath withIntermediateDirectories:NO attributes:nil error:&error];
如果n是int類型,它將不起作用。因爲數組只保存對象而int不是對象。 – user523234
n是int類型的,但它給了我垃圾值。 – Nasir
您不能直接將int存儲在NSMutableArray中。粘貼代碼添加對象的位置 –