简体   繁体   English

我应该在混合的Objective-C / Swift项目中使用Realm Objective-C或Realm Swift吗?

[英]Should I use Realm Objective-C or Realm Swift in my mixed Objective-C / Swift project?

My project uses Swift and targets iOS 8.0 and newer, but we use some files from our old Objective-C project, and brings in some Objective-C libraries via CocoaPods. 我的项目使用Swift并针对iOS 8.0及更新版本,但我们使用旧的Objective-C项目中的一些文件,并通过CocoaPods引入一些Objective-C库。 Which Realm interface should I use in this project: Objective-C or Swift? 我应该在这个项目中使用哪个Realm接口:Objective-C还是Swift? I'm confused because of the announcement in the Realm documentation: 我很困惑因为Realm文档中的公告:

If you're looking to use Realm from Objective-C, or from mixed Objective-C & Swift apps please see Realm Objective-C instead. 如果您希望使用Objective-C中的Realm,或者使用混合的Objective-C和Swift应用程序,请参阅Realm Objective-C。 Using both Realm Objective-C and Realm Swift simultaneously is not supported. 不支持同时使用Realm Objective-C和Realm Swift。

They key detail is whether you intend to access your Realm model classes from only Swift, or both Swift and Objective-C. 它们的关键细节是您是打算仅从Swift,还是Swift和Objective-C访问您的Realm模型类。 If you will only access them from Swift you can happily use Realm Swift, even if elsewhere in your application you use code written in Objective-C. 如果您只从Swift访问它们,您可以愉快地使用Realm Swift,即使您的应用程序中的其他地方使用了使用Objective-C编写的代码。 If you will access your Realm model classes from both Swift and Objective-C code you'll need to use Realm Objective-C rather than Realm Swift. 如果要从Swift和Objective-C代码访问Realm模型类,则需要使用Realm Objective-C而不是Realm Swift。

If you're looking to use Realm purely from Swift, you should consider using Realm Swift instead. 如果你想从Swift纯粹使用Realm,你应该考虑使用Realm Swift。 Using both Realm Objective-C and Realm Swift simultaneously is not supported. 不支持同时使用Realm Objective-C和Realm Swift。

I would recommend that you use Realm Swift only if you intend to use it from Swift otherwise you should use Realm Objective-C . 我建议你只有在打算从Swift使用它时才使用Realm Swift 否则你应该使用Realm Objective-C One of the reasons for this would be that at this point List and RealmOptional properties aren't accessible from Objective‑C . 其中一个原因是此时无法从Objective-C访问ListRealmOptional属性

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM