简体   繁体   中英

Accessing extern NSString from Objective-C in Swift

I have an extern as NSString in Objective-c and wanted to see if it can be accessed from Swift? And if so how would it get accessed.

Let's say the extern is as following:

extern NSString *_Nonnull const test;

You can easily test this thing

Like you have a file const.h where you have placed that extern Now import const.h in bridging header, if that extern is just a string or number or int or something like that it will easily be accessible

Like

Const.h

extern NSString * const test = “testing”;

Bridging_header.h

#import “const.h” 

SwiftTest.swift ....

Print(test)

您可以在Swift中将其用作全局常量test ,类似于在类/结构范围之外let test = "message"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM