Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 546
reza23 Avatar asked Sep 05 '14 15:09

reza23


1 Answers

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
like image 200
Mike S Avatar answered Sep 20 '22 21:09

Mike S