To get table data without loading to database, create the HHFWTable application, which uses framework methods:
Method name | Brief description |
initWithCredentials (_: host: environment: project: application: device:) | The method initializes the framework. |
auth (_: password:) | The method authenticates the user by login and password. |
table (_: transactionID: tableCallParams: handler:) | The method returns resource table data without loading to database. |
The HHFWTable application includes one screen, the UITextView text view, and the UIButton button:
Perform Table. Get table data without loading to database.
NOTE. When the application is initialized, authentication is executed, the button is not available. If the authentication is executed successfully, the button is available and the text box display the text "Authentication success".
To execute the example, click the Perform Table button. Clicking the button initializes a request to resource. The mobile platform server returns corresponding table data without loading to database.
Application code:
import UIKit
class ViewController: UIViewController {
//MARK: - Outlets
@IBOutlet weak var resultTextView: UITextView!
@IBOutlet weak var tableRequestButton: UIButton!
//MARK: - View life cycle
override func viewDidLoad() {
super.viewDidLoad()
self.deactivateButtons()
self.initializeFramework()
self.auth {
self.activateButtons()
self.resultTextView.text = "Authentication success"
}
}
//MARK: - Actions
@IBAction func tableRequestPressed(_ sender: UIButton) {
self.tableRequest { (jsonResult) in
self.resultTextView.text = String(format: "%@", jsonResult)
}
}
//MARK: - HHFW - Framework initialization
private func initializeFramework() {
let apiVersion: String = "v1"
let host: String = "http://testmasterfmp.fsight.cloud/"
let environment: String = "Leonid_environment"
let project: String = "Leonid_project"
let application: String = "app"
let device: String = (UIDevice.current.identifierForVendor?.uuidString)!
HHFWController.sharedInstance().initWithCredentials(
apiVersion,
host: host,
environment: environment,
project: project,
application: application,
device: device
)
}
//MARK: - HHFW - Authentication
private func auth(completion: @escaping ()->()) {
let username: String = "Leonid"
let password: String = "123123"
HHFWController.sharedInstance().auth(username, password: password){ (jsonResult) in
if let jsonDict = jsonResult as? NSDictionary,
let status = jsonDict["status"] as? String, status == "ok" {
print("Auth success")
completion()
} else {
print("Auth error")
}
}
}
//MARK: - HHFW - Table request
private func tableRequest(completion: @escaping (NSDictionary)->()) {
let resourceName = "study"
let tableCallParams = TableCallParams(defaultProperty: ())
HHFWController.sharedInstance().table(resourceName, transactionID: nil, tableCallParams: tableCallParams) { (jsonResult) in
if let jsonDict = jsonResult as? NSDictionary,
let status = jsonDict["status"] as? String, status == "ok" {
print("Table request success")
completion(jsonDict)
} else {
print("Table request error")
}
}
}
//MARK: - View methods
private func deactivateButtons() {
self.tableRequestButton.isEnabled = false
}
private func activateButtons() {
self.tableRequestButton.isEnabled = true
}
}
To get table data without loading to database, create the HHFWTableAsync application, which uses framework methods:
Method name | Brief description |
initWithCredentials (_: host: environment: project: application: device:) | The method initializes the framework |
auth (_: password:) | The method authenticates the user by login and password |
tableAsync (_: transactionID: tableCallParams: handler:) | The method asynchronously requests and returns resource table data without loading to database |
The HHFWTable application includes one screen, the UITextView text view, and the UIButton button:
Perform Table Async. Get table data without loading to database.
NOTE. When the application is initialized, authentication is executed, the button is not available. If authentication is successful, the button is available, and the text box displays "Authentication success".
To execute the example, click the Perform Table Async button. Clicking the button initializes an asynchronous request to resource. The mobile platform server returns corresponding table data without loading to database.
Application code:
import UIKit
class ViewController: UIViewController {
//MARK: - Outlets
@IBOutlet weak var resultTextView: UITextView!
@IBOutlet weak var tableRequestButton: UIButton!
//MARK: - View life cycle
override func viewDidLoad() {
super.viewDidLoad()
self.deactivateButtons()
self.initializeFramework()
self.auth {
self.activateButtons()
self.resultTextView.text = "Authentication success"
}
}
//MARK: - Actions
@IBAction func tableRequestPressed(_ sender: UIButton) {
self.tableRequest { (jsonResult) in
self.resultTextView.text = String(format: "%@", jsonResult)
}
}
//MARK: - HHFW - Framework initialization
private func initializeFramework() {
let apiVersion: String = "v1"
let host: String = "http://testmasterfmp.fsight.cloud/"
let environment: String = "DocumentationExampleEnv"
let project: String = "DocumentationExampleProj"
let application: String = "app"
let device: String = (UIDevice.current.identifierForVendor?.uuidString)!
HHFWController.sharedInstance().initWithCredentials(
apiVersion,
host: host,
environment: environment,
project: project,
application: application,
device: device
)
}
//MARK: - HHFW - Authentication
private func auth(completion: @escaping ()->()) {
let username: String = "test"
let password: String = "test123"
HHFWController.sharedInstance().auth(username, password: password){ (jsonResult) in
if let jsonDict = jsonResult as? NSDictionary,
let status = jsonDict["status"] as? String, status == "ok" {
print("Auth success")
completion()
} else {
print("Auth error")
}
}
}
//MARK: - HHFW - Table request
private func tableRequest(completion: @escaping (NSDictionary)->()) {
let resourceName = "FRUITS"
let tableCallParams = TableCallParams(defaultProperty: ())
HHFWController.sharedInstance().tableAsync(resourceName, transactionID: nil, tableCallParams: tableCallParams) { (jsonResult) in
if let jsonDict = jsonResult as? NSDictionary,
let status = jsonDict["status"] as? String, status == "ok" {
print("Table request success")
completion(jsonDict)
} else {
print("Table request error")
}
}
}
//MARK: - View methods
private func deactivateButtons() {
self.tableRequestButton.isEnabled = false
}
private func activateButtons() {
self.tableRequestButton.isEnabled = true
}
}
See also:
Examples of iOS Framework Use | Examples of Working with Resources