我無法在swift中從函數返回對象的自定義數組。我總是收到[(custon object)] is not convertable to '()'
錯誤消息。我認爲我違反了一些迅速的協議。以下是我的代碼。請讓我知道我違反了。如何在swift中返回函數中的對象的自定義數組
import Foundation
class DataSet {
var settings:Settings!
var service:PostService!
var currentBrand:Brand!
init(){
self.settings = Settings()
self.service = PostService()
}
func loadComments(id:Int) -> [CommentsList]{
service.apiCallToGet(settings.getComments(id), {
(response) in
var commentsList = [CommentsList]()
if let data = response["data"] as? NSDictionary {
if let comments = data["comments"] as? NSArray{
for item in comments {
if let comment = item as? NSDictionary{
var rating = comment["rating"]! as Int
var name = comment["device"]!["username"]! as NSString
var text = comment["text"]! as NSString
var Obj_comment = CommentsList(rating: rating, name: name, text: text)
commentsList.append(Obj_comment)
}
}
}
}
return commentsList //This line shows error as : "[(CommentsList)] is not convertable to '()'"
})
}
}
謝謝jrturton。你救了我。非常感謝。 – Nuibb