I have defined some constants in my .m
files that I need to access form my swift code. They are defined:
const CGFloat testValue = 40.0;
and in my other objective-c .m
files I can access them by using extern
:
extern const CGFloat testValue
Is there an equivalent way of making these constants accessible from the .swift files?
Just put the
var
declaration above the class - it will become a global variable.Add the
extern
to your bridging header and Swift should be able to access it.This simple test worked for me:
ObjCTest.m
ObjCSwiftBridgeTest-Bridging-Header.h
main.swift
Output