In my Singleton Class,I used [UIImage imageNamed:] in the block of dispatch_once,it sometimes crash,I have thought many days,my image is stored in my App(Not in Assets,In My custom Resource File),it's unbelievable,who can tell me why?
This is my Code
static dispatch_once_t onceToken;
static AClass *manager = nil;
dispatch_once(&onceToken, ^{
manager = [[AClass alloc] init];
dispatch_async(dispatch_get_global_queue(0, 0), ^{
NSMutableArray * imgDataList = [NSMutableArray array];
for (int i=0; i<=15; i++) {
NSString *imageName=[NSString stringWithFormat:@"imageNamedxx_%d@2x.png",i];
UIImage * img = [UIImage imageNamed:imageName];
if (img) {
[imgDataList addObject:img];
}
}
dispatch_async(dispatch_get_main_queue(), ^{
manager.liveImgData = [imgDataList copy];
});
});
});
return manager;
}
1
libobjc.A.dylib
objc_exception_throw
2
CoreFoundation
-[CFPrefsSearchListSource addManagedSourceForIdentifier:user:]
3
Foundation
-[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:]
4
UIKitCore
-[_UIImageCGImageContent initWithCGImage:scale:]
5
UIKitCore
-[CUINamedImage(UIKitAdditions) UIImageWithAsset:configuration:flippedHorizontally:optionalVectorImage:]
6
UIKitCore
-[UIImageAsset imageWithConfiguration:]
7
UIKitCore
-[_UIPathLazyImageAsset imageWithConfiguration:]
8
UIKitCore
+[UIImage imageNamed:inBundle:withConfiguration:]
myApp
AClass - 第 42 行([UIImage imageNamed:])
__34+[AClass shareInstance]_block_invoke_2 + 42