Merge user info email/phone number authentication, Firebase firestore with swift - ios

Create a user with Username, email, and password. Then force the user to complete phone number verification before the account is created.
I am designing an app where we would like to make the user sign up by creating a username, password, supply their email address, and then complete phone number verification.
This picture represents the desired flow we would like our user to complete to register their account.
here are our View Controller files:
This is the code for the "Create Account" view, it creates a user in Firebase using email
import UIKit
class CreateAccountVC: UIViewController {
#IBOutlet weak var scrollView: UIScrollView!
#IBOutlet weak var usernameTextfield: UITextField!
#IBOutlet weak var passwordTextfield: UITextField!
#IBOutlet weak var emailTextfield: UITextField!
#IBOutlet weak var confirmPasswordTextfield: UITextField!
#IBOutlet weak var createAccountLbl: UILabel!
#IBOutlet weak var createAccountTextView: UILabel!
#IBOutlet weak var signupBtn: UIButton!
override func viewDidLoad() {
super.viewDidLoad()
self.hideKeyboardWhenTappedAround()
NotificationCenter.default.addObserver(self, selector: #selector(keyboardWillShow), name:UIResponder.keyboardWillShowNotification, object: nil)
NotificationCenter.default.addObserver(self, selector: #selector(keyboardWillHide), name:UIResponder.keyboardWillHideNotification, object: nil)
overrideUserInterfaceStyle = .light
}
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
signupBtn.clipsToBounds = true
signupBtn.layer.cornerRadius = 15
signupBtn.addButtonGradient(didType: true)
}
#objc func keyboardWillShow(notification:NSNotification){
let userInfo = notification.userInfo!
var keyboardFrame:CGRect = (userInfo[UIResponder.keyboardFrameBeginUserInfoKey] as! NSValue).cgRectValue
keyboardFrame = self.view.convert(keyboardFrame, from: nil)
var contentInset:UIEdgeInsets = self.scrollView.contentInset
contentInset.bottom = keyboardFrame.size.height
scrollView.contentInset = contentInset
}
#objc func keyboardWillHide(notification:NSNotification){
let contentInset:UIEdgeInsets = UIEdgeInsets.zero
scrollView.contentInset = contentInset
}
#IBAction func alreadyHaveAccountBtnPressed(_ sender: Any) {
// dismiss(animated: true, completion: nil)
// self.performSegue(withIdentifier: "TypePhoneNumberVC", sender: self)
}
#IBAction func signupBtnPressed(_ sender: Any) {
let username = usernameTextfield.text
let email = emailTextfield.text
let password = passwordTextfield.text
signupBtn.isHidden = true
AuthorizationService.instance.registerUser(username: username!, email: email!, password: password!) { (success, err) in
if success{
AuthorizationService.instance.loginUser(withEmail: email!, andPassword: password!) { (success, err) in
if err != nil{
return
}
self.performSegue(withIdentifier: "EnterNumberSegue", sender: self)
print("Sign-up successful")
}
}else{
let alertController = UIAlertController(title: "Error", message: err?.localizedDescription, preferredStyle: .alert)
let defaultAction = UIAlertAction(title: "OK", style: .cancel, handler: nil)
alertController.addAction(defaultAction)
self.present(alertController, animated: true, completion: nil)
self.signupBtn.isHidden = false
}
}
}
#IBAction func backBtnPressed(_ sender: Any) {
dismiss(animated: true, completion: nil)
}
}
These next two demonstrate the implementation of the Phone number verification
import UIKit
import Firebase
import FirebaseAuth
class EnterPhoneNumberVC: UIViewController, UITextFieldDelegate{
#IBOutlet weak var backButton: UIButton!
#IBOutlet weak var phoneNumberUITextField: UITextField!
#IBOutlet weak var getCodeButton: UIButton!
let userDefaults = UserDefaults.standard
override func viewDidLoad() {
super.viewDidLoad()
phoneNumberUITextField.delegate = self
let tap = UITapGestureRecognizer(target: self, action: #selector(handle))
view.addGestureRecognizer(tap)
overrideUserInterfaceStyle = .light
}
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
getCodeButton.clipsToBounds = true
getCodeButton.layer.cornerRadius = 15
getCodeButton.addButtonGradient(didType: true)
}
#objc func handle(tap: UITapGestureRecognizer){
view.endEditing(true)
}
#IBAction func backButtonPressed(_ sender: Any) {
dismiss(animated: true, completion: nil)
}
#IBAction func getCodeButtonPressed(_ sender: Any) {
guard let phoneNumber = phoneNumberUITextField.text else {return}
PhoneAuthProvider.provider().verifyPhoneNumber(phoneNumber, uiDelegate: nil) { (verificationID, error) in
if error == nil {
print(verificationID)
guard let verifyID = verificationID else {return}
self.userDefaults.set(verifyID, forKey:"verificationID")
self.userDefaults.synchronize()
self.performSegue(withIdentifier: "GetCodeSegue", sender: self)
} else {
print("unable to confirm the users phone number", error?.localizedDescription)
}
}
}
import UIKit
import Firebase
import FirebaseAuth
class PhoneNumberVerificationVC: UIViewController, UITextFieldDelegate {
#IBOutlet weak var verifyBtn: UIButton!
#IBOutlet weak var resendCodeBtn: UIButton!
#IBOutlet weak var otpCode: UITextField!
var verificationID: String?
let userDefaults = UserDefaults.standard
override func viewDidLoad() {
super.viewDidLoad()
overrideUserInterfaceStyle = .light
let tap = UITapGestureRecognizer(target: self, action: #selector(handle))
view.addGestureRecognizer(tap)
}
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
verifyBtn.clipsToBounds = true
verifyBtn.layer.cornerRadius = 15
verifyBtn.addButtonGradient(didType: true)
}
#objc func handle(tap: UITapGestureRecognizer){
view.endEditing(true)
}
#IBAction func backBtnPressed(_ sender: Any) {
dismiss(animated: true, completion: nil)
}
#IBAction func verifyBtnPressed(_ sender: Any) {
guard let optCode = otpCode.text else {return}
guard let verificationID = userDefaults.string(forKey: "verificationID") else {return}
let credential = PhoneAuthProvider.provider().credential(withVerificationID: verificationID, verificationCode: optCode)
Auth.auth().signInAndRetrieveData(with: credential) { (success, error) in
if error == nil {
print(success)
self.performSegue(withIdentifier: "VerifiedSegue", sender: self)
print("The user has successfully logged In and is verified!")
} else {
print("Error: Phone number and One time password does not match")
}
}
}

