如何显示对象的所有信息

时间:2016-02-22 03:56:06

标签: ios nsobject

func makeGetRequest(){           
    var url : String = "http://apiairline.sunkhoai.com/api-v2/get-airinfo?ver=2?iata=ALL&direction=ALL"
    var request : NSMutableURLRequest = NSMutableURLRequest ()
    request.URL = NSURL(string: url)
    request.HTTPMethod = "GET"

    NSURLConnection.sendAsynchronousRequest(request, queue: NSOperationQueue(), completionHandler:{ (response:NSURLResponse!, data: NSData!, error: NSError!) -> Void in
        var error: AutoreleasingUnsafeMutablePointer<NSError?> = nil
        let jsonResult: NSDictionary! = NSJSONSerialization.JSONObjectWithData(data, options:NSJSONReadingOptions.MutableContainers, error: error) as? NSDictionary

        var _names: NSMutableArray = NSMutableArray()
        if (jsonResult != nil) {
            // Success
            // println(jsonResult)
            let dataArray = jsonResult["airinfo_list"] as NSArray;

            var _names: NSMutableArray = NSMutableArray()
            for item :AnyObject in dataArray{
                let obj = item as NSDictionary
                _names.addObject(item)                                
                self.TableData = _names
                dispatch_async(dispatch_get_main_queue()) {
                    self.tableView.reloadData()
                }        
            }

        } else {
            // Failed
            println("Failed")
        }

    })
}

如何显示对象的所有信息

override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier("Cell", forIndexPath: indexPath) as UITableViewCell

如何显示对象的所有信息

if let airinfo_list = TableData[indexPath.row] as? NSDictionary{
    var ten = airinfo_list.valueForKey("AirNumberEx") as NSString
    cell.textLabel?.text = ten                           
}
return cell

1 个答案:

答案 0 :(得分:0)

如果您只是想在对象中显示所有内容,最简单的方法是{{1}}这会将对象中的所有内容转储,您可以将其写入控制台或进行警报,无论哪种方法都能为您提供字符串结果。

最终编辑:忽略我的答案。您的标签已更新,以正确反映您正在使用的语言。由于相似之处,我在您需要Objective-C时给出了JS答案。正确标记/解释您的帖子有助于社区了解您的需求。

最后的最终编辑:在浏览了SO之后,这可能是您需要的答案:Objective C Introspection/Reflection

相关问题