iOS & Stackmob - [NSNull length]: unrecognized selector sent to instance - ios

In my iOS app I'm trying to update user information in the database (with Stackmob), but I keep getting "unrecognized selector sent to instance."
- (IBAction)save:(UIButton *)sender {
NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] initWithEntityName:#"User"];
NSPredicate *predicte = [NSPredicate predicateWithFormat:#"username == %#", self.username];
[fetchRequest setPredicate:predicte];
[self.managedObjectContext executeFetchRequest:fetchRequest onSuccess:^(NSArray *results) {
NSManagedObject *todoObject = [results objectAtIndex:0];
[todoObject setValue:#"example#gmail.com" forKey:#"email"];
[self.managedObjectContext saveOnSuccess:^{
NSLog(#"You updated the todo object!");
} onFailure:^(NSError *error) {
NSLog(#"There was an error! %#", error);
}];
} onFailure:^(NSError *error) {
NSLog(#"Error fetching: %#", error);
}];
}
Here's the full error I'm getting:
-[NSNull length]: unrecognized selector sent to instance 0x1ec5678
2013-07-21 12:01:25.773 [29207:c07] *** Terminating app due to uncaught exception 'NSInvalidArgumentException',
reason: '-[NSNull length]: unrecognized selector sent to instance 0x1ec5678'
Thanks in advance.

I think it may because your self.username is empty. Note that if you are getting the username data from json , you can't use
if(username){...} but
if(![username isKindOfClass:[NSNull class]])
to avoid empty data because the json interpreter will generate an NSNull object.

Related

[__NSDictionaryI bytes]: unrecognized selector sent to instance

This is my code for getting postal code.
CLGeocoder *reverseGeocoder = [[CLGeocoder alloc] init];
[reverseGeocoder reverseGeocodeLocation:locationManager.location completionHandler:^(NSArray *placemarks, NSError *error)
{
NSLog(#"reverseGeocodeLocation:completionHandler: Completion Handler called!");
if (error){
NSLog(#"Geocode failed with error: %#", error);
return;
}
NSLog(#"Received placemarks: %#", placemarks);
CLPlacemark *myPlacemark = [placemarks objectAtIndex:0];
NSString *countryCode = myPlacemark.ISOcountryCode;
NSString *countryName = myPlacemark.country;
NSLog(#"My country code: %# and countryName: %#", countryCode, countryName);
}];
But its always crashing with NSInvalidArgumentException error,
2017-02-07 12:29:58.124 CBB[3654:270750] Lat : 42.771389 Long :
129.423340
2017-02-07 12:29:58.967 CBB[3654:270750] -[__NSDictionaryI bytes]: unrecognized selector sent to instance 0x600000473b80
2017-02-07 12:29:59.011 CBB[3654:270750] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSDictionaryI bytes]: unrecognized selector sent to instance 0x600000473b80'
bytes is NSData's property, so you use NSDictionary as NSData.

Terminating app due to uncaught > exception 'NSInvalidArgumentException'

This seems like it should be pretty straight forward - but alas, I'm getting a crash. I'm simply trying to set my UILabel with the text returned from the users_name field:
.m
NSMutableDictionary *viewParams = [NSMutableDictionary new];
[viewParams setValue:#"u000" forKey:#"view_name"];
[DIOSView viewGet:viewParams success:^(AFHTTPRequestOperation *operation, id responseObject) {
self.userData = [responseObject mutableCopy];
self.username.text = [self.userData objectForKey:#"users_name"];
dispatch_async(dispatch_get_main_queue(), ^(void){
});
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
NSLog(#"Failure: %#", [error localizedDescription]);
}];
The console data returns:
2016-04-05 12:25:36.877 [1331:350069] This is the Other User Data (
{
address = "Vancouver";
userbio = "There is currently no bio available for this user. If you have added your bio, and require assistance, please contact the Team.";
"users_name" = Brittany;
},
That said, this line is causing the crash:
self.username.text = [self.userData objectForKey:#"users_name"];
And this is the error:
2016-04-05 12:25:36.878 [1331:350069] -[__NSCFArray objectForKey:]:
unrecognized selector sent to instance 0x15a23c100 2016-04-05
12:25:36.881 [1331:350069] * Terminating app due to uncaught
exception 'NSInvalidArgumentException', reason: '-[__NSCFArray
objectForKey:]: unrecognized selector sent to instance 0x15a23c100'
* First throw call stack: (0x181d51900 0x1813bff80 0x181d5861c 0x181d555b8 0x181c5968c 0x1000cce9c 0x1000c72bc 0x1000d3cc4
0x100459bf0 0x100459bb0 0x10045f658 0x181d08bb0 0x181d06a18
0x181c35680 0x183144088 0x186aacd90 0x1000d4c88 0x1817d68b8)
libc++abi.dylib: terminating with uncaught exception of type
NSException
How might I fix this? It seems like it should be simple...
I suppose userData is an Array type. Array have no key values.
Try: [[self.userData objectAtIndex:0] objectForKey:#"users_name"];

Multi NSDictionary returns string instead of child

I am trying to access keys from a multi NSDictionary.
This is my output from NSLog
Berlijn[23667:60b] data = {
1 = {
data = (
4,
0,
0,
0
);
key = "June 2014";
};
}
When I try to loop through this dictionary and log the key I get NSInvalidArgumentException because key is a NSString.
This is my current code:
- (void) updateRating: (int) companyID {
APICaller *api = [[APICaller alloc] init];
[api setUrl:#"http://domain.examle/api/getcompanyhistory.php"];
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
NSDictionary *parameters = #{
#"token": [[[FBSession activeSession] accessTokenData] accessToken],
#"device_token" : [defaults stringForKey:#"uniqueToken"],
#"companyid" : #(companyID)
};
[api setParameters: parameters];
[api sendPostRequest: ^(AFHTTPRequestOperation *operation, id responseObject) {
NSLog(#"data = %#", responseObject);
for(NSDictionary *contentData in responseObject) {
NSLog(#"contentData = %#", [contentData objectForKey:#"key"]);
}
[self.tableView reloadData];
}: ^(AFHTTPRequestOperation *operation, NSError *error) {
NSLog(#"Error: %#", error);
}];
}
As NSDictionary is a dictionary I don't know why it returns a string.
Update (error message):
2014-06-02 01:41:41.386 Berlijn[23747:60b] -[__NSCFString objectForKey:]: unrecognized selector sent to instance 0x1784253e0
2014-06-02 01:41:41.387 Berlijn[23747:60b] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFString objectForKey:]: unrecognized selector sent to instance 0x1784253e0'
*** First throw call stack:
(0x1860a309c 0x192021d78 0x1860a7d14 0x1860a5a7c 0x185fc54ac 0x1000eb8ac 0x1000ea014 0x1925f0420 0x1925f03e0 0x1925f356c 0x186062d64 0x1860610a4 0x185fa1b38 0x18b9c7830 0x188fe00e8 0x1000eaff4 0x19260baa0)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb)
Just because you call contentData a dictionary does NOT make it one.
Fast enumeration of a dictionary iterates over keys, NOT values. Your key is a string (even though you call it an NSDictionary) and will throw an exception when you try to call objectForKey: on it.
Since responseObject is a dictionary you can iterate over the keys AND values using enumerateKeysAndObjectsUsingBlock:(void (^)(id key, id obj, BOOL *stop)).
Another option is to use fast enumeration correctly like so...
for(NSString *key in responseObject) {
NSLog(#"contentData = %#", [responseObject objectForKey:key]);
}

Why do i get an error comparing NSString's? (-[__NSCFNumber isEqualToString:]: unrecognized selector sent to instance)

I have a NSMutableArray (_theListOfAllQuestions) that I am populating with numbers from a file. Then I compared the objects in that array with qNr (NSString) and I got error. I even casted the array to another NSString, _checkQuestions, just to be sure I am comparing NSStrings. I tested using item to compare also.
-(void)read_A_Question:(NSString *)qNr {
NSLog(#"read_A_Question: %#", qNr);
int counter = 0;
for (NSString *item in _theListOfAllQuestions) {
NSLog(#"item: %#", item);
_checkQuestions = _theListOfAllQuestions[counter]; //_checkQuestion = NSString
NSLog(#"_checkQuestions: %#", _checkQuestions);
if ([_checkQuestions isEqualToString:qNr]) {
NSLog(#">>HIT<<");
exit(0); //Just for the testing
}
counter++;
}
When running this code i get the following NSLog:
read_A_Question: 421
item: 1193
_checkQuestions: 1193
...and error:
-[__NSCFNumber isEqualToString:]: unrecognized selector sent to instance 0x9246d80
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFNumber
isEqualToString:]: unrecognized selector sent to instance 0x9246d80'
I do believe that I still comparing NSString with a number of some sort but to me it looks like I am comparing NSString vs. NSString?
I could really need some help here to 1) understand the problem, 2)solve the problem?
Replace this line
if ([_checkQuestions isEqualToString:qNr])
with
if ([[NSString stringWithFormat:#"%#",_checkQuestions] isEqualToString:[NSString stringWithFormat:#"%#",qNr]])
Hope it helps you..
Your _theListOfAllQuestions array has NSNumber objects and not NSString objects. So you cant use isEqualToString directly.
Try this,
for (NSString *item in _theListOfAllQuestions) {
NSLog(#"item: %#", item);
_checkQuestions = _theListOfAllQuestions[counter]; //_checkQuestion = NSString
NSLog(#"_checkQuestions: %#", _checkQuestions);
if ([[_checkQuestions stringValue] isEqualToString:qNr]) {
NSLog(#">>HIT<<");
exit(0); //Just for the testing
}
counter++;
}

problem with searching using specific NSDate in Core Data

I am using the following code to search for a specific date entry in Core Data :
//NSDate *tempDate=<a date element fetched from a core data query>
NSManagedObjectContext *context=[self managedObjectContext];
RecentMovieInfo *recent3 = nil;
request = [[NSFetchRequest alloc] init];
entity=[NSEntityDescription entityForName:#"RecentMovies" inManagedObjectContext:context2];
[request setEntity:entity];
[request setPredicate:[NSPredicate predicateWithFormat:#"DateTime=%#",tempDate]];
recent3 = [[context2 executeFetchRequest:request error:&error] lastObject];
However, I am getting the following error:
2011-08-03 15:28:59.573 EncameoApp[2447:707] -[__NSArrayI timeIntervalSinceReferenceDate]: unrecognized selector sent to instance 0x2c4640
2011-08-03 15:28:59.641 EncameoApp[2447:707] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSArrayI timeIntervalSinceReferenceDate]: unrecognized selector sent to instance 0x2c4640'
Any help ?
How do you set tempDate? Are you sure it's an NSDate and not an NSArray?
The error you're getting says that you're trying to call the selector timeIntervalSinceReferenceDate on a class (in this case an __NSArrayI) that doesn't respond to that selector.

Resources