Related

Login page doesn't work fully it works when segue connected but doesn't check if user is registered or not

Login page doesn't really check for if user is stored in core data and will just go ahead with the segue. It should login only if user is registered in core data else will input error and to go register but register seems to work correctly tho I followed some guides online
I have attached the code please check and give me some suggestion to achieve my task
LoginVC
import UIKit
import CoreData
class LoginVC: UIViewController {
#IBOutlet weak var username: UITextField!
#IBOutlet weak var password: UITextField!
var credits = 200.0
var context = (UIApplication.shared.delegate as! AppDelegate).persistentContainer.viewContext
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view
fetchData()
}
#IBAction func login(_ sender: Any) {
for acc in userList {
if acc.username == username.text && acc.password == password.text {
currentUser = username.text!
try! context.save()
//performSegue(withIdentifier: "DisplayShop1", sender: nil)
let storyBoard : UIStoryboard = UIStoryboard(name: "Main", bundle: nil)
let next = storyBoard.instantiateViewController(identifier: "DisplayShop1") as! ListingShopVC
next.modalPresentationStyle = .fullScreen
self.present(next, animated: true, completion: nil)
}
else if username.text != acc.username || password.text != acc.password || password.text == "" || username.text == "" {
let alert = UIAlertController(title: "Alert", message: "Please enter the correct credentials", preferredStyle: .alert)
alert.addAction(UIAlertAction(title: "Dismiss", style: .default, handler: nil))
present(alert, animated: true, completion: nil)
}
}
}
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
if segue.identifier == "hellothere" {
let ve = segue.destination as! ListingShopVC
ve.creditsss = credits
}
}
func fetchData(){
userList = try! context.fetch(User.fetchRequest())
}
}
RegisterVC
import UIKit
import CoreData
class RegisterVC: UIViewController {
var context = (UIApplication.shared.delegate as! AppDelegate).persistentContainer.viewContext
var userList: String = ""
#IBOutlet weak var username: UITextField!
#IBOutlet weak var cpassword: UITextField!
#IBOutlet weak var password: UITextField!
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
}
#IBAction func register(_ sender: Any) {
if username.text != ""{
if password.text != "" {
if password.text == cpassword.text {
let newu = User(context: context)
newu.username = username.text
newu.password = password.text
newu.credit = 200.0
try! context.save()
self.navigationController?.popViewController(animated: true)
}
else {
let alert = UIAlertController(title: "Alert", message: "Please enter values correctly", preferredStyle: .alert)
alert.addAction(UIAlertAction(title: "Dismiss", style: .default, handler: nil))
present(alert, animated: true, completion: nil)*/
}
}
}
}

