且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

将swift框架导入Objective-c项目

更新时间:2023-02-26 15:24:34

要访问objc中的swift类,这不是从NSObject继承的,你需要:

To access a swift class in objc, that is not inherited from NSObject you need to:

@objc public class VeediUtils

@objc public class VeediUtils


必须使用@objc属性标记Swift类或协议才能在Objective-C中访问和使用。该属性告诉编译器可以从Objective-C访问这段Swift代码。如果你的Swift类是Objective-C类的后代,编译器会自动为你添加@objc属性。

A Swift class or protocol must be marked with the @objc attribute to be accessible and usable in Objective-C. This attribute tells the compiler that this piece of Swift code can be accessed from Objective-C. If your Swift class is a descendant of an Objective-C class, the compiler automatically adds the @objc attribute for you.

https://developer.apple.com/library/prerelease/ios/documentation/ Swift / Conceptual / BuildingCocoaApps / MixandMatch.html