1

I am trying to call swift function from objective c file.

Swift function implementation:

@objc class FXFormVariables : NSObject {
    class func FXFontName() -> String { return fontName }
    class func FXFontSize() -> CGFloat { return fontSizeLarge }
    class func FXHiddenCell() -> NSArray { return hiddenElementFromFormIndex as NSArray }
}

Objective C:

NSArray *hideArray = [FXFormVariables FXHiddenCell];
if ([hideArray containsObject:@(cellIndexPath)]){
        return 0.0;
}

Linker error in Buildtime:

 Undefined symbols for architecture x86_64:
  "_OBJC_CLASS_$__TtCC13Social_Engine11AppDelegate15FXFormVariables", referenced from:
      objc-class-ref in FXForms.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

This code works fine in Xcode 7.3 but after upgrade to 8.3 it start throwing linker error.

Please help. Thanks in advance.

Rekha.t
  • 161
  • 6
  • 14
Vaibhav Agarwal
  • 238
  • 5
  • 19

2 Answers2

0

Import file named Project name appending by -Swift.h in your Objective-C file

Please check below example of import file

#import “ProjectName-Swift.h”

Xcode will generate this file when you build your project with .swift files.

Also, you can check from below question: How to import Swift code to Objective-C

Community
  • 1
  • 1
Patrick R
  • 6,621
  • 1
  • 24
  • 27
0

you can get this type of error check your class is listed under the "Compile Sources" step of the "Build Phases" tab of your target. Normally Xcode does this for you, but sometimes it loses the plot and you need to add the class file manually.

To do this:

TargetSettings -> Build Phases -> Compile Sources -> add your class -.swift >Build and Run

Rekha.t
  • 161
  • 6
  • 14