I have an iOS project that uses both Obj-C and Swift.
In main.m
, I want to instantiate a variable to be accessed by Swift. The specific use case is to store the absolute time at main
, and then measure time elapsed since main
elsewhere.
Here's what my relevant files look like:
main.m
#import <UIKit/UIKit.h>
CFAbsoluteTime StartTime;
int main(int argc, char* argv[])
{
StartTime = CFAbsoluteTimeGetCurrent(); // This is what I want to access elsewhere.
@autoreleasepool {
...
}
}
myapp-Bridging-Header.h
#import "AppDelegate.h"
extern CFAbsoluteTime StartTime;
AppDelegate.h
#import <UIKit/UIKit.h>
extern CFAbsoluteTime StartTime;
@interface AppDelegate : NSObject <UIApplicationDelegate>{}
@property (nonatomic, strong) IBOutlet UIWindow* window;
// ... other irrelevant @property
@end
And then in the actual .swift
file, I'm just trying to access StartTime
without declaring anything (as I thought it worked since it's being externed), but I'm getting an unresolved identifier
error.