From a7b814361c085eeb54b50f785adc333197d5098c Mon Sep 17 00:00:00 2001 From: jefft0 Date: Tue, 11 Oct 2022 00:35:00 -0700 Subject: [PATCH] fix: Update go.mod berty/mobile version. Fix Swift calls to send(). Update go.mod to use the latest berty/mobile which has this fix: https://github.com/golang/mobile/pull/85 . In Swift this correctly uses the RequestBuilder.send() signature with Data? , so update Swift calls to unwrap it. Signed-off-by: jefft0 --- ios/Bridge/GomobileIPFS/Sources/Config.swift | 2 +- .../GomobileIPFS/Sources/RequestBuilder.swift | 8 +++++--- .../BasicIPFSClassTests.swift | 5 ++++- .../GomobileIPFSTests/RequestIPFSTests.swift | 18 ++++++++++++------ ios/Example/Example/ViewController.swift | 4 ++-- packages/go.mod | 2 +- packages/go.sum | 4 ++-- 7 files changed, 27 insertions(+), 16 deletions(-) diff --git a/ios/Bridge/GomobileIPFS/Sources/Config.swift b/ios/Bridge/GomobileIPFS/Sources/Config.swift index 12071346..92e8c611 100644 --- a/ios/Bridge/GomobileIPFS/Sources/Config.swift +++ b/ios/Bridge/GomobileIPFS/Sources/Config.swift @@ -82,7 +82,7 @@ public class Config { public func get() throws -> [String: Any] { do { let rawJson = try self.goConfig.get() - let json = try JSONSerialization.jsonObject(with: rawJson, options: []) + let json = try JSONSerialization.jsonObject(with: rawJson!, options: []) return (json as? [String: Any])! } catch let error as NSError { throw ConfigError("getting failed", error) diff --git a/ios/Bridge/GomobileIPFS/Sources/RequestBuilder.swift b/ios/Bridge/GomobileIPFS/Sources/RequestBuilder.swift index 54893820..3e20c35f 100644 --- a/ios/Bridge/GomobileIPFS/Sources/RequestBuilder.swift +++ b/ios/Bridge/GomobileIPFS/Sources/RequestBuilder.swift @@ -101,7 +101,7 @@ public class RequestBuilder { /// - Throws: `RequestBuilderError`: If sending the request failed /// - Returns: A Data object containing the response /// - seealso: [IPFS API Doc](https://docs.ipfs.io/reference/api/http/) - public func send() throws -> Data { + public func send() throws -> Data? { do { return try self.requestBuilder.send() } catch let error as NSError { @@ -113,8 +113,10 @@ public class RequestBuilder { /// - Throws: `RequestBuilderError`: If sending the request or converting the response failed /// - Returns: A dict containing the response /// - seealso: [IPFS API Doc](https://docs.ipfs.io/reference/api/http/) - public func sendToDict() throws -> [String: Any] { - let res = try self.requestBuilder.send() + public func sendToDict() throws -> [String: Any]? { + guard let res = try self.requestBuilder.send() else { + return nil + } do { let json = try JSONSerialization.jsonObject(with: res, options: []) diff --git a/ios/Bridge/GomobileIPFSTests/BasicIPFSClassTests.swift b/ios/Bridge/GomobileIPFSTests/BasicIPFSClassTests.swift index d9e6fc07..f58029bb 100644 --- a/ios/Bridge/GomobileIPFSTests/BasicIPFSClassTests.swift +++ b/ios/Bridge/GomobileIPFSTests/BasicIPFSClassTests.swift @@ -101,7 +101,10 @@ class BasicIPFSClassTests: XCTestCase { } func makeRequest() throws { - let res = try ipfs.newRequest("id").sendToDict() + guard let res = try ipfs.newRequest("id").sendToDict() else { + XCTFail("error while casting dict for \"id\"") + return + } // TODO: improve these checks guard let peerID = res["ID"] as? String else { diff --git a/ios/Bridge/GomobileIPFSTests/RequestIPFSTests.swift b/ios/Bridge/GomobileIPFSTests/RequestIPFSTests.swift index f316fe96..b38e15e4 100644 --- a/ios/Bridge/GomobileIPFSTests/RequestIPFSTests.swift +++ b/ios/Bridge/GomobileIPFSTests/RequestIPFSTests.swift @@ -25,12 +25,18 @@ class RequestIPFSTests: XCTestCase { func testDNSRequest() throws { let domain = "website.ipfs.io" - let resolveResp = try ipfs.newRequest("resolve") + guard let resolveResp = try ipfs.newRequest("resolve") .with(argument: "/ipns/\(domain)") - .sendToDict() - let dnsResp = try ipfs.newRequest("dns") + .sendToDict() else { + XCTFail("error while casting dict for \"resolve\"") + return + } + guard let dnsResp = try ipfs.newRequest("dns") .with(argument: domain) - .sendToDict() + .sendToDict() else { + XCTFail("error while casting dict for \"dns\"") + return + } guard let resolvePath = resolveResp["Path"] as? String else { XCTFail("error while casting value associated to \"Path\" key") @@ -61,9 +67,9 @@ class RequestIPFSTests: XCTestCase { .send() do { - try JSONSerialization.jsonObject(with: latestRaw, options: []) + try JSONSerialization.jsonObject(with: latestRaw!, options: []) } catch _ { - XCTFail("error while parsing fetched JSON: \(String(decoding: latestRaw, as: UTF8.self))") + XCTFail("error while parsing fetched JSON: \(String(decoding: latestRaw! , as: UTF8.self))") } } } diff --git a/ios/Example/Example/ViewController.swift b/ios/Example/Example/ViewController.swift index 9ffeeb2e..22e79755 100644 --- a/ios/Example/Example/ViewController.swift +++ b/ios/Example/Example/ViewController.swift @@ -110,7 +110,7 @@ class ViewController: UIViewController { .send() title = "IPFS File" - image = UIImage(data: fetchedData)! + image = UIImage(data: fetchedData!)! } catch let err as IPFSError { error = err.localizedFullDescription } catch let err { @@ -257,7 +257,7 @@ class ViewController: UIViewController { .send() title = "\(randomIndex). \(fetchedInfo["title"] as! String)" - image = UIImage(data: fetchedData)! + image = UIImage(data: fetchedData!)! } catch let err as IPFSError { error = err.localizedFullDescription } catch let err { diff --git a/packages/go.mod b/packages/go.mod index 7932ac23..805b5a01 100644 --- a/packages/go.mod +++ b/packages/go.mod @@ -243,5 +243,5 @@ require ( replace ( github.com/ipfs-shipyard/gomobile-ipfs/go => ../go github.com/lucas-clemente/quic-go => github.com/lucas-clemente/quic-go v0.25.0 - golang.org/x/mobile => github.com/berty/mobile v0.0.8 // temporary, see https://github.com/golang/mobile/pull/58 and https://github.com/golang/mobile/pull/82 + golang.org/x/mobile => github.com/berty/mobile v0.0.9 // temporary, see https://github.com/golang/mobile/pull/58 and https://github.com/golang/mobile/pull/82 ) diff --git a/packages/go.sum b/packages/go.sum index d3f43b7c..daf85452 100644 --- a/packages/go.sum +++ b/packages/go.sum @@ -88,8 +88,8 @@ github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24 github.com/beorn7/perks v1.0.0/go.mod h1:KWe93zE9D1o94FZ5RNwFwVgaQK1VOXiVxmqh+CedLV8= github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM= github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw= -github.com/berty/mobile v0.0.8 h1:DoIuvRWaHPvrrVtLxg1ZFu9n1cTVQwkK1PkI6XbzC5M= -github.com/berty/mobile v0.0.8/go.mod h1:pe2sM7Uk+2Su1y7u/6Z8KJ24D7lepUjFZbhFOrmDfuQ= +github.com/berty/mobile v0.0.9 h1:ZWQFacIyXurHArdJiEG9wmryRIWj8hrSLTnCEKrHrDc= +github.com/berty/mobile v0.0.9/go.mod h1:pe2sM7Uk+2Su1y7u/6Z8KJ24D7lepUjFZbhFOrmDfuQ= github.com/bgentry/speakeasy v0.1.0/go.mod h1:+zsyZBPWlz7T6j88CTgSN5bM796AkVf0kBD4zp0CCIs= github.com/blang/semver/v4 v4.0.0 h1:1PFHFE6yCCTv8C1TeyNNarDzntLi7wMI5i/pzqYIsAM= github.com/blang/semver/v4 v4.0.0/go.mod h1:IbckMUScFkM3pff0VJDNKRiT6TG/YpiHIM2yvyW5YoQ=