So I have built my single view application in swift and Xcode. All my code is in one file, the main ViewController.swift to make things easier as the codes get bigger I have started to move the methods to a separate swift file to keep things organise - ClipManager.swift.
I have 3 methods which all use the notifyUser method which calls UIAlertController.
So I have moved this method to the same file, ClipManager.swift but now my Alerts are not showing when these methods are called in the current ViewController - ViewController.swiftas the methods are in a separate file.
Firstly my Method that uses UIAlert
////Located in ClipManager.swift
class ClipManager: UIViewController {
func notifyUser(title: String, message: String) -> Void
{
let alert = UIAlertController(title: title,
message: message,
preferredStyle: UIAlertControllerStyle.Alert)
let cancelAction = UIAlertAction(title: "OK",
style: .Cancel, handler: nil)
alert.addAction(cancelAction)
self.presentViewController(alert, animated: true,
completion: nil)
}}
The call of my Method from ViewController.swift
class ViewController: UIViewController {
///// In ViewController.swift (where I want the Alert to show)
let SavedRecord = MyClipManager.SaveMethod(publicDatabase!, myRecord: record)
}
The code for SaveMethod located in ClipManager.swift
func SaveMethod(publicDatabase: CKDatabase, myRecord:CKRecord ) -> CKRecord {
publicDatabase.saveRecord(myRecord, completionHandler:
({returnRecord, error in
if let err = error {
//// **** Notify called here *****
self.notifyUser("Save Error", message:
err.localizedDescription)
} else {
dispatch_async(dispatch_get_main_queue()) {
self.notifyUser("Success",
message: "Record saved successfully")
}
}
}))
return myRecord
}
I'm guessing my Alerts are not showing because they are actually being triggered on ClipManager.swift which isn't in view.
What are my options here, Move NotifyUser back to ViewController.swift and create and object of this in ClipManager.swift to call it in my methods located there?
Or is there a way to pass these Alerts to the shown view?