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.
Related
I was trying to save some data into fire base.So the format is like am adding contents into NSMutableDictionary and then am adding that into NSMutableArray and sending to FireBase.For first time it was working when i tried to add second contents its crashing with following message
2014-12-08 14:36:43.388 ChangeText[1634:576618] -[__NSArrayI addObject:]: unrecognized selector sent to instance 0x17023e580
2014-12-08 14:36:43.392 ChangeText[1634:576618] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSArrayI addObject:]: unrecognized selector sent to instance 0x17023e580'
*** First throw call stack:
(0x184db259c 0x1954c00e4 0x184db9664 0x184db6418 0x184cbab6c 0x1000fce74 0x189598d34 0x189581e48 0x1895986d0 0x18959835c 0x1895918b0 0x189564fa8 0x189803f58 0x189563510 0x184d6a9ec 0x184d69c90 0x184d67d40 0x184c950a4 0x18de3f5a4 0x1895ca3c0 0x1000fd7ec 0x195b2ea08)
libc++abi.dylib: terminating with uncaught exception of type NSException
My code
Viewdidload
arr=[[NSMutableArray alloc]init];
Firebase *fire=[[Firebase alloc]initWithUrl:#"http://del.firebaseio.com/users"];
[fire observeEventType:FEventTypeValue withBlock:^(FDataSnapshot *snapshot) {
// self.status.text=snapshot.value;
NSLog(#"snapshot%#",snapshot.value);
arr=[snapshot.value copy];
NSLog(#"copied%#",arr);
}];
Button to add values into Firebase
// arr=[[NSMutableArray alloc]init];
dict=[[NSMutableDictionary alloc]init];
[dict setValue:#"test1" forKey:#"username"];
[dict setValue:#"test2" forKey:#"password"];
[dict setValue:#"test3" forKey:#"profilepic"];
[dict setValue:#"test4" forKey:#"profile"];
[dict setValue:#"test5" forKey:#"details"];
[arr addObject:dict];
NSLog(#"added new elements%#",arr);
Firebase *f=[[Firebase alloc]initWithUrl:#"http://del.firebaseio.com/users"];
[f setValue:arr ];
My console logs
2014-12-08 14:36:32.017 ChangeText[1634:576618] snapshot(
{
details = test5;
password = test2;
profile = test4;
profilepic = test3;
username = test1;
}
)
2014-12-08 14:36:32.019 ChangeText[1634:576618] copied(
{
details = test5;
password = test2;
profile = test4;
profilepic = test3;
username = test1;
}
)
2014-12-08 14:36:43.388 ChangeText[1634:576618] -[__NSArrayI addObject:]: unrecognized selector sent to instance 0x17023e580
2014-12-08 14:36:43.392 ChangeText[1634:576618] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSArrayI addObject:]: unrecognized selector sent to instance 0x17023e580'
*** First throw call stack:
(0x184db259c 0x1954c00e4 0x184db9664 0x184db6418 0x184cbab6c 0x1000fce74 0x189598d34 0x189581e48 0x1895986d0 0x18959835c 0x1895918b0 0x189564fa8 0x189803f58 0x189563510 0x184d6a9ec 0x184d69c90 0x184d67d40 0x184c950a4 0x18de3f5a4 0x1895ca3c0 0x1000fd7ec 0x195b2ea08)
libc++abi.dylib: terminating with uncaught exception of type NSException
Please help me to fix this error
[arr addObject:dict]; is creating the crash in this case, since arr is Immutable.
arr=[snapshot.value copy]; gives you an immutable copy of object. You could try with
arr=[snapshot.value mutableCopy];
arr = [snapshot.value copy];
The above line assigns NSArray type instance to your arr object. That's the reason when you try to add objects in your array, it gets crashed because the current instance is of type NSArray, not NSMutableArray. Replace above line with the following line:
[arr addObjectsFromArray:snapshot.value];
I am trying to create a NSFetchedResultsController with a request to get photos from a specific region. I have two models Region and Photo in my core data. Below is my code of where I am getting the error:
- (void)setRegion:(Region *)region
{
_region = region;
// Making a request for the particular region
NSFetchRequest *request = [NSFetchRequest fetchRequestWithEntityName:#"Photo"];
request.sortDescriptors = [NSSortDescriptor sortDescriptorWithKey:#"name" ascending:YES selector:#selector(localizedStandardCompare:)];
request.predicate = [NSPredicate predicateWithFormat:#"fromRegion = %#", region];
NSLog(#"%#", region.name);
self.fetchedResultsController = [[NSFetchedResultsController alloc] initWithFetchRequest:request
managedObjectContext:[region managedObjectContext]
sectionNameKeyPath:nil
cacheName:nil];
}
I am receiving the following errors:
-[NSSortDescriptor countByEnumeratingWithState:objects:count:]: unrecognized selector sent to instance 0x8d67850
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NSSortDescriptor countByEnumeratingWithState:objects:count:]: unrecognized selector sent to instance 0x8d67850'
I don't understand why I am receiving it. All I am doing is retrieving photos from the database that contains a specific region. However, I am receiving as error on the self.fetchedResultsController line. This core data tableview controller that contains this code is actually the designation view controller from another core data tableview controller.
I have looked around for other solutions but they only deal with problems related to looping through the self.fetchedResultsController which I am not doing. I am only displaying the photos in a tableview from the fetchedResultsController.
The problem is here:
request.sortDescriptors = [NSSortDescriptor sortDescriptorWithKey:#"name" ascending:YES selector:#selector(localizedStandardCompare:)];
Fetch requests use an array of sort descriptors, because you can provide more than one. That's why it's sortDescriptors instead of sortDescriptor. You need to provide an array. A simple fix is to change the line to create a one-element array containing your descriptor:
request.sortDescriptors = #[[NSSortDescriptor sortDescriptorWithKey:#"name" ascending:YES selector:#selector(localizedStandardCompare:)]];
Additional evidence that this is the problem: countByEnumeratingWithState:objects:count: is a method that's defined by the NSFastEnumeration protocol. Since NSArray adopts that protocol, it would be expected to implement the method. But since NSSortDescriptor doesn't adopt that protocol, it would not have that method.
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.
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.
I have a Table View Controller with a list of Formations handled by a fetchResultsController.
Here's how my core data entities looks like :
I try to sort my fetchResultsController by dateRangelike this :
// |fetchedResultsController| custom setter
- (NSFetchedResultsController *)fetchedResultsController {
if (_fetchedResultsController != nil) {
return _fetchedResultsController;
}
_fetchedResultsController = [[NSFetchedResultsController alloc] initWithFetchRequest:self.fetchRequest managedObjectContext:self.mainManagedObjectContext sectionNameKeyPath:#"dateRange" cacheName:kFormationsFetchedCacheName];
_fetchedResultsController.delegate = self;
return _fetchedResultsController;
}
// |fetchRequest| custom setter
- (NSFetchRequest *)fetchRequest {
if (_fetchRequest != nil) {
return _fetchRequest;
}
NSPredicate *predicate = [NSPredicate predicateWithFormat:#"student == %#", self.currentStudent];
NSSortDescriptor *dateDescriptor = [NSSortDescriptor sortDescriptorWithKey:#"dateRange" ascending:NO];
NSSortDescriptor *nameDescriptor = [NSSortDescriptor sortDescriptorWithKey:#"name" ascending:NO];
_fetchRequest = [[NSFetchRequest alloc] initWithEntityName:kBSFormation];
_fetchRequest.predicate = predicate;
_fetchRequest.sortDescriptors = [NSArray arrayWithObjects: dateDescriptor, nameDescriptor, nil];
return _fetchRequest;
}
Everything is fine when i try to add the very first Formation, but for the next ones, i have these errors:
2013-01-30 22:43:08.370 [7202:c07] -[BSDateRange compare:]: unrecognized selector sent to instance 0x81781a0
2013-01-30 22:43:08.371 [7202:c07] CoreData: error: Serious application error. Exception was caught during Core Data change processing. This is usually a bug within an observer of NSManagedObjectContextObjectsDidChangeNotification. -[BSDateRange compare:]: unrecognized selector sent to instance 0x81781a0 with userInfo (null)
2013-01-30 22:43:08.372 [7202:c07] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[BSDateRange compare:]: unrecognized selector sent to instance 0x81781a0'
If i comment this line : NSSortDescriptor *dateDescriptor = [NSSortDescriptor sortDescriptorWithKey:#"dateRange" ascending:NO];, it's working but my table view is messy as the sectionNameKeyPath is set to dateRange
Someone is figuring out what's the problem here ? :/
You're telling it to sort based on the dateRange relationship. But dateRange is a relationship to BSDateRange, and how does Core Data compare those? Should it use from, or maybe to, or some combination of those? You can't just tell it to sort on an object like that, because it's not obvious how sorting should work.
Instead, first figure out what sorting even means. Then modify your sort descriptor appropriately. For example if you decide that sorting depends on the from value, change the sort descriptor to use the key path to from:
NSSortDescriptor *dateDescriptor = [NSSortDescriptor
sortDescriptorWithKey:#"dateRange.from"
ascending:NO];
If you need to sort based on both from and to, use more than one sort descriptor.