xcdatamodel

Access FetchRequest from xcdatamodel in iOS

拟墨画扇 提交于 2021-01-27 06:31:40
问题 I'm using NSPersistentContainer to access my core data in iOS10 app and Xcode 8. Similar to Entity, I added a "UserFetchRequest" in my Coredata xcdatamodel. Below is the screen shot. How can I access the "UserFetchRequest" in the code? 回答1: Having given your fetch request a name in the Data Model Inspector on the right hand side: (in my case named "randomFetch" where yours is "UserFetchRequest"), get the model from the persistentContainer: let model = persistentContainer.managedObjectModel

Core data model, game has a winner and a loser, a player has multiple games?

断了今生、忘了曾经 提交于 2020-01-06 12:53:17
问题 I'm trying to setup my core data model. I want to have a game that has one loser and one winner. And I need a Player that has multiple games. I have the following: Entity: Player Attributes: wins, losses, name Relationships: games Destination:Game inverse: ??? winner or loser??? Entity: Game Attributes: losingScore, winningScore, Relationships: loser destination:Player Inverse:games, winner destination:Player Inverse:games How can I set this up?? Thanks! 回答1: Why not just: player.gamesWon<-

XCode crashes when trying to view an .xcdatamodel

北慕城南 提交于 2019-12-22 10:44:58
问题 I have an app, backed by Core Data, that I've been working on for awhile. I use version control (formerly SVN, now Git) to move it around between different Macs. The other day, I was unable to open the project. OH CRAP. Luckily, due to Time Machine I was able to go back in time, and reverted to an earlier version. I suspected that something with either the XCode project files or the Core Data files was at play here (I ran into some of the problems that this guy did, I guess), but everything

Programmatically create attribute - Core Data

北慕城南 提交于 2019-12-19 04:50:21
问题 i have a simple iphone project which contains a simple xcdatamodel that has a single entity with roughly 3 attributes.. i want to know if there is a way to programmatically add an attribute to an entity.. i.e. if the user presses an "add" button of some kind, a simple string attribute is added to the entity and saved.. If this is not possible could someone point me in the right direction.. 回答1: You can programmatically alter entities but you can't alter a managed object model after it has

Core Data: Add a column on a table

混江龙づ霸主 提交于 2019-12-12 02:38:40
问题 I just want to add a column on a table for my new version of my app, and keep the filled columns. So I work with Core Data, this is my momd: On my appDelegate: /* CORE DATA */ // MARK: - Core Data stack lazy var applicationDocumentsDirectory: NSURL = { let urls = NSFileManager.defaultManager().URLsForDirectory(.DocumentDirectory, inDomains: .UserDomainMask) return urls[urls.count-1] }() lazy var managedObjectModel: NSManagedObjectModel = { let modelURL = NSBundle.mainBundle().URLForResource(

The inverse relationship for <…> does not reciprocate an inverse relationship

家住魔仙堡 提交于 2019-12-12 00:42:12
问题 I have the table A with the following relationships: Relationship Destination Inverse input B state output B state And the table B with the following relationship: Relationship Destination Inverse state A input And I get the warning: The inverse relationship for state.input does not reciprocate an inverse relationship Is there a right way how can I fix the warning? 回答1: You cannot have the same relationship name state for different relationships on the other side. Either rename the state

Re-add the xcdatamodel to the Build Settings

做~自己de王妃 提交于 2019-12-11 19:32:28
问题 While I was busy trying out stuff for this question, I accidently removed the xcdatamodel-package. I found out that recently there was this question which mentioned the following: For some reason, the xdatamodel was removed from the build settings. I added it back in and it worked. I tried doing what he did, but I don't know where to start. I recreated the package, but when I try to set an attribute value, I get +entityForName: could not locate an entity named 'EN'... All I know is; it did

How to represent Foreign Key relationships in Core Data - Data Model in XCode

混江龙づ霸主 提交于 2019-12-10 13:44:29
问题 Totally new with Core Data, I'm making my data model. I have 33 entities, and few hard relationships between them but lots of Foreign-Key relationships. How can I manage that relationships that are not exactly 1-many or 1-1 or many-many but are foreign keys in Core Data Model? For ex., I have a Contact entity, which has a relationship with a contact_x_mail, and at the same time contact_x_mail has a relationship with Mail, that contains all emails. This relationships are 1-many or many-many.

Compatibility problem with .xcdatamodeld between Xcode 4.1 (Lion) and Xcode 3.2.5 (snow leopard)

别说谁变了你拦得住时间么 提交于 2019-12-10 02:28:35
问题 I have a problem with a Data Model using Core Data. 1/ I've created a data model on xcode 4.1 (on lion) with my entities and their relationships. In the inspector on the right i've checked "Tools version" : Minimum : Xcode 3.2 instead of Xcode 4.1. 2/ When i try to reopen my project, in Xcode 3.2.5 (on snow leopard), I click on "mydatamodel.xcdatamodeld", then on "mydatamodel.xcdatamodel", but nothing happen ! It's like my xcdatamodel file was empty but it's a 4.9 Mo file ! My xcdatamodel

What are Fetch Index Elements in the CoreData Model?

荒凉一梦 提交于 2019-12-10 01:52:17
问题 In my xcdatamodel two new fields, byTitleIndex and compoundIndex , are showing under Fetch Index Elements. I have not seen this section before in Xcode. What is a Fetch Index Element? 回答1: Fetch Index Elements are part of Apple’s new indexing API, announced at WWDC 2017. They allow you to specify one or more Index Elements; properties that are used to create an index for faster database searches. In your case, the "title" property will be used to create an index called “compoundIndex” under