nsmanagedobject

Passing generic Class as argument to function in swift

心不动则不痛 提交于 2019-11-29 16:45:29
Below is my method in which there is fetch I make on a Managed object Class Appointment. I need to use same function for other similar managed object Classes. How do I pass different "Class" as parameter every time as I need. And also use it to fetch as I have currently "Appointment" Class. I might need to use Generics may be. Dont know how though. func getAppointmentArray(aPredicate : String , aModel : Any) -> [Any] { var apptArr = [Any]() let fetchRequest = NSFetchRequest<Appointment>(entityName: "Appointment") fetchRequest.returnsObjectsAsFaults = false fetchRequest.predicate = NSPredicate

An NSManagedObjectContext cannot delete objects in other contexts

怎甘沉沦 提交于 2019-11-29 16:39:48
问题 I have two entities, each displaying on its own UITableView section. I've enabled editing to allow the user to delete rows by swiping to the right. This works fine for the first entity, but when I try to delete an object in the second entity, I get this error: An NSManagedObjectContext cannot delete objects in other contexts I get what the error says, but I can't see how it applies here. I use a retained reference to my context to create, fetch, and delete all objects from the database, so I

Application crashes if a property name starts with new

廉价感情. 提交于 2019-11-29 15:22:10
问题 In my project I'm using coredata. One of the entity has an attribute named newTotal , in its corresponding NSManagedObject class the property declaration is like @property (nonatomic, strong) NSString *newTotal; If I add a property like this in an NSObject subclass the XCode will show an error like error: property's synthesized getter follows Cocoa naming convention for returning 'owned' objects But in NSManaged object subclasses it's not showing the error but the application crashes when the

What are the functional differences between Coredata's CodeGen 'manual/none + create NSManagedObject subclass' vs. 'category/extension'

浪子不回头ぞ 提交于 2019-11-29 14:03:11
I've read Subclassing NSManagedObject with swift 3 and Xcode 8 beta and read this great tutorial. Still have questions on some points. The similarities are: I can customize both classes however I like. I can add new attributes or remove or rename attributes. ie for category/extension it will get updated upon a new build (in the derived data), and in case of manual/none it will leave the class file intact and update the extension in the file navigation ie I won't end up with a duplicate file. This is all handled by Xcode because they are marked with a preprocessor @NSManaged Dumping something

How to convert NSManagedObject to NSDictionary

大城市里の小女人 提交于 2019-11-29 13:44:10
问题 I am trying to convert NSManagedObject to NSDictionary this is what I tried: var keys:NSArray = order?.entity.attributesByName.keys var dict:NSDictionary = order?.dictionaryWithValuesForKeys(keys) But I get error: LazyForwardCollection<MapCollectionView<Dictionary<NSObject, AnyObject>, NSObject>>? is not convertible to NSArray. What am I doing wrong here? 回答1: The keys property of a dictionary returns a LazyForwardCollection which has to be converted to a real array. Another problem is that

Custom initializer for an NSManagedObject

荒凉一梦 提交于 2019-11-29 12:12:05
According to the docs: You should not override init. You are discouraged from overriding initWithEntity:insertIntoManagedObjectContext: and you should instead use awakeFromInsert or awakeFromFetch. This is fine if all I want to do is set some attribute to the current date or similar, but what if I want to send in another object and set attributes based on its information? For example, in an NSManagedObject subclass called 'Item', I want an initFromOtherThing:(Thing *)thing, in which the item's name is set to that of the thing. I would like to avoid 'just having to remember' to set the name

Debugging SIGABRT within NSManagedObjectContext -save:

做~自己de王妃 提交于 2019-11-29 12:08:12
问题 From inside NSManagedObjectContext -save: I am getting this message: Assertion failed: (_Unwind_SjLj_Resume() can't return), function _Unwind_SjLj_Resume, file /SourceCache/libunwind/libunwind-24.1/src/Unwind-sjlj.c, line 326. Program received signal: “SIGABRT”. warning: Unable to read symbols for /Developer/Platforms/iPhoneOS.platform/DeviceSupport/4.2.1 (8C148)/Symbols/Developer/usr/lib/libXcodeDebuggerSupport.dylib (file not found). This happens when I delete an Experiment object with to

What is common case for @dynamic usage?

岁酱吖の 提交于 2019-11-29 11:20:23
There is previous post about difference of @synthesize and @dynamic. I wanna to know more about dynamic from the perspective of how to use @dynamic usually. Usually we use @dynamic together with NSManagedObject // Movie.h @interface Movie : NSManagedObject { } @property (retain) NSString* title; @end // Movie.m @implementation Movie @dynamic title; @end Actually there are no generated getter/setter during compiler time according to understanding of @dynamic, so it is necessary to implement your own getter/setter. My question is that in this NSManagedObject case, what is the rough

Swift CoreData: error: Failed to call designated initializer on NSManagedObject class 'NSManagedObject'

蹲街弑〆低调 提交于 2019-11-29 10:58:13
I'm using core data to save a category in vc1 and want to add list properties to a list in vc2. My data model is one category to many list properties. I'm adding the category like this in vc1: func createNewCategory() { var category: NSManagedObject! = NSEntityDescription.insertNewObjectForEntityForName("Category", inManagedObjectContext: self.context) as NSManagedObject category.setValue(self.categoryTextField.text, forKey: "name") var error: NSError? = nil self.context.save(&error) } Setting up the data in vc2: func setupCoreData() { var appDelegate: AppDelegate = (UIApplication

Core Data: Could not cast value of type 'MyType_MyType_2' to MyType

纵然是瞬间 提交于 2019-11-29 10:51:58
问题 I have an Objective-C model class MyType. This class is used in Swift code: NSEntityDescription.insertNewObjectForEntityForName("MyType", inManagedObjectContext: context) as! MyType The as! cast results in the error message Core Data: Could not cast value of type 'MyType_MyType_2' (0x7be99a30) to MyType (0xf33db74). If I cast it as NSManagedObject it works. When I print the result, I can nevertheless see, that it is an actual instance of MyType: <MyType: 0x7ae06d50> (entity: MyType; id: