我应该在我的混合Objective-C / Swift项目中使用Realm Objective-C或Realm Swift吗? [英] Should I use Realm Objective-C or Realm Swift in my mixed Objective-C / Swift project?

查看:100
本文介绍了我应该在我的混合Objective-C / Swift项目中使用Realm Objective-C或Realm Swift吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的项目使用Swift并针对iOS 8.0及更新版本,但我们使用旧的Objective-C项目中的一些文件,并通过CocoaPods引入一些Objective-C库。我应该在这个项目中使用哪个Realm接口:Objective-C还是Swift?我很困惑因为Realm文档中的公告:

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. Which Realm interface should I use in this project: Objective-C or Swift? I'm confused because of the announcement in the Realm documentation:


如果您正在寻找使用Objective-C中的Realm,或者来自混合物Objective-C& Swift应用程序请参阅Realm Objective-C。
不支持同时使用Realm Objective-C和Realm Swift。

If you’re looking to use Realm from Objective-C, or from mixed Objective-C & Swift apps please see Realm Objective-C instead. Using both Realm Objective-C and Realm Swift simultaneously is not supported.


推荐答案

它们的关键细节是您是打算仅从Swift,还是Swift和Objective-C访问您的Realm模型类。如果您只从Swift访问它们,您可以愉快地使用Realm Swift,即使您的应用程序中的其他地方使用了使用Objective-C编写的代码。如果您将从Swift和Objective-C代码访问您的Realm模型类,您将需要使用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. 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. 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.

这篇关于我应该在我的混合Objective-C / Swift项目中使用Realm Objective-C或Realm Swift吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