2016-07-18 2 views
3

엑스 코드 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") 
               } 
    }) 

} 
+2

은'error' 매개 변수는 대신 옵션 암시 적으로 풀어의 옵션으로 변경되었다. 'NSError? '로 변경하거나 어쨌든 불필요하므로 명시 적 유형을 제거하십시오. – dan

+1

@dan 감사합니다! 대답으로 추가하십시오 :) – Devhess

+0

제 경우에는 오류로 변경했을 때 작동합니까? . 어쨌든 당신의 질문은 나를 도왔습니다 :) – Mariam

답변

2

당신이해야 다음과 같이 코드를 업데이트하십시오.

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

이 버전은 Xco 8 GM Swift3 (일반 버전)

1

xcode 8.2와 swift 3에서이 방법을 확인했습니다. Bool과 NSError를 제거하면 성공과 오류를 알릴 수 있으며 okey가됩니다.

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

내가 당신을 도울 것입니다 희망, 행운을 빌어 요 :)

관련 문제