Accessing global const CGFloat defined in an Objective-c .m file from Swift

房东的猫 提交于 2019-12-05 07:43:53

Add the extern to your bridging header and Swift should be able to access it.

This simple test worked for me:

ObjCTest.m

#import <Foundation/Foundation.h>

const CGFloat testValue = 40.0;

ObjCSwiftBridgeTest-Bridging-Header.h

#import <Foundation/Foundation.h>

extern const CGFloat testValue;

main.swift

println(testValue);

Output

40.0

Just put the var declaration above the class - it will become a global variable.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!