gpt4 book ai didi

ios - Alamofire: 'weak' 无法应用于非类类型错误

转载 作者:行者123 更新时间:2023-11-30 13:49:05 27 4
gpt4 key购买 nike

我知道,在非引用类型数据上使用 weak 时,这会引发错误。但是,我在我自己创建的类上使用它。只是想知道是否有人遇到同样的问题。

internal static func registeruUser(email email: String, username: String, password: String, completion: (user: TSUser?, error: NSError?) -> Void) {

let baseURL = NSLocalizedString("sign_up", comment: "")
let headers = ["Accept": "application/json",
"Content-Type": "application/json"]
let parameters = ["email": email, "name": username, "password": password]

Alamofire.request(.POST, baseURL, headers: headers, parameters: parameters, encoding: .JSON).responseJSON {
[weak self] response in // compiler error

if let weakSelf = self {
switch response.result {
case .Success:
if let value = response.result.value {

let json = JSON(value)
if let jsonUser = json["user"].dictionaryObject,
let user = Mapper<TSUser>().map(jsonUser) as TSUser? {

currentUser = user
weakSelf.storeUserToCache() // compiler error
completion(user: user, error: nil)
}
else {
completion(user: nil, error: NSError(domain: "ResponseError:Something wrong with data from [TSUser]registeruUser", code: -1, userInfo: nil))
}
}
case .Failure(let error):
completion(user: nil, error: error)
}
}
}
}

这是我的类(class)声明:

@objc class TSUser: NSObject, Mappable, NSCoding

我打算调用storeUserToCache(),但收到另一个错误:调用中缺少参数#1的参数

这是函数:

private func storeUserToCache() {
if let currentUser = TSUser.currentUser {
NSKeyedArchiver.archiveRootObject(currentUser, toFile: self.getUserPath())
}
}

有人对 Swift 编译器有什么想法吗?

最佳答案

Paulw11 是正确的。因为我使用的是static,所以self没有任何意义。低级错误。问题解决了。

关于ios - Alamofire: 'weak' 无法应用于非类类型错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34540260/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com