core-data

How to sort Core Data array based on Date Entered

做~自己de王妃 提交于 2021-01-13 09:19:18
问题 I have a small Core Data Model which stores an array of Strings (search history). When fetching the Data I'd like to sort by the time created. I currently just have one property in my model called searchHistory is there a way I can use the following code (key: to sort the data or will I need to add a time saved to the model? let request = NSFetchRequest<NSFetchRequestResult>(entityName: entityName) request.sortDescriptors = [NSSortDescriptor.init(key: "", ascending: true)] 回答1: Yes, you need

How to sort Core Data array based on Date Entered

允我心安 提交于 2021-01-13 09:18:08
问题 I have a small Core Data Model which stores an array of Strings (search history). When fetching the Data I'd like to sort by the time created. I currently just have one property in my model called searchHistory is there a way I can use the following code (key: to sort the data or will I need to add a time saved to the model? let request = NSFetchRequest<NSFetchRequestResult>(entityName: entityName) request.sortDescriptors = [NSSortDescriptor.init(key: "", ascending: true)] 回答1: Yes, you need

SwiftUI with Core Data getting Blank Screen in simulator in Xcode 12

旧街凉风 提交于 2021-01-04 07:36:47
问题 In XCode 12, if I create a new SwiftUI App and check the "Use Core Data" button, the resulting application (with no changes) shows a blank screen in simulator (as well as on a device). In preview it shows the example timestamps as expected. Why are the simulator/device not showing the example timestamps? 回答1: If you want to see the sample inputs from the template (10 rows with timestamp) in your simulator, you need to change in App.swift: let persistenceController = PersistenceController

Choosing an integer type in core data

蓝咒 提交于 2021-01-02 20:40:40
问题 When I create models in core data, I'm always a little perplexed by which integer type I should choose—16, 32, 64. I'm almost always needing something for a simple, basic number: a count of people in the household, for my present case. Probably going to be a number between 1-20. Or, I have an incrementing case id number in another instance...can't imagine that going further than few hundred people. And here's the deal...It's clear that true computer science folk think of numbers differently,

Choosing an integer type in core data

荒凉一梦 提交于 2021-01-02 20:39:53
问题 When I create models in core data, I'm always a little perplexed by which integer type I should choose—16, 32, 64. I'm almost always needing something for a simple, basic number: a count of people in the household, for my present case. Probably going to be a number between 1-20. Or, I have an incrementing case id number in another instance...can't imagine that going further than few hundred people. And here's the deal...It's clear that true computer science folk think of numbers differently,

Choosing an integer type in core data

旧时模样 提交于 2021-01-02 20:39:49
问题 When I create models in core data, I'm always a little perplexed by which integer type I should choose—16, 32, 64. I'm almost always needing something for a simple, basic number: a count of people in the household, for my present case. Probably going to be a number between 1-20. Or, I have an incrementing case id number in another instance...can't imagine that going further than few hundred people. And here's the deal...It's clear that true computer science folk think of numbers differently,

Choosing an integer type in core data

匆匆过客 提交于 2021-01-02 20:39:10
问题 When I create models in core data, I'm always a little perplexed by which integer type I should choose—16, 32, 64. I'm almost always needing something for a simple, basic number: a count of people in the household, for my present case. Probably going to be a number between 1-20. Or, I have an incrementing case id number in another instance...can't imagine that going further than few hundred people. And here's the deal...It's clear that true computer science folk think of numbers differently,

How to fetch array of objects using array of ids using core data?

别说谁变了你拦得住时间么 提交于 2021-01-02 06:25:19
问题 I have an array of ids. I want to fetch core data entity for the items in the ids array. How can we implement that using NSFetchRequest ? 回答1: Use NSPredicate fetchRequest.predicate = NSPredicate(format: "itemId IN %@", itemIds) Instead of itemId set your actual id property name. Now perform a fetch with this fetch request 回答2: let hrData = self.cstProjectDetails as NSArray 来源: https://stackoverflow.com/questions/51264432/how-to-fetch-array-of-objects-using-array-of-ids-using-core-data

Core data + CloudKit - sharing between iOS and watchOS companion app

末鹿安然 提交于 2020-12-29 06:54:27
问题 In my app I store data with core data. Recently I discovered the new feature introduced by Apple in WWDC19 which allows core data to work with CloudKit. I just enabled cloudKit for my app and used an NSPersistentCloudKitContainer instead of NSPersistentContainer and all was set up ! All my data is shared between ios devices. That works like NSPersistentContainer but it sends a copy of changes on icloud server, so there is always a local cache of data. Now I'd like to access that data from my

Handling duplicate entries in Core Data

痞子三分冷 提交于 2020-12-28 07:43:51
问题 I have an app that allows users to save favorites. I am using Core Data to store the favorites as managed objects. I have written some code to prevent the possibility of storing duplicates, but am wondering if there is a better way to do so. Each favorite object has an ID field that is unique. In the following code I am simply looping through and checking the ID field, and if the value already exists, setting a flag value to true, and breaking out of the loop. -(BOOL)addFavorite{ BOOL