그래서 최근 Swift 3/XCode 8로 업데이트되었고 일부 코드는 건초 선으로 바뀌 었습니다. 나는 약간의 구문 변경이 있었지만이 하나의 권리를 얻을 수없는 것으로 보았습니다. "결합 조건에 대한 초기화하지 '모든 사람이 할 수있는 옵션 유형이 있어야합니다. 말한다 문"을 경우하는하자 "JSON 구문 분석 및 옵션 선택 3
func forLoadStats(completion: (AnyObject?, NSError?) -> Void)
{
var clientError: NSError?
let idString = api.getUserID()
let client = TWTRAPIClient()
let request = client.urlRequest(withMethod: "GET", url: "https://api.twitter.com/1.1/users/show.json", parameters: ["user_id" : 27446437], error: &clientError)
client.sendTwitterRequest(request)
{ (response, data, connectionError) in
if (connectionError == nil)
{
do {
if let json: Any = try? JSONSerialization.jsonObject(with: data!, options: .allowFragments) as? [AnyObject]
{
if let json = json, let immage = json?["profile_image_url_https"] as? String
{
//Make ProfilePic edges round
self.profPic.layer.cornerRadius = 42
self.profPic.clipsToBounds = true
//let immage = image["profile_image_url_https"] as String
let _vImageUrl = immage.replacingOccurrences(of: "_normal", with: "")
let urlProfilePic = NSURL(string: _vImageUrl)
let urlPP = NSData(contentsOf: urlProfilePic! as URL)
self.profPic.image = UIImage(data: urlPP! as Data)
let ScrName = json["screen_name"] as! String
self.scrNameLabel.text = "@\(ScrName)"
//Populate Followers Label.text
let flwrVar = json["followers_count"] as! Int
self.followerLbl.text = "\(flwrVar)"
//Populate Following Label.text
let flwngVar = json["friends_count"] as! Int
self.followingLbl.text = "\(flwngVar)"
//Populate Bio
let bio = json["description"] as! String
self.bioLabel.text = "\(bio)"
//created at date
let accountAge = json["created_at"] as! String
self.createdLbl.text = "\(accountAge)"
let tweetCount = json["statuses_count"] as! Int
self.tweetCount.text = "\(tweetCount)"
let likes = json["favourites_count"] as! Int
self.likesCount.text = "\(likes)"
let lists = json["listed_count"] as! Int
self.listedCount.text = "\(lists)"
}
}
}
catch let error
{
print(error)
}
}
}
}
내가 두 번째에 오류가 : 나는 트위터에 요청을하고 다시 JSON을 얻을 이는 이유를 설명?
이 줄에서 오류가 발생하는 것처럼 보입니다. 'if let json : Any = try?'... 또한 두 번째'if let' 행은'let json = json, let immage = json? '이 나에게 보이는 것처럼 보입니다. 그것은 잘못된 IF 비교이므로 그 사람들을보고보십시오 – KSigWyatt
@KSigWyatt하지만 정확히 무엇이 될 수 있습니다. 지금은 아무 것도 생각할 수 없습니다. –
'Any '에 주석을 달고 실제로'[String : Any]'인'[AnyObject]'에 캐스트하는 목적은 무엇입니까 ??? – vadian