gpt4 book ai didi

ios - 将 Realm 对象保存到数据库

转载 作者:行者123 更新时间:2023-11-28 15:07:15 24 4
gpt4 key购买 nike

我正在尝试将一个 Realm 对象保存到数据库,但遇到了一个问题。当我运行项目时出现错误:

"dyld: Library not loaded: @rpath/RealmSwift.framework/RealmSwift Referenced from: /Users/levchukmisha/Library/Developer/CoreSimulator/Devices/6C527B07-299E-4B4F-B093-C2E79011AD3E/data/Containers/Bundle/Application/1DA8CC9D-FDEC-4A75-8B6D-19C3AF3508EF/BookShop.app/BookShop Reason: image not found"

我尝试评论我的属性(property)图片并检查发生了什么,但错误仍然存​​在。

这是我的功能:

func addBook() {
let newBook = Book.createBook(
name: "11 22 63",
author: "Steven King",
cost: 150,
about: "Very interesting book with fantasty elements",
image: UIImage(named: "112263")!)


do {
let realm = try Realm()
try realm.write {
realm.add(newBook)
print("\(newBook.name)")
}
} catch {
error.localizedDescription.description
}


}

这是我的 Realm 对象:

class Book: Object {

@objc dynamic var name = ""
@objc dynamic var author = ""
@objc dynamic var cost = 0
@objc dynamic var about = ""
@objc dynamic var image = UIImage()

class func createBook(name: String, author: String, cost: Int, about: String, image: UIImage) -> Book {
let newBook = Book()
newBook.name = name
newBook.author = author
newBook.cost = cost
newBook.about = about
newBook.image = image

return newBook
}

最佳答案

确保将 Realm.framework 拖到项目的常规设置选项卡中的“嵌入式二进制文件”部分。还要确保你有“嵌入框架”构建阶段并且 Realm.framework 包含在那里

Installation section in documentation根据您使用的是 CocoaPods 还是 Carthage 选择一个选项卡

注意这点:

如果将 Realm 与 Swift 结合使用,请将位于 Swift/RLMSupport.swift 的文件拖到 Xcode 项目的文件导航器中,选中 Copy items if needed 复选框。

关于ios - 将 Realm 对象保存到数据库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48270336/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com