엑스 코드 8 (베타 1)와 스위프트 3 업그레이드 이후이 줄에 오류가 있습니다'(Bool, NSError!) -> Void'유형의 값을 예상 인수 유형 'ACAccountStoreRequestAccessCompletionHandler!'로 변환 할 수 없습니다.
account.requestAccessToAccounts(with: accountType, options: nil, completion: {(success: Bool, error: NSError!) -> Void in
은 말한다 :
유형의 값을 변환 할 수 없습니다 '(BOOL, NSError!) -> 예상되는 인수 유형 'Void'에 'ACAccountStoreRequestAccessCompletionHandler!'
는 라인 전에, 나는 "계정"과 "ACCOUNTTYPE을"정의 :
let account = ACAccountStore()
let accountType = account.accountType(
withAccountTypeIdentifier: ACAccountTypeIdentifierTwitter)
이 내 코드 (Xcode를 7 스위프트 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")
}
})
}
은'error' 매개 변수는 대신 옵션 암시 적으로 풀어의 옵션으로 변경되었다. 'NSError? '로 변경하거나 어쨌든 불필요하므로 명시 적 유형을 제거하십시오. – dan
@dan 감사합니다! 대답으로 추가하십시오 :) – Devhess
제 경우에는 오류로 변경했을 때 작동합니까? . 어쨌든 당신의 질문은 나를 도왔습니다 :) – Mariam