question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Unable to import Objective-C module into Swift

See original GitHub issue

I have an objective-C(cocoapod JKBigInteger) project I am trying to import into Swift, though the module is compiling correctly, Swift don’t see it.

error: no such module 'JKBigInteger'

First attempt:

apple_library(
  name = 'JKBigInteger',
  exported_headers = glob([
    'JKBigInteger/*.h',
    'JKBigInteger/LibTomMath/*.h'
  ]),
  srcs = glob([
    'JKBigInteger/LibTomMath/*.c',
    'JKBigInteger/*.m',
  ]),
  visibility = ['PUBLIC'],
)

Second attempt by creating a framework:

apple_library(
  name = 'JKBigIntegerDynamicLibrary',
  srcs = glob([
    'JKBigInteger/LibTomMath/*.c',
    'JKBigInteger/*.m',
  ]),
  preprocessor_flags = ['-fobjc-arc'],
  exported_headers = glob([
    'JKBigInteger/JKBigInteger.h',
    'JKBigInteger/LibTomMath/*.h'
  ]),
  visibility = ['PUBLIC'],
  header_path_prefix = 'JKBigInteger',
  frameworks = [
    '$SDKROOT/System/Library/Frameworks/Foundation.framework',
  ],
)

apple_bundle(
  name = 'JKBigInteger',
  binary = ':JKBigIntegerDynamicLibrary#shared',
  extension = 'framework',
  info_plist = 'JKBigInteger/Info.plist',
  visibility = ['PUBLIC'],
)

Using as dependency in my apple_binary:

apple_binary(
  name = 'BuckDemoBinary',
  deps = [
    ':Assets',
    ':Storyboards',
    '//Pods/RxSwift:RxSwift',
    '//Pods/RxCocoa:RxCocoa',
    '//Pods/RxGesture:RxGesture',
    '//Pods/JKBigInteger:JKBigInteger',
  ],
  preprocessor_flags = ['-fobjc-arc', '-Wno-objc-designated-initializers'],
  srcs = glob([
    'BuckDemo/*.swift',
  ]),
  frameworks = [
    '$SDKROOT/System/Library/Frameworks/UIKit.framework',
    '$SDKROOT/System/Library/Frameworks/Foundation.framework',
  ],
)

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:1
  • Comments:7 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
ediascommented, Jan 8, 2020

Any update on this one? I’m having the same issue.

1reaction
mgrebenetscommented, Feb 21, 2018

This one is same as https://github.com/facebook/buck/issues/1563 and I’m trying to solve it using bridging header with no luck.

I have a rule for Lottie:

# Lottie iOS.
apple_library(
    name='Lottie',
    visibility=['PUBLIC'],
    preprocessor_flags = ['-D', 'PRODUCT_NAME=Lottie'],
    exported_headers=glob([
        CHECKOUT_PATH + '/lottie-ios/lottie-ios/Classes/PublicHeaders/*.h',
    ]),
    headers=glob([
        CHECKOUT_PATH + '/lottie-ios/lottie-ios/Classes/**/*.h',
    ]),
    srcs=glob([
        CHECKOUT_PATH + '/lottie-ios/lottie-ios/Classes/**/*.m',
    ]),
    frameworks=[
        '$SDKROOT/System/Library/Frameworks/UIKit.framework',
    ],
)

Then I add it in another apple_binary rule:

apple_binary(
    name='AppBinary',
    headers=glob([
        os.path.join(APP_SRC, '**/*.h'),
    ]),
    bridging_header='App/Supporting Files/App-Bridging-Header.h',
    preprocessor_flags=['-fobjc-arc', '-Wno-objc-designated-initializers'],
    srcs=PROD_TARGET_FILES,
    deps=[
        '//vendor:Lottie',
    ],
    frameworks=DEFAULT_FRAMEWORKS,
)

In the bridging header I’ve added #import <Lottie/Lottie.h>, but no luck so far.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Importing Objective-C into Swift - Apple Developer
To import a set of Objective-C files into Swift code within the same app target, ... it by using your product module name...
Read more >
Unable to Import Objective-C Files into Swift project using ...
1 Answer 1 ... . Make sure AsyncSocket appears under Compile Sources of Build Phases and its header file is imported in the...
Read more >
Swift-Objective C interoperability and best practices - Infinum
To use Objective-C code in Swift, it is only necessary to import Objective-C header file in bridging header file to expose it to...
Read more >
Swift SPM dependency on Objc SPM (Could not build ... - Reddit
I have FeatureASwiftSPM that has a dependency on ObjectiveCSPM, this SPM starts to fail as soon as I import `ObjectiveCSPM` with the error...
Read more >
Header import conditionally fails in mixed Swift package
This works well when I build the MyPackageObjC target, and I can use the resulting package in Obj-C code in my app. However,...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found