Closed neerajkhede16 closed 5 years ago
I'm sorry you're encountering this issue, @neerajkhede16. I looked at your sample, but there are too many external factors in the complex project configuration to determine whether AnyCodable is the cause of any problems you're having.
Have you tried deleting ~/Library/Developer/Xcode/DerivedData
or removing Pods
and re-running pod install
?
Yes, I tried already tried deleting DerivedData and/or removing Pods before reporting the issue, It is working on Xcode 12.1 version but not on 12.2.1. Other developers in team also facing the same issue.
Thanks for following up. Which version of the library are you using and how are you installing it?
I was using version number 0.2.2, and I added 3 files AnyCodable, AnyDecodable and AnyEncodable into my framework.
Searching for that error message, it looks like one possible resolution is to add an import
statement: https://github.com/ReactiveX/RxSwift/issues/1583
Looking through the attached sample, I think that might work. Can you give that a try?
Sorry, not getting your suggestion. we can import module only in the app, how can we import any structure file?
could you please try that fix in my sample code and share it with me?
The error you're seeing has to do with the linker not being able to find those referenced types. Whichever module you're including AnyCodable files, you're very likely missing an import
statement for that module somewhere.
At this point, I don't have any reason to believe that the problem you're seeing is specific to AnyCodable; if you continue to have issues, I'd recommend looking for answers on Stack Overflow or another community forum.
Steps are very easy to reproduce, you can also do it, To believe on me you just need to follow below steps:
You will find error as mentioned above. In debug mode it works fine.
Which package manager did you use?
To reproduce the issue I created framework from Xcode, by selecting "Cocoa touch framework" and added to sample app directly by going to Target >> Build Phases >> Link binary with library. Instantiate AnyCodable structure in the sample app and make archive will show you errors.
Initially I was facing issue while creating framework and creating cocoapods library, and consumed the library in production created issue for me, so I tried the same on sample app (mentioned in first line) and found same issue found.
Issue can be seen in both the cases.
This is a little bit weird but understandable.
I think that Swift 5.0 toolchain is removing (or hiding) internal names for some reason.
_AnyEncodable
is an internal protocol and the mangled names are removed (or hided) because of the above reason.
You can avoid this issue by patch like this:
--- A/Sources/AnyCodable/AnyEncodable.swift
+++ B/Sources/AnyCodable/AnyEncodable.swift
@@ -205,7 +205,41 @@
extension AnyEncodable: ExpressibleByArrayLiteral {}
extension AnyEncodable: ExpressibleByDictionaryLiteral {}
-extension _AnyEncodable {
+extension AnyEncodable {
+ public init(nilLiteral _: ()) {
+ self.init(nil as Any?)
+ }
+
+ public init(booleanLiteral value: Bool) {
+ self.init(value)
+ }
+
+ public init(integerLiteral value: Int) {
+ self.init(value)
+ }
+
+ public init(floatLiteral value: Double) {
+ self.init(value)
+ }
+
+ public init(extendedGraphemeClusterLiteral value: String) {
+ self.init(value)
+ }
+
+ public init(stringLiteral value: String) {
+ self.init(value)
+ }
+
+ public init(arrayLiteral elements: Any...) {
+ self.init(elements)
+ }
+
+ public init(dictionaryLiteral elements: (AnyHashable, Any)...) {
+ self.init([AnyHashable: Any](elements, uniquingKeysWith: { first, _ in first }))
+ }
+}
+
+extension AnyCodable {
public init(nilLiteral _: ()) {
self.init(nil as Any?)
}
Good luck.
This patch works. Are you not going to release another version after including these changes.
Are you not going to release another version after including these changes.
I will open the pull request which associated with this issue, but Iām currently finding a real reason to resolve this issue perfectly.
So, please wait for a few days! šāāļø
@minacle Do you have any update on this topic?
I wrote a pull request (#24) and currently waiting to be merged.
@neeraj110600 @neerajkhede16 Good news! The changes are merged and you can try v0.2.3 now!
I am getting following error while using library:
Undefined symbols for architecture arm64: "protocol witness table for MyTestFramework.AnyCodable : MyTestFramework._AnyEncodable in MyTestFramework", referenced from: function signature specialization <Arg[0] = Dead> of TestAnyEncodable.ViewController.test() -> () in ViewController.o "(extension in MyTestFramework):MyTestFramework._AnyEncodable.init(floatLiteral: Swift.Double) -> A", referenced from: function signature specialization <Arg[0] = Dead> of TestAnyEncodable.ViewController.test() -> () in ViewController.o "(extension in MyTestFramework):MyTestFramework._AnyEncodable.init(stringLiteral: Swift.String) -> A", referenced from: function signature specialization <Arg[0] = Dead> of TestAnyEncodable.ViewController.test() -> () in ViewController.o "(extension in MyTestFramework):MyTestFramework._AnyEncodable.init(booleanLiteral: Swift.Bool) -> A", referenced from: function signature specialization <Arg[0] = Dead> of TestAnyEncodable.ViewController.test() -> () in ViewController.o "(extension in MyTestFramework):MyTestFramework._AnyEncodable.init(integerLiteral: Swift.Int) -> A", referenced from: function signature specialization <Arg[0] = Dead> of TestAnyEncodable.ViewController.test() -> () in ViewController.o "(extension in MyTestFramework):MyTestFramework._AnyEncodable.init(nilLiteral: ()) -> A", referenced from: function signature specialization <Arg[0] = Dead> of TestAnyEncodable.ViewController.test() -> () in ViewController.o ld: symbol(s) not found for architecture arm64 clang: error: linker command failed with exit code 1 (use -v to see invocation)
Issue is reproducible
You can download the Sample framework and test app where the issue is reproducible from here