- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
因此,当我尝试将部署目标设置为iOS 9时(确实低于10.0),我得到了标题中所述的错误。
这里存在问题:
// MARK: - Core Data stack
lazy var persistentContainer: NSPersistentContainer = {
/*
The persistent container for the application. This implementation
creates and returns a container, having loaded the store for the
application to it. This property is optional since there are legitimate
error conditions that could cause the creation of the store to fail.
*/
let container = NSPersistentContainer(name: "Keebin_development_1")
container.loadPersistentStores(completionHandler: { (storeDescription, error) in
if let error = error as NSError? {
// Replace this implementation with code to handle the error appropriately.
// fatalError() causes the application to generate a crash log and terminate. You should not use this function in a shipping application, although it may be useful during development.
/*
Typical reasons for an error here include:
* The parent directory does not exist, cannot be created, or disallows writing.
* The persistent store is not accessible, due to permissions or data protection when the device is locked.
* The device is out of space.
* The store could not be migrated to the current model version.
Check the error message to determine what the actual problem was.
*/
fatalError("Unresolved error \(error), \(error.userInfo)")
}
})
return container
}()
@available(iOS 10.0, *)
。但这还不够。我期望这是因为我错过了“如果不可用,请使用此功能”,但是对于Swift和iOS编程来说我是新手,所以我不确定该写些什么。而且我似乎找不到任何答案,无法给出关于所写内容的确切答案。有人可以帮忙吗?
最佳答案
您确实不需要将iOS 10与早期版本区分开。 NSPersistentContainer
需要iOS 10,但是较旧的技术仍然有效并且仍受支持。如果您需要支持iOS <10,请不要使用NSPersistentContainer
。加载托管对象模型和添加持久性存储要采取更多步骤,但这意味着您可以为所有版本的iOS使用单个代码路径。
关于ios - Swift 3-“NSPersistentContainer仅在ios 10和更高版本上可用”,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42132799/
注意:我看过类似的问题,但没有找到描述这种情况的问题。 我正在查看以下来自 Apple 的有关核心数据并发性 (https://developer.apple.com/library/content/
我正在创建一个 NSPersistentContainer 来保存一些数据,但即使在上下文中调用 save() 也不会创建任何数据库文件。 我用来创建 NSPersistentContainer 的代
我创建了一个单例类来管理我的核心数据: class CoreDataManager { static let sharedManager = CoreDataManager() private ini
当我通过这段代码自己创建容器时,在应用程序支持文件夹中会创建什么样的持久存储? private lazy var storeContainer: NSPersistentContainer = {
我像这样创建一个 NSPersistentContainer: static let persistentContainer: NSPersistentContainer = { let c
我刚刚添加了一个选项,供用户在我的应用程序中切换云同步,我保存用户是否要在“useCloudSync”下的 UserDefaults 中使用 iCloud 同步。当应用程序运行时,我加载我的persi
我正在熟悉 NSPersistentContainer .我想知道使用 newBackgroundContext 生成私有(private)上下文的实例是否更好。每次我需要在后台插入/获取一些实体或创
我刚刚在 Core Data 上设置了一个只读数据存储。它可以工作,但编译器对此有提示,我想知道如何解决这个问题。 这里的相关代码是我在Xcode自动生成模板后修改的。 lazy var persis
我在一些地方(例如 a high score answer here )读到,将主托管上下文作为后台托管上下文的子级是一种很好的做法,可以节省 save() 时间并提高 UI 响应能力。 Persis
我已经阅读了一些关于此的博客,但我仍然对如何使用 NSPersistentContainer performBackgroundTask 创建实体并保存它感到困惑。通过在 performBackgro
我正在使用 NSPersistentContainer 来创建我的核心数据堆栈。 documentation说我们应该使用它的 viewContext 属性来获取主要的 NSManagedObject
使用在主队列上运行的 NSManagedObjectContext 和在私有(private)队列上运行的辅助 NSManagedObjectContext 并让它们共享一个 NSPersistent
我的单元测试核心数据设置有问题。 我在我的 AppDelegate 中使用默认/新的核心数据堆栈设置 class AppDelegate: UIResponder, UIApplicationDele
我收到一个错误: AppDelegate has no member persistentContainer import UIKit import CoreData class ViewContro
在Apple的NSPersistentContainer文档中,该方法有如下描述: func loadPersistentStores(completionHandler block: @escapi
我的 AppDelegate 带有以下所有熟悉的核心数据模板: lazy var persistentContainer: NSPersistentContainer = { let cont
现在所有核心数据示例都是 iOS 示例,因此自从 macOS 10.12 中对核心数据进行了有趣的更改以来,对于 macOS 没有太多指导。但我想看看 NSPercientContainer 应该如何
在当前运行的 App Store 应用程序中,我使用 MagicalRecord 来设置我的核心数据。当我遇到并发问题时,我四处寻找解决方案。我意识到自从引入 iOS 10 以来,Core Data
我无法将令人兴奋的核心数据堆栈更改为 NSPersistentCloudKitContainer,因为这只是 iOS 13 及更高版本的支持功能,但我希望为 iOS 13 及更高版本设置该设置,同时为
我确信这个问题会被问到并回答很多次,但我惊讶地发现,经过数小时的搜索,我找不到答案。随着 iOS 10 的到来,NSPersistentContainer 改变了我们处理 Core Data Stac
我是一名优秀的程序员,十分优秀!