小编L.W*_*iam的帖子

Alamofire 5:“Result<Data, AFError>”类型的值没有成员“value”

是 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)

ios swift alamofire

15
推荐指数
1
解决办法
8534
查看次数

创建一个只接受正整数的 Swift 函数

我正在尝试创建一个只接受正整数的公共函数。我想不出任何方法来做到这一点。即使我要检查该值并返回错误,我该怎么办?我当前的代码是:

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)

int ios swift

1
推荐指数
1
解决办法
1777
查看次数

以编程方式 Swift 打开蓝牙

我正在尝试使用我的应用程序自动打开蓝牙。通常的方法是用户进入设置并打开。但我需要从应用程序中打开。我查阅了很多文档,它们都指的是私有 API,但都非常旧了。我不介意它不会在 App Store 获得批准。

有没有办法以编程方式打开蓝牙?

ios core-bluetooth swift

0
推荐指数
1
解决办法
3404
查看次数

标签 统计

ios ×3

swift ×3

alamofire ×1

core-bluetooth ×1

int ×1