ios - 在 Swift 中从 Objective-C 访问 extern NSString

标签 ios objective-c swift cocoa

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

假设外部如下:

extern NSString *_Nonnull const test;

最佳答案

你可以轻松测试这个东西

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

喜欢

Const.h

extern NSString * const test = “testing”;

Bridging_header.h

#import “const.h” 

SwiftTest.swift ....

Print(test)

关于ios - 在 Swift 中从 Objective-C 访问 extern NSString,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51488887/

相关文章:

objective-c - MKMapView setSelected : animated: not working first time

ios - 将手势 UITapGestureRecognizer 添加到 UILabel 后应用程序崩溃

ios - UIPopoverController 显示的 UIViewController 的大小类错误

objective-c - objc_getProtocol() 为 `NSApplicationDelegate"返回 NULL ?

ios - 我不明白为什么我的电话使用本地时区的代码不起作用

ios - 应用程序在 AdHoc 期间崩溃,但在调试期间不会崩溃

ios - UIColor 饱和度亮度值不同于颜色的常规饱和度亮度值

iphone - 将数组中的 NSString 转换为 NSDates

swift - 和有什么不一样?和 ? = 无

ios - 无法将类型 '[String : String?]' 的值转换为预期的参数类型 '[String : AnyObject?]'