swiftframework方法如何导出

swift framework中的方法如何在objective-c中调用呢?

类或属性加@objc public

stackoverflow的解答

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

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

示例如下:


@objc public class YKFile: NSObject {
    
    @objc public var fileName : String?
    
    @objc public var myData : Data?
    
    @objc public func myFilePath() -> String {
        return "ksnowlv"
    }
    
    @objc public static func name() -> String {
        return "ksnowlv"
    }
}

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • rljs by sennchi Timeline of History Part One The Cognitiv...
    sennchi阅读 7,449评论 0 10
  • mean to add the formatted="false" attribute?.[ 46% 47325/...
    ProZoom阅读 2,726评论 0 3
  • 我是日记星球144号星宝宝罗云,正在参加孙老师的日记星球21天蜕变之旅的写作训练,这是我的第23篇原创日记,要在2...
    罗文均阅读 294评论 5 7
  • 我们常常听说,最可怕的对手是什么,不是你知道TA是谁,TA有多厉害,而是你根本就没见过,但是挥之不去,走哪都感受到...
    俏姐原创成都阅读 274评论 0 0
  • 今天不算忙,但我却睡得比较早,吃了一顿饱饭八点了,吃完之后我却显得很累,所以我八点半就躺在了床上,去休息,去调整,...
    庄德坤阅读 172评论 0 0