With these lines of code:
PayPalPayment *payment = [[PayPalPayment alloc] init];
NSLog(#"Price %#",[self.product objectForKey:#"Price"]);
NSString *string = [self.product objectForKey:#"Price"];
payment.amount = [[NSDecimalNumber alloc] initWithString:string];
my app is crashing with this log:
[NSDecimalNumber length]: unrecognized selector sent to instance
The NSLog is returning:
Price 96.67
Whay is it crashing???
I would guess that you have a type problem, most likely with the object at
[self.product objectForKey:#"Price"];
My guess is that this object is already an NSDecimalNumber, and when you treat it as a string and then call the initWithString method using it, bad things happen
put a breakpoint at:
payment.amount = [[NSDecimalNumber alloc] initWithString:string];
and then type po [string class] into the debugger.
This will show you the type of object stored at [self.product objectForKey:#"Price"];
It looks like your string object isn't an NSString. Looks like it's actually an NSDecimalNumber - set a breakpoint there and inspect the object. What kind of object is self.product?
Related
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.
Hi I am getting this data form server
NSDictionary*feed=[saveDic objectForKey:#"feed"];
NSLog(#"%#",feed); //Outputs: feed = ( { code = yQ7j0t; "user_id" = 889445341091863; } ); }
NSLog(#"%#",[feed valueForKey:#"code"]);
NSString *referralCode = [feed valueForKey:#"code"];
NSLog(#"%#",referralCode);
self.referralCode.text=referralCode;
And beacuse of that I am getting below error.
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSArrayI length]: selector sent to instance 0x165d5150'``
Any help will be appreciated.
The issue is, your feed key holds an array. You are not properly handling that in your code, that is why the crash occurs. When you call valueForKey: it retrieves an array of values held by that specific key.
For fixing that you can use:
NSArray *feed = [saveDic objectForKey:#"feed"];
NSArray *referralCodes = [feed valueForKey:#"code"];
NSString *referralCode = referralCodes.count ? referralCodes[0] : #"";
NSLog(#"%#",referralCode);
But I personally prefer using objectForKey: instead of valueForKey:. So you can re-write the code like:
NSArray *feed = [saveDic objectForKey:#"feed"];
NSString *referralCode = feed.count ? [feed[0] objectForKey:#"code"] : #"";
NSLog(#"%#",referralCode);
Some where you use a variable;
yourVaribleName.length
or
[yourVaribleName length]
which should be
yourVaribleName.count
note: the crash says exactly that "yourVaribleName" is NSArray type where you wants length of the NSArray. But NSArray has not feature "length". NSArray has "Count" feature
//try with this code bellow
NSArray *referralCode = [feed valueForKey:#"code"];
NSLog(#"%#",referralCode);
self.referralCode.text=[referralCode componentsJoinedByString:#" "];//#"," or #"" what event you need
Your feed data is in array. So you have retrieve code value from array.Hope it will help you.
NSMutableArray*feed=[saveDic objectForKey:#"feed"];
NSLog(#"%#",feed);
NSLog(#"%#",[feed valueForKey:#"code"]);
NSString *referralCode = [[feed objectAtIndex:indexPath]valueForKey:#"code"];
NSLog(#"%#",referralCode);
self.referralCode.text=referralCode;
I can't figure out why this string is null inside the FQuery block. My app keeps crashing when I build the dailyLog MutableDictionary at the user key;
NSDateFormatter *df = [[NSDateFormatter alloc] init];
[df setDateFormat:#"MMMM dd, YYYY"];
NSString *userID = [[self.userProfile objectForKey:#"userID"] copy];
self.logFirebase = [[Firebase alloc] initWithUrl:#"https://urlName.firebaseio.com/DailyLog"];
[[[self.logFirebase queryOrderedByPriority] queryEqualToValue:userID childKey:#"userID"] observeEventType:FEventTypeValue withBlock:^(FDataSnapshot *snapshot) {
if (![snapshot.value isEqual:[NSNull null]]) {
NSMutableArray *data = [CGCFirebaseDataExtractor extractKeysAndObjects:snapshot.value];
self.dailyLog = [data filteredArrayUsingPredicate:[NSPredicate predicateWithFormat:#"Name CONTAINS[cd] %#",[df stringFromDate:[NSDate date]]]].lastObject;
}else{
self.dailyLog = [[NSMutableDictionary alloc] init];
NSLog(#"users Profile:%#",self.userProfile);
NSLog(#"users ID :%#",[self.userProfile objectForKey:#"userID"]);
[self.dailyLog setObject:[df stringFromDate:[NSDate date]] forKey:#"date"];
[self.dailyLog setObject:[self.userProfile objectForKey:#"userID"] forKey:#"user"];
[self.dailyLog setObject:[NSNumber numberWithInt:450] forKey:#"calories"];
[[self.logFirebase childByAutoId] setValue:self.userProfile];
}
}];
EDIT:
When I log self.userProfile, I get the proper info I want. But when I log the userID itself from within the FQuery block, it's null
Here is my updated crash data:
2015-05-08 13:21:22.709 <appname>[4160:1321097] users Profile:{
"-JoirTqCXFFDY1psLTNn" = {
dateRegistered = "1431010405.81792";
userID = "304D92EF-CE77-4A10-A55F-9847153699F7";
userName = "User's Name";
};
}
2015-05-08 13:21:22.709 <appname>[4160:1321097] users ID :(null)
2015-05-08 13:21:22.714 <appname>[4160:1321097] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** setObjectForKey: object cannot be nil (key: user)'
*** First throw call stack:
(0x1852082d8 0x196a340e4 0x1850f1428 0x10007de00 0x1001454d0 0x100390fd4 0x100390f94 0x100395c28 0x1851bf7f8 0x1851bd8a0 0x1850e92d4 0x18e8ff6fc 0x189caefac 0x10007f14c 0x1970b2a08)
libc++abi.dylib: terminating with uncaught exception of type NSException
Sorry, I'm an idiot and didn't look closely at your log.
2015-05-08 13:21:22.709 <appname>[4160:1321097] users Profile:{
"-JoirTqCXFFDY1psLTNn" = {
dateRegistered = "1431010405.81792";
userID = "304D92EF-CE77-4A10-A55F-9847153699F7";
userName = "User's Name";
};
This object is evidently a dictionary in a dictionary. The first (outer) dictionary has key "-JoirTqCXFFDY1psLTNn" and that is its only key. That is why trying to get the key userID fails; that key is part of the second (inner) dictionary.
When processing a json response I a get the below error:
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[DADGList setDescription:]:
unrecognized selector sent to instance 0x7ae88880'
The class it crashed on:
#implementation DADGList
-(id)copy
{
DADGList *list = [[DADGList alloc] init];
list.identifier = self.identifier;
list.name = [self.name copy];
list.description = [self.description copy];
list.created = [self.created copy];
list.itemCount = self.itemCount;
list.shareLink = [self.shareLink copy];
return list;
}
+(DADGList *)listFromDictonary:(NSDictionary *)dictonary
{
DADGList *list = [[DADGList alloc] init];
NSLog( #"%#", dictonary );
list.identifier = [[dictonary objectForKey:#"list_id"] integerValue];
list.itemCount = [[dictonary objectForKey:#"list_items_count"] integerValue];
list.name = [NSString stringWithString:[dictonary objectForKey:#"list_name"]];
list.description = [NSString stringWithString:[dictonary objectForKey:#"list_description"]];
list.created = [[NSDate alloc] initWithTimeIntervalSince1970:[[dictonary objectForKey:#"list_created"] doubleValue]];
list.shareLink = [NSString stringWithString:[dictonary objectForKey:#"list_share_url"]];
return list;
}
and the dictonary that is past to listFromDictonary:
You should rename your description property for something else as this is a field already existing in the iOS echosystem (NSObject if I am not mistaken) and that creates all sort of weird crash like this.
If you are using core data maybe you need to implement the following instance:
Mall(entity: NSEntityDescription.entity(forEntityName: "Mall", in: context)!, insertInto: nil)
Where Mall is my entity and context is my view context.
I have a simple value in an NSSTRING that I want to convert to an NSNumber. I do this all the time in my code and for some reason, this time it is not working. Do you see anything wrong with this?
NSNumberFormatter * num_formatter = [[NSNumberFormatter alloc] init];
[num_formatter setNumberStyle:NSNumberFormatterDecimalStyle];
NSNumber *score;
NSString *mystr = [[player ScoresArray] objectAtIndex:currentKeeper - 1];
NSLog(#"here is my string: -%#-", mystr);
score = [num_formatter numberFromString:mystr]; // crash occurs on this line. see error below...
NSLog(#"now it is: %d", [score intValue]); // it never gets to this line...
Here is the output from the above code:
here is my string: -3-
Here is the error I get:
2013-02-26 17:21:48.912 Golf Whiz[50407:c07] -[__NSCFNumber isEqualToString:]: unrecognized selector sent to instance 0xcb5fa90
2013-02-26 17:21:48.912 Golf Whiz[50407:c07] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFNumber isEqualToString:]: unrecognized selector sent to instance 0xcb5fa90'
*** First throw call stack:
Make sure the objects you're adding to ScoresArray are in fact strings, not NSNumbers.
Thanks, all, as suspected, it turns out that I did have nsnumber objects in the scoresArray afterall.