1
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")
        }

    })
}

how do I display all the information of an object

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

how do I display all the information of an object

if let airinfo_list = TableData[indexPath.row] as? NSDictionary{
    var ten = airinfo_list.valueForKey("AirNumberEx") as NSString
    cell.textLabel?.text = ten                           
}
return cell
Peyman Mohamadpour
  • 17,954
  • 24
  • 89
  • 100

1 Answers1

0

If you just want to show everything in the object, the easiest method is JSON.stringify(object); This will dump everything in the object, you can write it to the console or do an alert, either way that method gives you a string result.

Final Edit: Disregard my answers. Your tags have been updated to properly reflect what language you are working in. Due to similarities, I was giving JS answers when you needed Objective-C. Properly tagging / explaining your post helps the community know what you want.

Final Final edit: After looking around on SO, here is probably the answer you need: Objective C Introspection/Reflection

Community
  • 1
  • 1
Munsterlander
  • 1,356
  • 1
  • 16
  • 29
  • Updated answer but I am uncertain what your object name is or where you want it. I assume it is the obj variable or are you wanting the cell variable? If so, place the above after your for loop and it will dump the contents of that variable. – Munsterlander Feb 22 '16 at 04:10
  • thank you but I'm still not sure where to put it help me fix to code – Tống Văn Tuyền Feb 22 '16 at 04:20
  • What is your object? You have posted 3 functions that all return different things. I will update the answer with your first function. – Munsterlander Feb 22 '16 at 04:25
  • 1
    request the post should not have to fix it. I need to correct in this function func override 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      } – Tống Văn Tuyền Feb 22 '16 at 04:36
  • I need the 3rd function – Tống Văn Tuyền Feb 22 '16 at 04:50
  • I have removed my code due to updated tags as explained. – Munsterlander Feb 22 '16 at 17:06
  • You might want to look at this: http://stackoverflow.com/questions/289241/how-to-dump-data-stored-in-objective-c-object-nsarray-or-nsdictionary or the one I posted above. – Munsterlander Feb 23 '16 at 02:24