[英]Install Realm in a Swift App
I am trying to add Realm to my app written in swift. 我正在尝试将Realm添加到我用swift编写的应用程序中。 I have followed the tutorial and I can't seem to get it to work. 我按照教程,似乎无法让它工作。 The biggest problem is that when I try to import Realm I get No such module 'Realm'
I don't know what else to try. 最大的问题是,当我尝试导入Realm时,我得到No such module 'Realm'
我不知道还有什么可以尝试。 You can see my efforts below. 你可以在下面看到我的努力。
You can see the instructions here: http://realm.io/docs/cocoa/0.85.0/#swft 您可以在此处查看说明: http : //realm.io/docs/cocoa/0.85.0/#swft
I have also copied the instructions below: 我还复制了以下说明:
Due to the current lack of proper infrastructure for Swift dependency management, using Realm in your project requires the following steps: 由于当前缺乏适当的Swift依赖管理基础结构,因此在项目中使用Realm需要执行以下步骤:
Below is what it looks like in my project: 以下是我的项目中的样子:
I am not sure exactly why this isn't working, but here is a workaround: 我不确定为什么这不起作用,但这是一个解决方法:
Follow the latest instructions. 按照最新说明操作。
Create a bridging header, for example by 创建一个桥接头,例如
Add this in the bridging header: 在桥接标题中添加:
#import "Realm/Realm.h"
Remove any Import Realm
statements from your code, including from RLMSupport.swift 从代码中删除任何Import Realm
语句,包括RLMSupport.swift
Now it should work. 现在它应该工作。 For example, I test with putting this in my ViewController.swift 例如,我将它放在我的ViewController.swift中进行测试
import UIKit class Person: RLMObject { dynamic var name = "" dynamic var birthdate = NSDate(timeIntervalSince1970: 1) } class ViewController: UIViewController { override func viewDidLoad() { super.viewDidLoad() let author = Person() author.name = "David Foster Wallace" // Get the default Realm let realm = RLMRealm.defaultRealm() // Add to the Realm inside a transaction realm.beginWriteTransaction() realm.addObject(author) realm.commitWriteTransaction() // Print all Persons println(Person.allObjects()) } }
Which prints: 哪个印刷品:
RLMArray <0x7a243760> (
[0] Person {
name = David Foster Wallace;
birthdate = 1970-01-01 00:00:01 +0000;
}
)
I have been talking with the guys at Realm, and it turns out that the latest instructions don't work with Realm <= 0.85 They changed they way the build the framework and it won't work anymore. 我一直在与Realm的人交谈,事实证明最新的指令不适用于Realm <= 0.85他们改变了构建框架的方式,它将不再起作用。 They said they will release 0.86 later today that should fix the problems anyone is having with Swift. 他们说他们将在今天晚些时候发布0.86,这将解决任何人对Swift的问题。 In the meantime I have a test project that anyone can take the latest framework from. 与此同时,我有一个测试项目,任何人都可以从中获取最新的框架。 https://github.com/smitt04/testRealm https://github.com/smitt04/testRealm
Version 0.86 is now out and this is no longer an issue. 版本0.86现已淘汰,这不再是一个问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.