'StorageMetadata' has no member 'downloadURL'

So, I've gotten 2 more errors in my code which I've tried to solve for a while for my school project, but since I'm not used to programming in swift I haven't been able to solve it (I've taken code from a youtube tutorial). The first one is "Value of 'StorageMetaData' has no member 'downloadURL' (inside the func uploadImg). Then the other erros is "use of unresolved identifier 'imagePicker' (at the end of #IBAction func selectedImgPicker".
Here's my code:
class SignUpVC: UIViewController, UIImagePickerControllerDelegate, UINavigationControllerDelegate {
#IBOutlet weak var userImagePicker: UIImageView!
#IBOutlet weak var usernameField: UITextField!
#IBOutlet weak var signUpBtn: UIButton!
var userUid: String!
var emailField: String!
var passwordField: String!
var imagePicker: UIImagePickerController!
var imageSelected = false
var username: String!
override func viewDidLoad() {
super.viewDidLoad()
imagePicker.delegate = self as? UIImagePickerControllerDelegate & UINavigationControllerDelegate
imagePicker = UIImagePickerController()
imagePicker.allowsEditing = true
}
override func viewDidDisappear(_ animated: Bool) {
if let _ = KeychainWrapper.standard.string(forKey: "uid"){
performSegue(withIdentifier: "Message", sender: nil)
}
}
func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any]){
if let image = info[UIImagePickerControllerEditedImage] as? UIImage{
userImagePicker.image = image
imageSelected = true
} else {
print("image wasnt selected")
}
imagePicker.dismiss(animated: true, completion: nil)
}
func setUser(img: String){
let userData = ["username": username!, "userImg": img]
KeychainWrapper.standard.set(userUid, forKey: "uid")
let location = Database.database().reference().child("users").child(userUid)
location.setValue(userData)
dismiss(animated: true, completion: nil)
}
func uploadImg(){
if usernameField.text == nil {
signUpBtn.isEnabled = false
} else {
username = usernameField.text
signUpBtn.isEnabled = true
}
guard let img = userImagePicker.image, imageSelected == true else{
print("image needs to be selected")
return
}
if let imgData = UIImageJPEGRepresentation(img, 0.2){
let imgUid = NSUUID().uuidString
let metadata = StorageMetadata()
metadata.contentType = "image/jpeg"
Storage.storage().reference().putData(imgData, metadata: metadata){
(metadata, error) in
if error != nil{
print("did not upload image")
}else{
print("uploaded")
let downloadURL = metadata?.downloadURL()?.absoluteString
if let url = downloadURL{
self.setUser(img: url)
}
}
}
}
}
#IBAction func createAccount(_ sender: AnyObject){
Auth.auth().createUser(withEmail: emailField, password: passwordField, completion: {
(user, error) in
if error != nil {
print("Cant create user")
} else {
if let user = user {
self.userUid = user.user.uid
}
}
self.uploadImg()
})
}
#IBAction func selectedImgPicker (_ sender: AnyObject){
present(imagePicker, animated: true, completion: nil)
}
#IBAction func cancel (_ sender: AnyObject){
dismiss(animated: true, completion: nil)
}
}

Use of local variable 'displayAlert' before its declaration

