Swift and MySQL

Hello,

I am trying to create an app that will be communicating with Mysql Database, and I understand that I have to have an extra layer, such as as PHP, to achieve this. I already created the tables in the Database and the PHP files to interact with the Database. I have also created the interface in xcode, which includes textfields, buttons, etc. For now, if I were to click a button, say load, and want to grab a record off of the Database and display it on a label field, how do I go about this? There are some articles out there but are written using Objective-C but they are a bit confusing.

I thought about using SQLite but how am I going to keep the records updated? This Database contains records that are continuously changing, so I presume this won't work.

Any help would be appreciated!

Thank you!

I tend to use a lot of the built in features in Swift, and combine them with "SwiftyJSON" library for handling the data once received. Some of the basic source code I use is:


         let urlPath: String = "http:// your network address here"
        var url: NSURL = NSURL(string: urlPath)!
        var request1: NSMutableURLRequest = NSMutableURLRequest(URL: url)
        request1.HTTPMethod = "POST"
        var stringPost="userID=\(user.id)"
        let data = stringPost.dataUsingEncoding(NSUTF8StringEncoding)
        request1.timeoutInterval = 60
        request1.HTTPBody=data
        request1.HTTPShouldHandleCookies=false
        let queue:NSOperationQueue = NSOperationQueue()
        NSURLConnection.sendAsynchronousRequest(request1, queue: NSOperationQueue.mainQueue(), completionHandler:{ (response: NSURLResponse!, data: NSData!, error: NSError!) -> Void in
            var err: NSError?
            if (err != nil) {
                //IF IT ERRORS--DO THIS
                println("Error:\(err)")
            } else {
               //IF YOU GET RESULTS DO THIS:
                println("Data: \(data)")
                var datastring = NSString(data: data, encoding: NSUTF8StringEncoding)
                println("Datastring: \(datastring)")\\
            }



Also--you will get a lot of help over at StackOverflow, pretty much any question have has probably already been answered by people with way more knowledge than I have. Good luck!

Swift and MySQL
 
 
Q