0

I have in my Bridging-Header.h:

#ifndef EXAMPLE_HEADER_H
#define EXAMPLE_HEADER_H

#import "com/example/MyObject.h"

#endif

The Swift Compiler - Code Generation also has been updated to have a reference to this file under Build Settings.

While the bridge header file alone compiles and runs with the project, as soon as I try to initialize an object, like in AppDelegate.swift:

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {

var window: UIWindow?

func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
    // Override point for customization after application launch.
    let example = ComExampleMyObject()
    return true
}

I get the following error:

Undefined symbols for architecture x86_64:
  "_OBJC_CLASS_$_ComExampleMyObject", referenced from:
      type metadata accessor for __ObjC.ComExampleMyObject in AppDelegate.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

Any ideas on what went wrong?

  • Have you defined ComExampleMyObject correctly and is it added to the target? – blacksheep_2011 Feb 01 '16 at 01:20
  • @blacksheep_2011 Yes it is defined correctly. It is a Java class with a single constructor and String member variable (with its own setter and getter). What do you mean is it added to the target? – weeehee123 Feb 01 '16 at 02:13

1 Answers1

1

"Adding to the target" means including the file in your app, or whatever build target that is currently failing. To add it, select the project in the Project Explorer, click on the target, then click on Build Phases and expand the Compile Sources step, and click the + icon and add MyObject.m. Now your project will build and include the translated Java source.

tball
  • 1,984
  • 11
  • 21
  • I see. Do I have to do this for every file that is translated? It seems like cumbersome manual labor if the shared codebase becomes large. – weeehee123 Feb 02 '16 at 06:33
  • Another option you have is to add a Java build rule, then add the Java files to your project (http://j2objc.org/docs/Xcode-Build-Rules.html). One way or the other, Xcode needs to be explicitly told what files make up a project. That's why we'll be moving to Bazel (http://bazel.io), as it rebuilds Xcode projects with all the necessary dependencies. – tball Feb 03 '16 at 17:38