Get Unresolved Identifier for MMWormhole in Watch InterfaceController.swift

My Apple Watch project is in Swift. I have used CocoaPods to install MMWormhole,
and I created the bridging header as described in these links:

  • Approaching Size Limit - The size of watch application (50MB limit is headache.)
  • Using Core Location in Apple WatchKit
  • watchOS 2: haptic feedback in background
  • NSXMLParserErrorMessage - Could not open data stream
  • How can i start developing app on watchOS 3 SDK?
  • Play Video From URL in WatchOS 2
  • How to call Objective-C code from Swift

    When I created the bridging header, I target it to my iphone app, and also watch Extension.

    The bridging header.h, I have this:

    #import "MMWormhole.h"

    In my iPhone app View Controller, I have this:

    import UIKit
    import Foundation 
    let wormhole = MMWormhole(applicationGroupIdentifier: "group.cocoShareData", optionalDirectory: "wormhole")

    and there is no complain.

    However, in my watch Interface Controller, I have this:

    import WatchKit
    import Foundation
    override func willActivate() {
            // This method is called when watch view controller is about to be visible to user
            let wormhole = MMWormhole(applicationGroupIdentifier: "group.cocoShareData", optionalDirectory: "wormhole")

    And it complains about “Use of unresolved identifier MMWormhole”.

    I even try to use #import “MMWormholeClient.h” but nothing can resolve this problem.

    I also try when creating the bridging header, just target on the iphone App. But still… doesn’t work.

    I also make pod ‘MMWormhole’, ‘~> 1.2.0’ in the podfile target for WatchExtension. but still not identified MMWormhole in the Watch interfaceController

    Am I missing something ?

    here is my project:

    Solutions Collect From Internet About “Get Unresolved Identifier for MMWormhole in Watch InterfaceController.swift”

    Here is my answer. After few days of struggle and help from a code mentor:

    Problems are:

    1) The Objective-C bridge has to set the correct path and header search path so both IOS & WatchExt can use
    2) The PodFile in MMWormhole must target for both iOS & WatchExt. 
    3) The code in MMWormhole npm page is not correct.  Move the instantiation of MMWormhole out and be a class Variable.

    Here is the brief step by step:

    Objective C Bridge

    • Add App Groups for both iPhone App & Watch Ext
    • Add Objective C
    • Target on both
    • Build Settings: Set the *.h in relative path for both iOS & Watch Ext. set the *.h relative path. e.g.
    • Add Header Search path: ${PRODS_ROOT}/Headers , recursive for both IOS 7 Watch Ext


    • Cocoa pods it.
    • Set pod ‘MMWormhole’, ‘~> 1.2.0’ target for both iOS & Watch Ext in Podfile
    • Set #import “MMWormhole.h” in bridging header file.
    • in both ViewController & InterfaceOController, set wormhole as class scope variable. e.g. var wormhole:MMWormhole!
    • Instantiate MMWormhole in ViewDidLoad and awakeWithContext
      in WatchExt, set listener in awakeWithContext , and use self.lable.setText because of closure. e.g. self.label.setText(messageObject! as! String)
    • No need to register receiver as shown in some other MMWormhole examples in Stack overflow.