Ben bu linkte ki kütüphaneyi kullanıyorum.
**pod 'SQLClient', :git => 'https://github.com/martinrybak/SQLClient.git’**
Yukarıdaki gibi önce projene import et bu kütüphaneyi Xcode kapalı olsun.
Daha sonra Xcode aç projeni build/clean ettikten sonra
aşağıda bir örnek kod paylaşıyorum bir deneyebilirsin.
import Foundation
import UIKit
class deneme: UIViewController, SQLClientDelegate {
/**
* Required delegate method to receive error notifications
*
* @param error Error text
* @param code FreeTDS error code
* @param severity FreeTDS error severity
*/
func error(_ error: String!, code: Int32, severity: Int32) {
print(error)
if(!error.isEmpty){
let refreshAlert = UIAlertController(title: "", message: "", preferredStyle: UIAlertControllerStyle.alert)
refreshAlert.addAction(UIAlertAction(title: "", style: .default, handler: { (action: UIAlertAction!) in
//do something
}))
present(refreshAlert, animated: true, completion: nil)
}
}
let client = SQLClient.sharedInstance()
override func viewDidLoad() {
denemeFunc { (isResponse) in
// true ise buraya girer
}
}
func denemeFunc(_ completionHandler : @escaping ((_ isResponse : Bool) -> Void)) {
client?.delegate = self
client?.connect(macAddress+":"+portNoSon, username: username, password: password, database: databaseName) {
success in
if success {
self.client?.execute("SQL SORGUSU BURADA" ) {
results in
for table in results as! [[[String:AnyObject]]] {
for row in table {
for (columnName, value) in row {
print("\(columnName) = \(value)")
}
}
}
}
completionHandler(true)
self.client?.disconnect()
}else{
completionHandler(false)
}
}
}
}