Hello i have a UIImageview and trying to set the image which was previously saved in a NSArray and then the NSArray is saved into an NSMutableDictionary. Here is the error and the code. Any help appreciated.
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFConstantString _isSymbolImage]: unrecognized selector sent to instance 0x100e14318' terminating with uncaught exception of type NSException
myAppDelegate *appDelegate = (myAppDelegate *)[UIApplication sharedApplication].delegate;
NSMutableArray *allKeys = [[appDelegate.localDataForIngestAndErrorVideos allKeys] mutableCopy];
for (NSString *key in allKeys) {
NSArray *object = (NSArray*)[appDelegate.localDataForIngestAndErrorVideos objectForKey:key];
NSLog(@"id object ingest: %@",[object objectAtIndex:0]);
if ( [cell.Model.ContentItem.videoUploadStatus isEqualToString:@"ingest"])
{
cell.Model.ContentItem.mediaVideoUriHls = (NSURL*)[object objectAtIndex:2];
UIImage *tempImage = [[UIImage alloc]init];
tempImage = [object objectAtIndex:1];
[cell.mediaImageView setImage:tempImage]; <=== here crashes
}
}
The error [__NSCFConstantString _isSymbolImage]: unrecognized selector sent to instance
is saying this:
Let's translate first: __NSCFConstantString
is a inner (optimized) class for NSString
, so just consider it as NSString
So you have NSString
instance and you try to call _isSymbolImage
method on it. That method is hidden, it's an under the hood call from iOS SDK.
But that method doesn't exists on NSString
, it doesn't know it, hence the error you are getting.
Seeing the crash line:
[cell.mediaImageView setImage:tempImage];
The inner method called makes sense, you are treating tempImage
as it were an UIImage
.
So [object objectAtIndex:1]
is a NSString
not a UIImage
.
Now, I'd suggest to use custom model for your NSDictionary
appDelegate.localDataForIngestAndErrorVideos
. It's better than handling NSArray
/NSDictionary
without knowing what's inside it each time.
You could also add to it methods/compute properties like -(NSURL)ingestURL
, etc to make your code easier and more readable.
Side note:
UIImage *tempImage = [[UIImage alloc]init];
tempImage = [object objectAtIndex:1];
The alloc/init is useless, since you are setting the value. You are doing an alloc/init for nothing, since you are ignoring it just after.