建立斯威夫特和Objective-C库 [英] Build a library for Swift and Objective-C

查看:127
本文介绍了建立斯威夫特和Objective-C库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要与同时支持迅速和对象C的项目迅速的一个库(也支持X code 5),这将是一个分发库(不共享源$ C ​​$ C)。有两种方法可以做到这一点:创建一个可可触摸框架或创建一个可可触摸静态库。我做了一些研究,但仍找出解决方案。这似乎在Cocoa Touch框架不支持打造专业化分布的库,我不知道可可触摸静态库工作,完善与斯威夫特又或没有。为它的任何解决方案。谢谢你。

I need to make a library with swift that support both swift and object c project (also support xcode 5), this will be a distribution library (do not share source code). There are two ways to do this: create a Cocoa Touch Framework or create a Cocoa Touch Static Library. I make some research, but still find out the solution. It seems the Cocoa Touch Framework not support to buid a distribution library, and I'm not sure the Cocoa Touch Static Library work perfect with with Swift yet or not. Any solutions for it. Thanks.

推荐答案

对于这种库的一个很好的例子就是境界

A very good example for this kind of library is Realm.

他们都支持快捷和Objective-C项目集成。检查GitHub上的回购,并浏览它:这里

They both support swift and objective-c project integration. Check the repo on GitHub , and browse it : here

在事实上,他们在Objective-C中所有库$ C $光盘,并与客户端使用的对象扩展的插件支持迅速specifecity。 (例如,检查其回购王国/ RLMSwiftSupport.m)

In fact, they have all the library coded in Objective-C, and the add Support for swift specifecity with extensions on objects used by the client. (For example, check the Realm/RLMSwiftSupport.m in their repo)

修改

要访问Objective-C的一类雨燕,只需添加 @objc(MyClass的)在斯威夫特类,这将是在Objective-C文件中提供。

To access a Swift class in Objective-C, just add @objc(MyClass) in your Swift Class and it will be available in Objective-C files.

阅读关于Objective-C和斯威夫特更多的信息一起工作

Read the this for more informations about Objective-C and Swift working together

这篇关于建立斯威夫特和Objective-C库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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