I have called function and It isn't still displaying the code right I have been receiving and error Use of local variable 'displayAlert' before its declaration
import UIKit
import FirebaseAuth
class ViewController: UIViewController {
// I have also switched the #IBAction to function so the code actually run better any suggestions to fix this
#IBOutlet weak var dropoffLabel: UILabel!
#IBOutlet weak var pickupLabel: UILabel!
#IBOutlet weak var passwordTextField: UITextField!
#IBOutlet weak var emailTextfield: UITextField!
#IBOutlet weak var pickupDropoffSwitch: UISwitch!
#IBOutlet weak var buttomButton: UIButton!
#IBOutlet weak var topButton: UIButton!
var signUpMode = true
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
}
#IBAction func topTapped(_ sender: Any) {
if emailTextfield.text == "" || passwordTextField.text == "" {
code error coming from here ----> displayAlert(title: "Missing Information", message: "You must provide both a email and password")
} else {
if let email = emailTextfield.text {
if let password = passwordTextField.text {
if signUpMode {
// SIGN UP
Auth.auth().createUser(withEmail: email, password: password, completion: { (user, error) in
if error != nil {
displayAlert(title: "Error", message: error!.localizedDescription)
} else {
print("Sign Up Success")
}
})
} else {
// LOG IN
Auth.auth().signIn(withEmail: email, password: password, completion: { (user, error) in
if error != nil {
displayAlert(title: "Error", message: error!.localizedDescription)
} else {
print("Sign Up Success")
}
})
}
}
}
}
------> I believe if I am doing it correctly called the function here func displayAlert(title:String, message:String) {
let alertController = UIAlertController(title: title, message: message, preferredStyle: .alert)
alertController.addAction(UIAlertAction(title: "OK", style: .default, handler: nil))
self.present(alertController, animated: true, completion: nil)
}
//there is no other issue besides the code not understanding the the function I have labeled
//Also I have ran the code before and the alert would pop up but now it is not allowing the
func buttomTapped(_ sender: Any) {
if signUpMode {
topButton.setTitle("Log In", for: .normal)
buttomButton.setTitle("Switch to Sign Up", for: .normal)
pickupLabel.isHidden = true
dropoffLabel.isHidden = true
pickupDropoffSwitch.isHidden = true
signUpMode = false
} else {
topButton.setTitle("Sign Up", for: .normal)
buttomButton.setTitle("Switch to Log In", for: .normal)
pickupLabel.isHidden = false
dropoffLabel.isHidden = false
pickupDropoffSwitch.isHidden = false
signUpMode = true
}
}
}
}
You have incorrectly defined your displayAlert func inside the topTapped func.
You need to move it outside so it is on the class level
#IBAction func topTapped(_ sender: Any) {
//code here
}
func displayAlert(title:String, message:String) {
//
}

Segue to next view controller after successful sign up

