gpt4 book ai didi

ios - 无法将类型 '(Bool, NSError!) -> Void' 的值转换为预期的参数类型 'ACAccountStoreRequestAccessCompletionHandler!'

转载 作者:搜寻专家 更新时间:2023-10-31 19:29:33 25 4
gpt4 key购买 nike

自从在 Xcode 8 (Beta 1) 和 Swift 3 上升级后,我在这一行中遇到错误:

account.requestAccessToAccounts(with: accountType, options: nil, completion: {(success: Bool, error: NSError!) -> Void in

它说:

Cannot convert value of type '(Bool, NSError!) -> Void' to expected argument type 'ACAccountStoreRequestAccessCompletionHandler!'

在那行之前,我定义了“account”和“accountType”:

let account = ACAccountStore()
let accountType = account.accountType(
withAccountTypeIdentifier: ACAccountTypeIdentifierTwitter)

这是我的(使用 Xcode 7 和 Swift 2 工作)代码:

func getTimeline() {

//https://api.twitter.com/1.1/statuses/user_timeline.json?screen_name=twitterapi&count=2
let account = ACAccountStore()
let accountType = account.accountType(
withAccountTypeIdentifier: ACAccountTypeIdentifierTwitter)

account.requestAccessToAccounts(with: accountType, options: nil,
completion: {(success: Bool, error: NSError!) -> Void in

if success {
let arrayOfAccounts =
account.accounts(with: accountType)

if arrayOfAccounts.count > 0 {
let twitterAccount = arrayOfAccounts.last as! ACAccount

let requestURL = URL(string:
"https://api.twitter.com/1.1/statuses/user_timeline.json")

let parameters = ["screen_name": self.userName!,
"count" : "20"]

let postRequest = SLRequest(forServiceType:
SLServiceTypeTwitter,
requestMethod: SLRequestMethod.GET,
url: requestURL,
parameters: parameters)

postRequest.account = twitterAccount

postRequest.perform(
handler: {(responseData: Data!,
urlResponse: HTTPURLResponse!,
error: NSError!) -> Void in

if error != nil {

Crashlytics.sharedInstance().recordError(error)

}
do {
self.dataSource = try JSONSerialization.jsonObject(with: responseData, options: JSONSerialization.ReadingOptions.mutableLeaves) as! [AnyObject]

if self.dataSource.count != 0 {
DispatchQueue.main.async {
self.tableView.reloadData()
}
}
} catch {
print("catching")
}
})
}
} else {
print("Failed to access account")
}
})

}

最佳答案

您应该按如下方式更新您的代码:

    account.requestAccessToAccounts(with: accountType, options: [:]) {
(success: Bool, error: Error?) -> Void in
// blah blah: the rest of the code
}

此版本适用于Xcode 8 GM Swift3(普通版)

关于ios - 无法将类型 '(Bool, NSError!) -> Void' 的值转换为预期的参数类型 'ACAccountStoreRequestAccessCompletionHandler!',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38438418/

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