objective-cswiftpocket

NSWorkspace throwing error when bridging library with swift


I'm using the pocket api and bridging it over to use with swift and it's throwing the error "Semantic issue: Use of undeclared identifier 'NSWorkspace'" for the following line in their obj-c API:

[[NSWorkspace sharedWorkspace] openURL:url];

The app is targeting os 10.9+, so it should be available.

Any ideas on what can cause that error?

Update I've also tested in iOS, and it's returning the same error, but with 'UIApplication' instead of 'NSWorkspace'.

I also forgot to mention I had to use the -fno-objc-arc flag in the Build Phases tab so the lib doesn't freak out over ARC.


Solution

  • Got it working on iOS and OSX by adding the following code after the imports in PocketAPI.m and PocketAPILogin.m:

    #ifdef __IPHONE_OS_VERSION_MAX_ALLOWED
       #import <UIKit/UIKit.h>
    #endif
    
    #ifdef __MAC_OS_X_VERSION_MAX_ALLOWED
       #import <Appkit/AppKit.h>
    #endif