以下是代码:
NSData * imageData = [NSData dataWithContentsOfURL:imageURL];
[imageData writeToFile:savedImagePath options:NSDataWritingAtomic error:&error];
if(error != nil)
NSLog(@"write error %@", error);
Run Code Online (Sandbox Code Playgroud)
错误:
write error Error Domain=NSCocoaErrorDomain Code=4 "The operation couldn’t be completed. (Cocoa error 4.)" UserInfo=0x8b7b850 {NSUnderlyingError=0x8b7d7c0 "The operation couldn’t be completed. No such file or directory", NSFilePath=/Users/alfa-1/Library/Application Support/iPhone Simulator/6.0/Applications/C24B228A-599E-4249-97A7-17775E8A546B/Library/Caches/ChannelListImages/http:/direct.domain.com/files/icons/1-all-cb.jpg, NSUserStringVariant=Folder}
Run Code Online (Sandbox Code Playgroud) 我试图从数组中删除重复的对象.
NSMutableArray* filterResults = [[NSMutableArray alloc] init];
BOOL copy;
// remove duplicate
if (![arrSelectedVehicle count] == 0)
{
for (Vehicles *a1 in arrSelectedVehicle) {
copy = YES;
for (Vehicles *a2 in filterResults) {
if ([a1.Vehicle_id isEqualToString:a2.Vehicle_id]) {
copy = NO;
[arrSelectedVehicle removeObjectIdenticalTo:a2];
break;
}
}
if (copy) {
[filterResults addObject:a1];
}
}
}
Run Code Online (Sandbox Code Playgroud)
我正在添加两个已经在数组中的对象
下面是我的代码我无法播放SnareHitSample.wav文件.我不知道我哪里出错了.
-(void)playAudioFiles
{
NSString * path;
AVAudioPlayer * snd;
NSError * err;
NSString *name;
name = @"SnareHitSample.wav";
path = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:name];
if ([[NSFileManager defaultManager] fileExistsAtPath:path]) {
NSURL * url = [NSURL fileURLWithPath:path];
snd = [[AVAudioPlayer alloc] initWithContentsOfURL:url
error:&err] ;
if (! snd) {
NSLog(@"Sound named '%@' had error %@", name, [err localizedDescription]);
} else {
[snd prepareToPlay];
}
} else {
NSLog(@"Sound file '%@' doesn't exist at '%@'", name, path);
}
}
Run Code Online (Sandbox Code Playgroud)