I have no idea whats wrong, there are no filenames to mess the case up on..
var nameArray = [String]()
var textArray = [String]()
var userArray = [String]()
var latArray = [String]()
var longArray = [String]()
var timeArray = [String]()
var locTextArray = [String]()
var refreshControl: UIRefreshControl!
var i = 1
@IBOutlet weak var tableView: UITableView!
@IBAction func addButton(sender: AnyObject) {
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
class Card: Mappable {
var locationText: String?
var latitude: String?
var longitude: String?
var titlee: String?
var text: String?
var attending: String?
var time: String?
required init?(_ map: Map) {
}
func mapping(map: Map) {
locationText <- map["location_text"]
titlee <- map["title"]
text <- map["description"]
attending <- map["attending"]
latitude <- map["latitude"]
longitude <- map["longitude"]
time <- map["time"]
}
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
func getData() {
let myURLString = "http://meetup.x10host.com/api/get_event.php?radius=15"
let myURL = NSURL(string: myURLString)!
var myCardsArray = [Card]()
let mySession = NSURLSession(configuration: NSURLSessionConfiguration.defaultSessionConfiguration())
let myDataTask = mySession.dataTaskWithURL(myURL) { (data, response, error) in
guard error == nil else {
let alertController = UIAlertController(title: "No Coection", message:
"Can't coect to database, perhaps tu on your WiFi?", preferredStyle: UIAlertControllerStyle.Alert)
alertController.addAction(UIAlertAction(title: "Okay", style: UIAlertActionStyle.Default,handler: nil))
self.presentViewController(alertController, animated: true, completion: nil)
retu
}
do {
let jsonData = try NSJSONSerialization.JSONObjectWithData(data!, options: NSJSONReadingOptions.AllowFragments)
for someCard in jsonData as! NSArray{
let card = Mapper<Card>().map(someCard)
myCardsArray.append(card!)
self.nameArray.append(card!.titlee!)
self.textArray.append(card!.text!)
self.userArray.append(card!.attending!)
self.latArray.append(card!.latitude!)
self.longArray.append(card!.longitude!)
self.timeArray.append(card!.time!)
self.locTextArray.append(card!.locationText!)
dispatch_async(dispatch_get_main_queue()) {
self.tableView.reloadData()
}
}
} catch {
print("There was an error")
}
}
myDataTask.resume()
print(mySession)
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
func numberOfSectionsInTableView(tableView: UITableView) -> Int
{
retu 1
}
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int
{
retu nameArray.count
}
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell
{
let cell : MainViewCell! = tableView.dequeueReusableCellWithIdentifier("MainCell") as! MainViewCell
cell.cellTitle.text = nameArray[indexPath.row]
cell.cellText.text = textArray[indexPath.row]
cell.userCount.text = userArray [indexPath.row]
cell.cellDate.text = timeArray [indexPath.row]
cell.cellAddress.text = locTextArray [indexPath.row]
retu cell as MainViewCell
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
if segue.identifier == "details" {
let destination = segue.destinationViewController as? MainViewDetails
let cell = sender as! MainViewCell
let selectedRow = tableView.indexPathForCell(cell)!.row
destination!.nameArrayy = nameArray[selectedRow]
destination!.textArrayy = textArray[selectedRow]
destination!.userArrayy = userArray[selectedRow]
destination!.lat = latArray[selectedRow]
destination!.long = longArray[selectedRow]
destination!.time = timeArray[selectedRow]
}
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
override func viewDidLoad() {
super.viewDidLoad()
getData()
self.tableView.delegate = self
self.tableView.dataSource = self
self.refreshControl = UIRefreshControl()
self.refreshControl.attributedTitle = NSAttributedString(string: "Refresh")
self.refreshControl.addTarget(self, action: "refresh:", forControlEvents: UIControlEvents.ValueChanged)
self.tableView.addSubview(self.refreshControl)
}
func refresh(sender:AnyObject)
{
self.tableView.reloadData()
getData()
self.refreshControl?.endRefreshing()
}
override func didReceiveMemoryWaing() {
super.didReceiveMemoryWaing()
}
}
