我怎样才能从我的函数中删除Bool返回而不出现错误:
Generic parameter 'T' could not be inferred
这是一个函数:
private func syncDataStore() async throws -> Bool {
try await withUnsafeThrowingContinuation { continuation in
Amplify.DataStore.stop { (result) in
switch(result) {
case .success:
Amplify.DataStore.start { (result) in
switch(result) {
case .success:
print("DataStore started")
continuation.resume(returning: true)
case .failure(let error):
print("Error starting DataStore:\(error)")
continuation.resume(throwing: error)
}
}
case .failure(let error):
print("Error stopping DataStore:\(error)")
continuation.resume(throwing: error)
}
}
}
}
这是我试图做的,但我得到上面提到的错误:
private func syncDataStore() async throws {
try await withUnsafeThrowingContinuation { continuation in
Amplify.DataStore.stop { (result) in
switch(result) {
case .success:
Amplify.DataStore.start { (result) in
switch(result) {
case .success:
print("DataStore started")
continuation.resume()
case .failure(let error):
print("Error starting DataStore:\(error)")
continuation.resume(throwing: error)
}
}
case .failure(let error):
print("Error stopping DataStore:\(error)")
continuation.resume(throwing: error)
}
}
}
}
老实说,我不知道它为什么抱怨,没有回报,它不依赖于任何模型或任何东西...
5条答案
按热度按时间xxb16uws1#
这是最有效的方法:
pbwdgjma2#
技巧是将
withUnsafeThrowingContinuation
的返回值强制转换为Void
,如下所示:vsnjm48y3#
让我们看看签名
如图所示,
withUnsafeThrowingContinuation
是返回值具有泛型的函数,其类型从continuation中检测到因此,您的情况下的解决方案可以如下:
n9vozmp44#
在“私有函数syncDataStore()异步抛出{...}"中尝试以下操作:
kulphzqa5#
这在iOS 14上确实有效