是 Alamofire 5 中的新错误吗?因为上次没有遇到错误。下面是完成的代码。任何使用 Alamofire 的人都面临这个问题?
import Foundation
import Alamofire
class MyAppService {
static let shared = MyAppService()
let url = "http://127.0.0.1:5000"
private init() { }
func getCurrentUser(_ completion: @escaping (SomeRequest?) -> ()) {
let path = "/somePath"
AF.request("\(url)\(path)").responseData { response in
if let data = response.result.value { //error shown here (Value of type 'Result<Data, AFError>' has no member 'value')
let contact = try? SomeRequest(protobuf: data)
completion(contact)
}
completion(nil)
}
}
}
Run Code Online (Sandbox Code Playgroud) 我正在尝试创建一个只接受正整数的公共函数。我想不出任何方法来做到这一点。即使我要检查该值并返回错误,我该怎么办?我当前的代码是:
public func encodeQuantity(value: Int) -> String {
// Besides using if-else to check, is there any alternatives?
if value < 0 {
return "Negative values are not supported" << I dont know how we should return an error here to the user when using our function but putting a negative number
} else {
return "\(value+10)"
}
}
Run Code Online (Sandbox Code Playgroud) 我正在尝试使用我的应用程序自动打开蓝牙。通常的方法是用户进入设置并打开。但我需要从应用程序中打开。我查阅了很多文档,它们都指的是私有 API,但都非常旧了。我不介意它不会在 App Store 获得批准。
有没有办法以编程方式打开蓝牙?