在Swift中隐藏一个Objective-C初始化程序(或方法) [英] Hide an Objective-C initializer (or method) from Swift

查看:41
本文介绍了在Swift中隐藏一个Objective-C初始化程序(或方法)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 Framework ,其中有一个 Objective-C 类,其中一个指定的初始化程序需要两个NSArray.在 Framework 中,我定义了一个 Swift 扩展,它提供了一个额外的初始化程序,该初始化程序使用元组数组而不是两个数组.

I have a Framework with has one Objective-C class with one designated initializer which takes two NSArrays. Inside the Framework, I have defined a Swift extension which provides an extra initializer which takes an array of tuples instead of the two arrays.

从外部导入 Framework 时,是否可以从 Swift 中隐藏原始的 Objective-C 初始化程序(因此只有使用可以使用元组数组),但是在使用 Objective-C 代码中的 Framework 时是否保持可用?

When importing the Framework eternally, is it possible to hide the original Objective-C initializer from Swift (so only the initializer taking the array of tuples can be used) but keep it available when using the Framework from Objective-C code?

推荐答案

@mattt的答案:

Answer by @mattt:

使用NS_SWIFT_UNAVAILABLE宏(仅在 Xcode 7 及更高版本上可用).

Use the NS_SWIFT_UNAVAILABLE macro (available only on Xcode 7 and up).

这篇关于在Swift中隐藏一个Objective-C初始化程序(或方法)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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