XCode7 Core Data: Fetch for objects etc - ios

I created an iOS8 application and updated it to XCode7. I have a couple of problems after I recreated the NSManagedObject.
First I get an error, if I fetch for contacts and iterate over them:
let contacts = try self.managedObjectContext.executeFetchRequest(request) as! [Contact]
for contact in contacts{
//--> EXC_BAD_INSTRUCION
}
Contact is my NSManagedObject. I do not get any compiler error or warning.
Second: I get this warning:
CoreData: warning: Unable to load class named 'MyAppName.Contact' for entity 'Contact'. Class not found, using default NSManagedObject instead.
What can cause this? The #objc(Contact) in Contact has already been generated bei XCode and now I can't set the className MyAppName.Contact in CoreData-editor. Any suggestion?

Finally found it. All the other tips are not working, because Apple has changed it with XCode7.
Now XCode creates #(Classname) in the NSManagedSubclass. This needs to be commented out (beta1 and beta2). Then XCode can find your class.

Related

Swift3 CoreData crash on iOS9 device

I have CoreData app that is perfectly working on iOS10, written in Swift3, supporting iOS 8.4 and above.
When I try to run it on iOS 9.3.5 I'm getting error:
2016-10-07 17:47:20.596 FormApp[710:179733] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[NSSet intersectsSet:]: set argument is not an NSSet'
crashing on line:
form.addToOpenQuestions(openQuestion)
I have added #objc() to managed object classes. Then I'm getting new error:
CoreData: warning: Unable to load class named 'FormApp.Form' for entity 'Form'. Class not found, using default NSManagedObject instead.
It is happening on line:
let form = NSEntityDescription.insertNewObject(forEntityName: "Form", into: managedObjectContext) as! Form
My config:
All classes were generated by Xcode. I have tried deleting Module and all configurations. Anyone have idea how to make it work?
For some reason NSSet is expected, but your NSManagedObject code has NSOrderedSet, which is a subclass of NSObject. Try to remove "Arrangment: Ordered" checkmark in your core data model and refactor those relationships to NSSet.
Not sure why this happens in iOS 10 but not in iOS 9 though.
P.S. Perhaps you should reconsider your Core Data model? It looks like your Open/Closed questions are going to change their status. If so, I would recommend to make one Question entity with closed bool or status int.
I was having the same issue with iOS 9.3
The issue was same as mention by #alex above and i have solve as below
if #available(iOS 11.0, *) {
// use iOS 11-only feature
YOUR_CLASS.insertIntoClosedQuestion(YOUR_OBJECT, at: index)
} else {
// handle older versions
let orderset:NSMutableOrderedSet = Form.closeQuestion as! NSMutableOrderedSet
orderset.insert(YOUR_OBJECT, at: index)
YOUR_CLASS.addToClosedQuestion(orderset)
}
Hope it will helpful to others.

Parse local datastore doesn't work - Swift 2

I am currently using the latest version of Parse 1.14.2 and Bolts 1.8.4.Parse is implemented correctly and I have been using it for a long time now. The problem I'm facing now is when I try to use Parse's local datastore. I have the following code in my AppDelegate.swift:
Parse.enableLocalDatastore()
Parse.setApplicationId("ID",
clientKey: "Client_Key")
I have the following code to create and save a string named firstName in a class named contact:
let contact = PFObject(className: "contact")
contact["firstName"] = "Jack"
contact.pinInBackground()
Here is the code to retrieve objects from the created class:
let query = PFQuery(className: "contact")
query.fromLocalDatastore()
query.getFirstObjectInBackgroundWithBlock({ (object, error) -> Void in
if error == nil {
if let contact = object {
print(contact.objectForKey("firstName"))
}
}
})
I have added libsqlite3.dylib to my project. My app doesn't crash when I run this code but it simply gives me the following message when I try to retrieve objects:
2016-08-29 11:31:38.049 App_Demo[14436:3504319] [Bolts] Warning: `BFTask` caught an exception in the continuation block.
This behavior is discouraged and will be removed in a future release.
Caught Exception: Method requires Pinning enabled.
Can anyone help me to work around this issue? I am guessing the issue is that this version of Bolts cannot pin Parse objects in the background and I need to work my way around this bug. Any help would be appreciated as I have been stuck at this for a while and can't find too much info online.
Edited: I have tried downgrading Bolts, but then Parse downgrades with it in Cocoapod and it causes errors in Xcode.
it's not objectforkey.
You need to call object["UsedName"] "UsedName" being the key. Hope that helps.

Opening Realm hangs after implementing new object class

I wish to support rearranging a UITableView. I have seen other answers here, here, and here recommend using a another class to manage the realm objects. The only problem is as soon as I add the class I cannot successfully open a Realm.
import RealmSwift
class Data: Object {
dynamic var id = ""
}
// Adding this class causes issues
class DataList: Object {
let list dataList = List<Data>()
}
Any ideas on what is going wrong here? When I attempt to open the Realm it just hangs: no error thrown.
Edit:
From the realm doc it says they should be declared as let.
Thanks to Tj3n for the solution. Migrate your schema or reinstall the app fixes the issue. Here is some doc on that.

Delete parse class and object in class

I try to delete a class called "test". I found some code but nothing happens. The class are still exist.
-(void)delete{
PFObject *deleteClass = [PFObject objectWithClassName:#"test"];
[deleteClass deleteEventually];
}
Error message:
Failed to run command eventually with error: Error Domain=Parse Code=106 "(null)" UserInfo={message=Failed to run an eventually command., exception=Attempt to delete non-existent object.}
Edit 1: After looking through more Parse forums, I've found a definitive answer stating that you cannot do this with the Parse SDK; you must use the Parse website.
From this question on the Parse website, it looks like this should be done from your Parse dashboard. If you are constantly creating and deleting new classes and need to do this dynamically, I'm not sure you are using Parse in the way it was intended.

Parse SDK and Swift: Incorrect argument label in call PFObject 'withoutDataWithObjectId'

I subclass PFObject exactly as described here.
Then I create a new instance of the subclassed object without data, but since Swift 1.2 I get an error (It did work perfectly before):
var test = Armor(withoutDataWithObjectId: "1234567890")
-> Xcode complains:
"Incorrect argument label in call (have 'withoutDataWithObjectId:',
expected: 'className:')"
Why className? It should get the class name from the class function parseClassName
And I can under no circumstances create a new object with objectId but no data (which I MUST have to fetch it from the local datastore)
This is super annoying as my app doesn't compile any longer.
Update to the newest Parse SDK, available here.
The issue is caused due to necessary adaptions in the Parse SDK after the Swift language update. This issue also occurs with the most recent update to Swift 2.2. The newest (as of today) Parse SDK release 1.13.0 already fixes this.
UPDATE
Parse iOS SDK 1.13.0 has a typo and the function PFUser(withoutDataWithObjectId:) is called PFUser(outDataWithObjectId:). So upgrading the Parse SDK alone does solve this. Until this is fixed a temporary workaround would be to extend PFObject with a convenience initializer. To do this add a new Swift file to your project and insert this:
import Parse
extension PFObject {
convenience init(withoutDataWithObjectId objectId: String?) {
self.init(outDataWithObjectId: objectId)
}
}
It may be a little late to answer this question.
I use swift 1.2, and v 1.7.5 Parse SDK, and it works totally fine.
however, make sure you have define objective-c bridging header in "build setting".
and try to run it, even though there may reports some error

Resources