func SomeSwift(){}
SomeSwift()没有在任何Swift类中定义,它只是一个纯函数.
在CMD B构建项目之后,打开Project-Swift.h,SomeSwift()没有显示在那里.
是否必须在某些Swift类中定义Swift中的函数?和@objc标记?
如下:
@objc class SomeSwift: NSObject { func SomeSwift() { }}解决方法 参考 Apple Documentation关于从Objective-C使用Swift:
A Swift class must be a descendant of an Objective-C class to be
accessible and usable in Objective-C
意味着你的类应该是@objc类SomeSwift:NSObject(你是对的!),但是你无法访问Swift文件中的全部内容:
When you create a Swift class that descends from an Objective-C class,
the class and its members—propertIEs,methods,subscripts,and
initializers—that are compatible with Objective-C are automatically
available from Objective-C. This excludes Swift-only features,such as
those Listed here:Generics
Tuples
Enumerations defined in Swift without Int raw value type
Structures defined in Swift
top-level functions defined in Swift
Global variables defined in Swift
Typealiases defined in Swift
Swift-style variadics
nested types
CurrIEd functions
Reference.
因此,您无法使用SomeSwift顶级功能.
即使你试图在声明之前添加@objc,编译器也会告诉:
@objc can only used when with memebers of classes,@objc protocols,
and concrete extensions of classes.
建议删除@objc.
总结以上是内存溢出为你收集整理的ios – Objective-C调用Swift函数全部内容,希望文章能够帮你解决ios – Objective-C调用Swift函数所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)