I have a weird problem writing a simple unit test (Xcode 7.2) for a very simple function which makes sure a parameter is added to a URL:
func appendToken(token: String, toRequest request: URLRequestConvertible) throws -> URLRequestConvertible {
var error: NSError?
let modifiedRequest: NSMutableURLRequest
(modifiedRequest, error) = Alamofire.ParameterEncoding.URL.encode(request, parameters: ["token": self.token])
guard error == nil else {
// TODO: handle error
throw error!
}
return modifiedRequest
}
The unit test is like this:
func testTokenAddition() {
let token = "ABCD12345"
let client = MyClass(token: token)
let originalRequest = NSURLRequest(URL: NSURL(string:"http://localhost")!)
do {
let modifiedRequest = try client.appendToken(token, toRequest: originalRequest).URLRequest
XCTAssertTrue(modifiedRequest.URLRequest.URLString.hasSuffix("token=\(token)"))
} catch {
XCTFail()
print(error)
}
}
Obviously this is a very simple test on which I want to build upon (so please don't focus on the actual assertion). But when I try to run the test, I get this linking error:
Undefined symbols for architecture x86_64:
"protocol witness table for __ObjC.NSURLRequest : Alamofire.URLRequestConvertible in Alamofire", referenced from:
SDKitTests.SDKitTests.testTokenAddition (SDKitTests.SDKitTests)() -> () in SDKitTests.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
The function works when I run it from a normal target, so the problem is in the test function, but I'm not clear on how I should be calling it, I run the same code in a non-test class and there was no problem, so I'm a bit puzzled by this. Also the error message is a bit cryptic, from what I've Googled, a witness table is kind of like a vtable for protocols. But I haven't messed with that, the extension to NSMutableURLRequest is implemented in Alamofire, and I'm just using it.
What am I doing wrong? What do I need to do to fix it?
Ensure the Alamofire library is linked with your test target.
You may also need to remove inherit! :search_paths from the test target.
Related
Using AWSAppSync ios sdk, trying to configure the AWSAppSyncClient, and the simulator crashes when trying to create a Reachability instance (when trying to get the UserPoolsAuthProvider):
let appSyncConfig = try AWSAppSyncClientConfiguration(appSyncServiceConfig: AWSAppSyncServiceConfig(),
userPoolsAuthProvider: {
class MyCognitoUserPoolsAuthProvider : AWSCognitoUserPoolsAuthProviderAsync {
func getLatestAuthToken(_ callback: #escaping (String?, Error?) -> Void) {
AWSMobileClient.default().getTokens { (tokens, error) in
if error != nil {
callback(nil, error)
} else {
callback(tokens?.idToken?.tokenString, nil)
}
}
}
}
return MyCognitoUserPoolsAuthProvider()}(),
cacheConfiguration: cacheConfiguration)
Below is the full error message:
dyld: lazy symbol binding failed: Symbol not found: _$sSo18NSNotificationNamea12ReachabilityE19reachabilityChangedABvau
Referenced from: /Users/user/Library/Developer/CoreSimulator/Devices/5BD6D58E-C91E-4737-AD3B-547E9D77770B/data/Containers/Bundle/Application/F8307EF9-70B5-4834-BFC4-D340DCF4D3DD/nano-staging.app/Frameworks/AWSAppSync.framework/AWSAppSync
Expected in: /Users/user/Library/Developer/CoreSimulator/Devices/5BD6D58E-C91E-4737-AD3B-547E9D77770B/data/Containers/Bundle/Application/F8307EF9-70B5-4834-BFC4-D340DCF4D3DD/nano-staging.app/Frameworks/Reachability.framework/Reachability
Using aws-mobile-appsync-sdk-ios v3.1.11 and Reachability v5.1.0, would appreciate any help immensely!
You can try to add "Reachability.framework" in xcode to the "Link Binary With Libraries" with the flag "optional"
I need to interact with Hyperledger Fabric in an iOS application, and I've run into a problem when creating the proposal signature. Fabric requires low-s ECDSA, but I can't find a way to specify that in Apple's crypto functions. Without specifying low-s, my calls fail about %50 of the time, when S is higher than R.
My signing code is pretty simple:
static func sign(data:Data, withPrivateKey:SecKey) throws -> Data {
var error: Unmanaged<CFError>?
guard
let signature = SecKeyCreateSignature(
withPrivateKey,
.ecdsaSignatureMessageX962SHA256,
data as CFData,
&error
) as Data?
else {
throw error!.takeRetainedValue()
}
return signature
}
I just switched from Xcode 9 beta 3 to beta 4 the other day, and now I get the following error when I use the OAuthSwift library to connect to Discogs.com. It doesn't seem to be a problem on either OAuthSwift or Discogs' part, though, because the error is:
dyld: lazy symbol binding failed: Symbol not found: __T0SS10FoundationE9substringS2S13CharacterViewV5IndexV2to_tF
Referenced from: /Users/nrith/Library/Developer/CoreSimulator/Devices/<blah-blah-blah>.app/Immediate.app/Frameworks/OAuthSwift.framework/OAuthSwift
Expected in: /Users/nrith/Library/Developer/CoreSimulator/Devices/<blah-blah-blah>.app/Frameworks/libswiftFoundation.dylib
It looks like something to file a radar against, but before doing that, I just wanted to see whether anyone else has come across this.
The OAuthSwift library call that's failing on line 151 of OAuthSwiftCredential:
open func authorizationHeader(method: OAuthSwiftHTTPRequest.Method, url: URL, parameters: OAuthSwift.Parameters, body: Data? = nil) -> String {
let timestamp = String(Int64(Date().timeIntervalSince1970))
let nonce = OAuthSwiftCredential.generateNonce()
return self.authorizationHeader(method: method, url: url, parameters: parameters, body: body, timestamp: timestamp, nonce: nonce)
}
open class func generateNonce() -> String {
let uuidString = UUID().uuidString
return uuidString.substring(to: 8)
}
Specifically, the uuidString.substring(to: 8) is failing.
Here's the relevant info from the stack (note that the generateNonce() method has been inlined):
After downloading Xcode 8 and migrating to Swift 3 I'm not longer able to archive the project. At the same time the project builds without any issues.
Error that I get:
Undefined symbols for architecture armv7:
"Swift.UnsafeMutableBufferPointer.(subscript.materializeForSet :
(Swift.Int) -> A).(closure #1)", referenced from:
function signature specialization of generic specialization
with
Swift.UnsafeMutableBufferPointer :
Swift.MutableCollection in Swift and
Swift.UnsafeMutableBufferPointer :
Swift.RandomAccessCollection in Swift> of Swift._siftDown (inout A,
index : A.Index, subRange : Swift.Range, by : inout
(A.Iterator.Element, A.Iterator.Element) -> Swift.Bool) -> () in
OrderCoordinator.o
function signature specialization of generic specialization
with
Swift.UnsafeMutableBufferPointer :
Swift.MutableCollection in Swift and
Swift.UnsafeMutableBufferPointer :
Swift.RandomAccessCollection in Swift> of Swift._heapSort (inout A,
subRange : Swift.Range, by : inout (A.Iterator.Element,
A.Iterator.Element) -> Swift.Bool) -> () in OrderCoordinator.o
function signature specialization of generic specialization
with
Swift.UnsafeMutableBufferPointer :
Swift.MutableCollection in Swift and
Swift.UnsafeMutableBufferPointer :
Swift.RandomAccessCollection in Swift> of Swift._partition (inout A,
subRange : Swift.Range, by : inout (A.Iterator.Element,
A.Iterator.Element) -> Swift.Bool) -> A.Index in OrderCoordinator.o
ld: symbol(s) not found for architecture armv7 clang: error: linker
command failed with exit code 1 (use -v to see invocation)
I was able to get rid of error by commenting array sorting code in following function:
func didFinishWithResults(_ results: [PhotoProcessorResult]) {
guard let album = albumService.currentAlbum else { return }
//let sortedResults = results.sorted(by: { $0.fileIndex < $1.fileIndex })
let updateItems = zip(sortedResults, album.assetItems).map { (photoProcessorResult, assetItem) -> UpdateItem in
UpdateItem(path: photoProcessorResult.filePath, position: photoProcessorResult.fileIndex, isCover: assetItem.isCover)
}
albumService.updateAlbumWithItems(updateItems) { (success, errorDescription) in
if success {
self.handleAlbumUpdate()
} else {
self.showFailureAlert(errorDescription) {
self.startProcessingAlbum(self.albumService.currentAlbum)
}
}
}
}
While I resolved issue by sorting data using NSArray, I don't like this solution.
Will be grateful for any suggestions.
Since it compiles i don't think there is anything wrong with your code. The fact that it says "Undefined symbols for architecture armv7" and is failing to archive tells me that something is going on with your project, but unfortunately there are many ways to cause this problem. arm7 is iphone 5 so your project is probably setup correctly only for arm64. Try the solutions mentioned here: Undefined symbols for architecture armv7
If here is problem only for the this line:
let sortedResults = results.sorted(by: { $0.fileIndex < $1.fileIndex })
You can change to it:
let sortedResults = results.sorted { (first, second) -> Bool in
return first.fileIndex < second.fileIndex
}
Did it solve your problem?
Issue disappeared after updating to XCode 8.1.
Thanks everyone :)
The full error is this:
Command /Applications/Xcode6-Beta7.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swiftc failed with exit code 254
I'm using RestKit to post an object to a json-accepting endpoint. The following works:
var manager = RKObjectManager(baseURL: NSURL(string: myURL))
manager.addRequestDescriptor(myItemRequestDescriptor)
manager.addResponseDescriptor(myItemResponseDescriptor)
manager.postObject(newItem, path: "/api/saveitem/", parameters: nil, success: nil , failure: nil)
But, if I want to do something with the resulting object:
manager.postObject(newItem, path: "/api/saveitem/", parameters: nil, success: { operation, result in dump(result) } , failure: { operation, error in dump(error) })
I get the error mentioned above. (Also, the line above causes SourceKitService to crash incessantly, I assume it's linked to SourceKitService failing to handle the compiler error gracefully.)
Here are some things that I've tried:
Modifying the code line to use both types of closure syntax (named and unnamed closure parameters: dump($1))
Deleting the DerivedData folder
Has anyone experienced this? Have a workaround? Or have some ideas as to how to work around it?
Edit: Wordaround 1
Using the following to call the endpoint works without compiler errors. It's not an Xcode workaround, though, it's a RestKit workaround.
Instead of calling manager.postObject(), you can get an RKRequestOperation object and use that instead:
var operation: = manager.appropriateObjectRequestOperationWithObject(newItem, method: RKRequestMethod.POST, path: "/api/saveitem/", parameters: nil) as RKObjectRequestOperation
operation.setCompletionBlockWithSuccess({ (operation, response) in
dump(response)
},
failure: { (operation, error) in
dump(error)
})
operation.start()