0
Web APIからアーティスト情報を取得し、返されたデータで新しいArtistクラスを作成しようとしていますが、返されたデータにクラス属性を設定できません。ここに私のコードがあるはプロパティ....に割り当てることができません。setter in accesible swift 3
輸入財団 クラスの収録曲 {
static var trackService:TrackService?
static func getArtistFromService()-> Artist
{
// construct the complete URL endpoint ot be called
//let searchURL = "https://\(siteURL)/?s=\(searchTerm)"
var searchedartist : Artist
let searchURL = "http://ws.audioscrobbler.com/2.0/?method=artist.gettoptracks&artist=drake&api_key=d932ba18a79b1739a4d9ba02c63bdb61&format=json"
// degugging - can test in browser if call is failing
print ("Web Service call = \(searchURL)")
// create the Web Service object that will make the call - initialiser
trackService = TrackService(searchURL)
// create an operation queue - to allow the web service to be called on a secondary thread...
let operationQ = OperationQueue()
//... will only allow one task at a time in queue...
operationQ.maxConcurrentOperationCount = 1
//...queue that web service object as the operation object to be run on this thread
operationQ.addOperation(trackService!)
//... wait for the operation to complete [Synchronous] - better to use delegation, for [Asynchronous]
operationQ.waitUntilAllOperationsAreFinished()
// clear the current list of movies
// get the raw JSON back from the completed service call [complete dataset]
let returnedJSON = trackService!.jsonFromResponse
let artist = returnedJSON?["artist"] as! String
let bio = returnedJSON?["bio"] as! String
searchedartist.name = artist
searchedartist.bio = bio
// return the main list of Movie objects to caller (UI)
return searchedartist
}
// for debugging - displays some details of the Movies currently in the main list...
} //クラス宣言
クラスのアーティスト { プライベート(セット)VAR名の最後:文字列 プライベート(セット)var bio:String
init?(_ n:String, _ b:String)
{
name = n
bio = b
}
convenience init(_ JSONObject:[String:String])
{
let name = JSONObject["name"]!
let bio = JSONObject["bio"]!
self.init(name, bio)!
}
}
TrackServiceとは何ですか?適切に表示されるようにコードを少しフォーマットしてください – Ocunidee