【问题标题】:Accessing extern NSString from Objective-C in Swift在 Swift 中从 Objective-C 访问外部 NSString
【发布时间】:2018-12-31 12:02:12
【问题描述】:

我在 Objective-c 中有一个作为 NSString 的 extern,想看看它是否可以从 Swift 访问?如果是这样,它将如何被访问。

假设extern如下:

extern NSString *_Nonnull const test;

【问题讨论】:

    标签: ios objective-c swift cocoa


    【解决方案1】:

    你可以很容易地测试这个东西

    就像你有一个文件 const.h 你放置了外部 现在在桥接头中导入 const.h,如果该 extern 只是一个字符串或数字或 int 或类似的东西,它将很容易访问

    喜欢

    Const.h

    extern NSString * const test = “testing”;
    

    Bridging_header.h

    #import “const.h” 
    

    SwiftTest.swift ....

    Print(test)
    

    【讨论】:

      【解决方案2】:

      你可以在Swift中使用它作为全局常量test,类似于let test = "message"在类/结构范围之外

      【讨论】:

        猜你喜欢
        • 2016-03-04
        • 1970-01-01
        • 2016-10-02
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多