I've searched and searched and searched but not found a solution. The sign up works but will not segue to the next view controller. Heres my code:
import UIKit
import Parse
import Bolts
class SignUpVC: UIViewController, UIImagePickerControllerDelegate, UINavigationControllerDelegate {
#IBOutlet weak var profilePictureIV: UIImageView!
#IBOutlet weak var firstNameTF: UITextField!
#IBOutlet weak var lastNameTF: UITextField!
#IBOutlet weak var newUsernameTF: UITextField!
#IBOutlet weak var newPasswordTF: UITextField!
#IBOutlet weak var emailTF: UITextField!
#IBOutlet weak var phoneNumberTF: UITextField!
#IBAction func setProfilePicture(sender: AnyObject) {
let myPickerController = UIImagePickerController()
myPickerController.delegate = self
myPickerController.sourceType = UIImagePickerControllerSourceType.PhotoLibrary
self.presentViewController(myPickerController, animated: true, completion: nil)
}
#IBAction func signUpButton(sender: AnyObject) {
let spinner: UIActivityIndicatorView = UIActivityIndicatorView(frame: CGRectMake(0, 0, 150, 150)) as UIActivityIndicatorView
if firstNameTF.text != "" && lastNameTF.text != "" && newUsernameTF.text != "" && newPasswordTF.text != "" && emailTF.text != "" && phoneNumberTF.text != "" {
let newUser = PFUser()
if let profilePictureImage = profilePictureIV?.image {
let profilePicture = UIImageJPEGRepresentation(profilePictureImage, 1)!
let profilePictureImageFile = PFFile(data: profilePicture)
newUser["profilePicture"] = profilePictureImageFile
}
newUser["firstName"] = firstNameTF.text
newUser["lastName"] = lastNameTF.text
newUser.username = newUsernameTF.text
newUser.password = newPasswordTF.text
newUser.email = emailTF.text
newUser["phoneNumber"] = phoneNumberTF.text
newUser.signUpInBackgroundWithBlock {
(succeeded: Bool, error: NSError?) -> Void in
if let error = error {
spinner.startAnimating()
self.alert("Opps", textMessage: (error.localizedDescription))
} else {
spinner.startAnimating()
self.alert("Congratualtion!", textMessage: "Success, your account has been created.")
self.performSegueWithIdentifier("showMessages", sender: self)
}
}
} else {
alert("Hmm...", textMessage: "If you want an account, please fill in the blanks.")
}
}
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
override func viewWillAppear(animated: Bool) {
self.navigationController!.navigationBar.hidden = false
}
func imagePickerController(picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : AnyObject]) {
profilePictureIV.image = info[UIImagePickerControllerOriginalImage] as? UIImage
self.dismissViewControllerAnimated(true, completion: nil)
}
func alert(textTitle: String, textMessage: String) {
let alertController = UIAlertController(title: textTitle, message: textMessage, preferredStyle: .Alert)
alertController.addAction(UIAlertAction(title: "OK", style: .Default, handler: nil))
self.presentViewController(alertController, animated: true, completion: nil)
}
/*
// MARK: - Navigation
// In a storyboard-based application, you will often want to do a little preparation before navigation
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
// Get the new view controller using segue.destinationViewController.
// Pass the selected object to the new view controller.
}
*/
}
If i play the self.performSegueWithIdentifier("showMessages", sender: self) line anywhere else then when i run the program and press the signup button it will directly go to in the messages view controller without any signup required.
as Paulw11 said , Try to remove alert message :-
if let error = error {
spinner.startAnimating()
self.alert("Opps", textMessage: (error.localizedDescription))
} else {
spinner.startAnimating()
self.performSegueWithIdentifier("showMessages", sender: self)
}
or You can call the handler in your code.
if let error = error {
spinner.startAnimating()
self.alert("Opps", textMessage: (error.localizedDescription))
} else {
spinner.startAnimating()
var alert = UIAlertController(title: "Welcome", message: "Login", preferredStyle: UIAlertControllerStyle.Alert)
alert.addAction(UIAlertAction(title:"OK", style: .Default, handler: { action in self.performSegueWithIdentifier("showMessages", sender: self) }
}
You can not pass self as a argument in side the block.
so create a method to call a segue
#IBAction func signUpButton(sender: AnyObject) {
let spinner: UIActivityIndicatorView = UIActivityIndicatorView(frame: CGRectMake(0, 0, 150, 150)) as UIActivityIndicatorView
if firstNameTF.text != "" && lastNameTF.text != "" && newUsernameTF.text != "" && newPasswordTF.text != "" && emailTF.text != "" && phoneNumberTF.text != "" {
let newUser = PFUser()
if let profilePictureImage = profilePictureIV?.image {
let profilePicture = UIImageJPEGRepresentation(profilePictureImage, 1)!
let profilePictureImageFile = PFFile(data: profilePicture)
newUser["profilePicture"] = profilePictureImageFile
}
newUser["firstName"] = firstNameTF.text
newUser["lastName"] = lastNameTF.text
newUser.username = newUsernameTF.text
newUser.password = newPasswordTF.text
newUser.email = emailTF.text
newUser["phoneNumber"] = phoneNumberTF.text
newUser.signUpInBackgroundWithBlock {
(succeeded: Bool, error: NSError?) -> Void in
if let error = error {
spinner.startAnimating()
self.alert("Opps", textMessage: (error.localizedDescription))
} else {
spinner.startAnimating()
self.alert("Congratualtion!", textMessage: "Success, your account has been created.")
callSegue()
}
}
} else {
alert("Hmm...", textMessage: "If you want an account, please fill in the blanks.")
}
}
func callSegue()
{
self.performSegueWithIdentifier("showMessages", sender: self)
}

Cancel Segue and show alert - Xcode

I got the tutorial from this site: http://jamesleist.com/ios-swift-tutorial-stop-segue-show-alert-text-box-empty/
This is my current code. It's just not working, which causes the app to crash because if any of the fields are empty, the next ViewController crashes.
import Foundation
import UIKit
import Darwin
class View3on3 : UIViewController, UITextFieldDelegate {
#IBOutlet weak var APTeams: UITextField!
#IBOutlet weak var APRounds: UITextField!
#IBOutlet weak var APBreakers: UITextField!
var AP1: String = String()
var AP2: String = String()
var AP3: String = String()
override func viewDidLoad()
{
super.viewDidLoad()
initializeTextFields()
}
func initializeTextFields()
{
APTeams.delegate = self
APTeams.keyboardType = UIKeyboardType.NumberPad
APRounds.delegate = self
APRounds.keyboardType = UIKeyboardType.NumberPad
APBreakers.delegate = self
APBreakers.keyboardType = UIKeyboardType.NumberPad
}
#IBAction func userTappedBackground(sender: AnyObject)
{
view.endEditing(true)
}
override func shouldPerformSegueWithIdentifier(identifier: String!, sender: AnyObject!) -> Bool {
if identifier == "segueTest" {
if (APTeams.text!.isEmpty) {
let alert = UIAlertView()
alert.title = "No Text"
alert.message = "Please Enter Text In The Box"
alert.addButtonWithTitle("Ok")
alert.show()
return false
}
else {
return true
}
}
// by default, transition
return true
}
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
if (segue.identifier == "segueTest"){
var passs = segue.destinationViewController as! View3on3Results
passs.AP1 = APTeams.text!
passs.AP2 = APRounds.text!
passs.AP3 = APBreakers.text!
}
}
}
I tried looking at other questions on SO, but the solutions all threw errors. I think this is due to Swift updating to 2.0. I could be wrong- very new to this.
I hope it may be because of AlertView. In swift 2.0 UIAlertView is replaced by UIAlertController:
let alertController: UIAlertController = UIAlertController(title: "Hello", message: "Are you sure?", preferredStyle: UIAlertControllerStyle.Alert)
let okAction = UIAlertAction(title: "Yes", style: UIAlertActionStyle.Default, handler: nil)
alertController.addAction(okAction)
presentViewController(alertController, animated: true, completion: nil)
Replace your UIAlertView with UIAlertViewController using the above code.
Edited:
Also make the IBOutlet optionals:
#IBOutlet weak var APTeams: UITextField?
#IBOutlet weak var APRounds: UITextField?
#IBOutlet weak var APBreakers: UITextField?
I think you should call segue manually using performSegueWithIdentifier
if the textfield is not empty and if it is then show alert
Your code might look like [may be on button click when you are submitting your data or trying to segue Or put this code inside viewDidLoad after initializeTextFields()]
if(APTeams.text!.isEmpty){
// your code for showing alert. You can use UIAlertController if UIAlertView is not working.
}
else
{
self.performSegueWithIdentifier("segueTest",sender: View3on3Results.self)
}
And you dont need shouldPerformSegueWithIdentifier if I'm not wrong.
Solved! This was the code that worked. Thank you to #SohilRMemon and #FrequencyMatched for helping me put this together.
Code here:
import Foundation
import UIKit
import Darwin
class View3on3 : UIViewController, UITextFieldDelegate {
#IBOutlet weak var APTeams: UITextField!
#IBOutlet weak var APRounds: UITextField!
#IBOutlet weak var APBreakers: UITextField!
var AP1: String = String()
var AP2: String = String()
var AP3: String = String()
override func viewDidLoad()
{
super.viewDidLoad()
initializeTextFields()
}
func initializeTextFields()
{
APTeams.delegate = self
APTeams.keyboardType = UIKeyboardType.NumberPad
APRounds.delegate = self
APRounds.keyboardType = UIKeyboardType.NumberPad
APBreakers.delegate = self
APBreakers.keyboardType = UIKeyboardType.NumberPad
}
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
if (APTeams.text!.isEmpty || APRounds.text!.isEmpty || APBreakers.text!.isEmpty)
{
let alertController: UIAlertController = UIAlertController(title: "Hello", message: "Are you sure?", preferredStyle: UIAlertControllerStyle.Alert)
let okAction = UIAlertAction(title: "Yes", style: UIAlertActionStyle.Default, handler: nil)
alertController.addAction(okAction)
presentViewController(alertController, animated: true, completion: nil)
}
else
{
let DestViewController : View3on3Results = segue.destinationViewController as! View3on3Results
DestViewController.AP1 = APTeams.text!
DestViewController.AP2 = APRounds.text!
DestViewController.AP3 = APBreakers.text!
//self.performSegueWithIdentifier("segueTest",sender: View3on3Results.self)//
}
}
}

Resources