With QuickBlox, one can create custom objects. All went fine but now I want to display the returned records from one of my custom class. I can see that the records are returned but I cannot grab them to display on a UITableView. I tried saving the result of getObjectsResult.objects into a NSMutableArray and then used an "objectForKey" construction but although the records were saved in my array, I got the error :
2013-04-25 22:09:09.700 People[897:12b03] * Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[QBCOCustomObject objectForKey:]: unrecognized selector sent to instance 0x86c2520'
I will appreciate any help to help me fix this. For more check out http://quickblox.com/developers/SimpleSample-customObjects-ios.
Thanks!
-kisimi
For predefine custom object table field, you don't need to use "objectForKey" to get value from field. you need to only use QBCOCustomObject's property for example below...
For getting message ID just use [[QBCOCustomObject]ID].
and for custom filed value [[QBCOCustomObject]objectForKey:#"customFieldName"].
Related
In this SO question from 2010, the OP asks how to go about formatting a stored fetch request created in the Xcode GUI to allow for variable substitution when the stored request is called at runtime using NSFetchRequest:fetchRequestFromTemplateWithName:substitutionVariables.
Apple has some archived documentation that talks about how to do this in Obj-C, but Swift handles variables differently and I haven't found the syntax documented anywhere.
In my application, I'm looking to find an audio track that belongs to a certain category. The track has an attribute called trackCategory which is defined as an Int64
In my template Fetch Request, I've set up a Custom Predicate with the statement trackCategory == $TRACKCATEGORY. As I understand it, I'm setting up a condition where the object will only be returned if the object's trackCategory value matches a variable value named $TRACKCATEGORY that will be substituted at runtime.
And then, in my code, I'm trying to call this stored fetch request as follows:
fetchRequest = model.fetchRequestFromTemplate(withName:
"getUnplayedTracks", substitutionVariables: ["TRACKCATEGORY" : forCategory])!
Two things:
model is declared at the top of the ViewController (this document) as:
let model = (UIApplication.shared.delegate as! AppDelegate).persistentContainer.managedObjectModel.
forCategory is an Int64 declared elsewhere.
When I build and run this, I get a SIGABRT with the error message:
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'unable to resolve variable expression: $TRACKCATEGORY'
I'm sure I'm missing something with how the Custom predicate statement is formatted, but I just can't figure out what it is.
I have two entities and a simple one to many relation, Activity and CountedObject entities, and the relation Counted object can have multiple Activities
So in my code I was able to get the list of counted objects and now I want to calculate the sum of amount from activities related to specific counted object. Here is my code
let countedObject = countedObjects[indexPath.row]
let activities = countedObject.activities?.allObjects as! [Activity]
the problem is when I try to get activities I have an error
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[CountedObject activities]: unrecognized selector sent to instance 0x60000009d470'
Seems like the relation is not correct or something
To set relation correctly in CoreData just making relationship in table is not enough you have to set all relation object using an object ex.
countedObject.activity = activityObject
Then after you can access activityObjects from countedObject.activites
Suddenly my app started to crash when trying to save something on Realm. I couldn't specifically trace where this error was occurring. Error message:
terminating with uncaught exception of type realm::LogicError: Data type mismatch
Any thoughts?
Turns out this issue is caused when you try to save a realm object, or assign it to another realm object, while it still doesn't have its Primary Key (or any other required key) set.
Explaining better, if you create a realm object and forget to set its Primary Key, when you try to perform a save action (via addOrUpdateObject or commitWriteTransaction, or any other saving method), or even when you try to relate that object to another realm object (e.g. chat.message = message, while message doesn't have a PK yet), that exception might be thrown.
To fix this, ensure that every realm object you're creating has its PK and required keys set before saving it.
I'm having some issues with saving a new object/editing an existing one, from a One-To-Many relationship in CoreData.
I have a class Patient that has a To-Many relationship with class Indication.
What's been happening is:
First time I create an Indication Object from a normal workflow, it all seems to save alright, but if I try to access it from an Edit screen, it crashes with a SIGABRT and the following error
-[Patient compare:]: unrecognized selector sent to instance 0x7fa991893ca0
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[Patient compare:]: unrecognized selector sent to instance 0x7fa991893ca0'
The same happens if I try to create a new one from the NSFetchedResultsController that shows the list of Indication Objects.
I've tried to create the relationships between them in two ways:
indication = [NSEntityDescription insertNewObjectForEntityForName:#"Indication"
inManagedObjectContext:appDelegate.managedObjectContext];
indication.patient = patient;
and through the GeneratedAccessors from CoreData:
[patient addIndicationObject:indication];
and I validate both objects during viewDidLoad to avoid creating a new Indication if I'm editing an existing one. But in both cases I get the same error.
Haven't been able to find any posts related to this matter so far. Please help.
After a few days researching this with no success, finally I've managed to find a post that managed to shine some light on the problem.
It happens that the NSFetchedResultsControllerDelegate seems to "lock" the NSManagedObjectContext and that's why I couldn't add or change anything within the same context.
I just had to set the delegate to nil once I left the screen and everything seems to work just fine now.
Thanks for the solution on this post:
Core data: Serious application error
I am having an issue with core data many to many relationship. I have two entity Menus <<---->> Categories. I can insert data on both the entities. But when I tried to establish a relationship between them, I used this code:
[menu addToCategoriesObject:catagory];
And it crashes with the following error :
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSDictionaryI addToCategoriesObject:]: unrecognized selector sent to instance 0x8fca680'
Your help is appreciated. Also, if there is any good tutorial on Core Data many to many relationship, please share it.
Thanks.
menu seems to be an NSDictionary object. NSDictionary does not know the method addToCategoriesObject.
You need to establish the relationship by calling the methods on your generated NSManagedObject subclasses, for example something like addManyCategories:(NSSet *)value.
The problem was I kept my data in NSDictionary instead of NSManagedObject subclass object. NSDictionary changed its format. So when I tried to add it by addToCategoriesObject method it crashed!!