Json and UISearchBar Source Code
JSON Web Service with UISearchBar and UITableView Source Code,
Click Link Below to download source code
Click to Download
override func viewDidLoad() { super.viewDidLoad() var urlPath = "https://www.daydev.com/calendar.php?api_key=p24567739e33xcbnfg0" var jsonURL: NSURL = NSURL(string: urlPath) var URLrequest: NSURLRequest = NSURLRequest(URL: jsonURL) var response: AutoreleasingUnsafePointer<NSURLResponse?>=nil var jsonSource: NSData = NSURLConnection.sendSynchronousRequest(URLrequest, returningResponse: response, error:nil) let jsonObjects = NSJSONSerialization.JSONObjectWithData(jsonSource, options: NSJSONReadingOptions.MutableContainers, error: nil) as NSMutableArray var dataDict: NSDictionary for dataDict : AnyObject in jsonObjects { var title_data: NSString = dataDict.objectForKey("title") as NSString var date_data: NSString = dataDict.objectForKey("date") as NSString println("วันหยุดคือ:"+title_data+" ตรงกับวันที่:"+date_data+"") let dictionary = [thetitle: title_data, thedate: date_data] myObject.addObject(dictionary) } println(myObject.count) self.tableData.registerClass(UITableViewCell.self, forCellReuseIdentifier: "Cell") }
//Table func tableView(tableView: UITableView!, numberOfRowsInSection section: Int) -> Int{ return myObject.count } func tableView(tableView: UITableView!, cellForRowAtIndexPath indexPath: NSIndexPath!) -> UITableViewCell{ let tableCell: UITableViewCell = UITableViewCell(style: UITableViewCellStyle.Subtitle, reuseIdentifier: "Cell") var tmpDict: NSDictionary = myObject[indexPath.row] as NSDictionary let text: NSMutableString = tmpDict.objectForKeyedSubscript(thetitle) as NSMutableString let detail: NSMutableString = tmpDict.objectForKeyedSubscript(thedate) as NSMutableString tableCell.text=text tableCell.detailTextLabel.text = detail return tableCell }