I created Objective C Header file. and added some properties in it.
i declaredstatic NSString* const kColor005C98 = @"005C98";
in Constants.h
file
I defined this file in Bridging-Header file as #import "Constants.h"
Now when i want to use this property kColor005C98
in some swift file it failed the build and i am getting
Undefined symbols for architecture armv7: "_kColor005C98", referenced from:
i don't know what else i need to do so i don't get this error? (i have used this property in other objective C file successfully and no issue in that case)
The error Undefined symbols for architecture arm64: "_OBJC_CLASS_$_SKAdImpression" during the iOS build usually happens if XCode or CocoaPods version is lower than required. To fix it update XCode to 12.5 or higher and CocoaPods to 1.10. 0 or higher.
You can use Objective-C and Swift files together in a single project, no matter which language the project used originally. This makes creating mixed-language app and framework targets as straightforward as creating an app or framework target written in a single language.
Import Swift code into Objective-C within the same framework: Under Build Settings, in Packaging, make sure the Defines Module setting for that framework target is set to Yes. Import the Swift code from that framework target into any Objective-C .
Update:
As of Swift 2/Xcode 7 and later, a static constant definition like
static NSString* const kColor005C98 = @"005C98"; // in Constants.h file
is imported to Swift and can be used without problems.
(Old answer for Swift 1.x) When the code
static NSString* const kColor005C98 = @"005C98"; // in Constants.h file
is processed by an Objective-C compiler, it is treated as two things combined into one statement:
See for example What is the difference between a definition and a declaration? for a good explanation of the difference between declaration and definition.
The Swift compiler treats the statement only as a declaration. Therefore the variable is not defined anywhere, causing the linker error.
To solve the problem, you have to move the definition to an Objective-C file:
// Constants.m:
#import "Constants.h"
NSString * const kColor005C98 = @"005C98";
and change the declaration to an extern
declaration:
// Constants.h:
extern NSString * const kColor005C98;
Alternatively, you can just remove the static
modifier:
NSString * const kColor005C98 = @"005C98";
to make it work with Swift. The disadvantage is that when
this line is included by multiple Objective-C files, all of them
will define a globally visible symbol kColor005C98
, causing
"duplicate symbol" linker errors.
Another alternative is to use a macro definition instead:
#define kColor005C98 @"005C98"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With