error message with IBAction - swift

import UIKit
import Firebase
class ViewController: UIViewController {
#IBOutlet weak var emailField: UITextField!
#IBOutlet weak var passwordField: UITextField!
#IBOutlet weak var emailkeyboard: UITextField!
#IBOutlet weak var passwordkeyboard: UITextField!
#IBOutlet weak var myaccountButton: UIButton!
#IBOutlet weak var welcomeLabel: UILabel!
override func viewDidLoad() {
super.viewDidLoad()
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
//Built in method
override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?) {
self.view.endEditing(true)
}
#IBAction func buttonPressed(sender: UIButton) {
self.emailkeyboard.resignFirstResponder()
self.passwordkeyboard.resignFirstResponder()
}
#IBAction func myaccountbutton(sender: AnyObject) {
FIRAuth.auth()?.signInWithEmail(self.emailField.text!, password: self.passwordField.text!, completion: { (user,error) in
}
#IBAction func createaccountButton(sender: AnyObject) {
FIRAuth.auth()?.createUserWithEmail(emailField.text!, password: passwordField.text!) { (user, error) in
if error == nil {
print("User Created")
if (FIRAuth.auth()?.currentUser) != nil
{
self.myaccountButton.alpha = 1.0
}
else
{
self.myaccountButton.alpha = 0.0
self.welcomeLabel.text = ""
}
}
}
}
}
}
I cant figure out where to put the ) I asked before but i am still stuck. Sorry guys for asking again.
I am not sure if theres an error in the code above or with the IBAction itself so I have posted all of the code maybe that will help find the problem.

The signInWithEmail() function call is missing its ending parentheses, as well as an actual closure for the closure argument.

Related

Add button doesn't add text to UITextView in swift

I'm testing the my add button in the view controller file. It should go to validateName function in my model file and which returns true and then enables my addButton. But when I click on "Add" it doesn't change the text of the UITextView.
In viewcontroller.swift:
import UIKit
class ViewController: UIViewController,UITextFieldDelegate{
#IBOutlet weak var nameInputText: UITextField!
#IBOutlet weak var usernameInputText: UITextField!
#IBOutlet weak var passwordInputText: UITextField!
#IBOutlet weak var phoneInputText: UITextField!
#IBOutlet weak var emailInputText: UITextField!
#IBOutlet weak var addButton: UIButton!
#IBOutlet weak var textviewText: UITextView!
let model = Model()
#IBAction func addButton(_ sender: UIButton) {
textviewText.text = "hi"
}
func textField(_ textField: UITextField,
shouldChangeCharactersIn range: NSRange,
replacementString string: String)
-> Bool
{
addButton.isEnabled = false
let text: String = nameInputText.text!
var test_name: Bool
var name_array = [String]()
test_name = model.validateName(nametext: text)
if test_name == true{
addButton.isEnabled = true
name_array.append(text)
return true
}
return (true)
}
override func viewDidLoad() {
super.viewDidLoad()
usernameInputText.delegate = self
nameInputText.delegate = self
passwordInputText.isSecureTextEntry = true
}
override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
self.view.endEditing(true)
}
func textFieldShouldReturn(_ textField: UITextField) -> Bool{
usernameInputText.resignFirstResponder()
nameInputText.resignFirstResponder()
return (true)
}
}
//In model.swift:
import Foundation
class Model {
func validateName(nametext: String) -> Bool{
return true
}
}

textField to LabelView live by swift 2 [duplicate]

This question already has answers here:
UITextField text change event
(22 answers)
Closed 6 years ago.
how can i what ever i type in textField immediately show it in labelView without button that do it ?
import UIKit
class ViewController: UIViewController {
#IBOutlet weak var labelView: UILabel!
#IBOutlet weak var textViewout: UITextField!
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
It's best to use UITextField's delegate:
class ViewController: UIViewController, UITextFieldDelegate {
#IBOutlet weak var labelView: UILabel!
#IBOutlet weak var textViewout: UITextField!
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
textViewout.delegate = self
}
func textField(textField: UITextField, shouldChangeCharactersInRange range: NSRange, replacementString string: String) -> Bool {
labelView.text = textViewout.text
return true
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
EDIT:
Sorry, it actually is not exactly the best solution. It will be delayed. This should work more efficiently for you:
class ViewController: UIViewController {
#IBOutlet weak var labelView: UILabel!
#IBOutlet weak var textViewout: UITextField!
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
textViewout.addTarget(self, action: "updateLabel", forControlEvents: .EditingChanged)
}
func updateLabel() {
labelView.text = textViewout.text
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}

How can I add several UIStepper Values to one Label?

I'm working right now on my first Swift project. I've got 2 stepper and one label - both stepper are sending their values to it. How can I add the value of the second stepper to the label, in which the value of the first stepper is already? Here is my code:
override func viewDidLoad() {
super.viewDidLoad()
stepper.wraps = true
stepper.autorepeat = true
stepper.maximumValue = 10000
stepper2.wraps = true
stepper2.autorepeat = true
stepper2.maximumValue = 10000
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
#IBOutlet weak var valueLabel: UILabel!
#IBOutlet weak var stepper: UIStepper!
#IBAction func stepperValueChanged(sender: UIStepper) {
valueLabel.text = Int(sender.value).description
}
#IBOutlet weak var stepper2: UIStepper!
#IBAction func stepper2ValueChanged(sender: UIStepper) {
valueLabel.text = Int(sender.value).description
}
}
Thank you!
If you want to combine the two values to ONE String and show this String on your Label, than you have to create a new function that does this for you. I added such a function to your code:`
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
stepper.wraps = true
stepper.autorepeat = true
stepper.maximumValue = 10000
stepper2.wraps = true
stepper2.autorepeat = true
stepper2.maximumValue = 10000
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
#IBOutlet weak var valueLabel: UILabel!
#IBOutlet weak var stepper: UIStepper!
#IBAction func stepperValueChanged(sender: UIStepper) {
// valueLabel.text = Int(sender.value).description
addValuesToASumAndPutItIntoTheLabel()
}
#IBOutlet weak var stepper2: UIStepper!
#IBAction func stepper2ValueChanged(sender: UIStepper) {
// valueLabel.text = String(sender.value)
addValuesToASumAndPutItIntoTheLabel()
}
func addValuesToASumAndPutItIntoTheLabel() {
let summe : Int = Int(stepper.value + stepper2.value)
valueLabel.text = summe.description
}
}`

user Log In, let the users in without errors (SWIFT) (Parse)

i'm making an app that required Logging In. the problem is when i run my app to try it and type wrong user info it proceed to the next view controller without giving the error !. Heres my code i don't whats the problem !
{
#IBOutlet weak var ActivityIndicator: UIActivityIndicatorView!
#IBOutlet weak var Message: UILabel!
#IBOutlet weak var UsernameTextField: UITextField!
#IBOutlet weak var PasswordTextField: UITextField!
override func viewDidLoad() {
super.viewDidLoad()
ActivityIndicator.hidden = true
ActivityIndicator.hidesWhenStopped = true
// Do any additional setup after loading the view.
}
#IBAction func LogInButtonTapped(sender: AnyObject) {
LogIn()
}
func LogIn() {
// Start activity indicator
ActivityIndicator.hidden = false
ActivityIndicator.startAnimating()
// if there is a user
var user = PFUser()
user.username = UsernameTextField.text
user.password = PasswordTextField.text
PFUser.logInWithUsernameInBackground(UsernameTextField.text, password:PasswordTextField.text) {
(user: PFUser?, error: NSError?) -> Void in
if user != nil {
dispatch_async(dispatch_get_main_queue()) {
self.performSegueWithIdentifier("LogInToHomeVC", sender: self)}
println("Logged In")
} else {
self.ActivityIndicator.stopAnimating()
if let Message: AnyObject = error!.userInfo!["error"] {
self.Message.text = "\(Message)"}
println("Could Not Find User")
}
}
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
so the question is how to let the user try again and not let him enter the Home Page?

Delegate Method is not called in Swift?

I want to pass a Bool value from on view controller to another without the help of segues. So i referred & got Delegates.
I have applied delegates in my App. But the Delegate method is not being called. I don't know where i am making the mistake.
So Please help me.
MainViewController
class MainViewController: UIViewController, WriteValueBackDelegate {
#IBOutlet weak var LoginButton: UIButton!
var LoggedInL :Bool?
override func viewDidLoad() {
super.viewDidLoad()
}
func writeValueBack(value: Bool) {
println("Delegate Method")
if (value == true){
LoginButton.setTitle("My Profile", forState:UIControlState.Normal)
}
}
Second View Controller
class LoginController: UIViewController {
#IBOutlet weak var LoginLabel: UILabel!
#IBOutlet weak var email: UITextField!
#IBOutlet weak var pwd: UITextField!
var LoggedInL :Bool?
var mydelegate: WriteValueBackDelegate?
override func viewDidLoad() {
super.viewDidLoad() }
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
#IBAction func onSubmit(sender: AnyObject) {
Alamofire.request(.GET, "http://www.jive.com/index.php/capp/user_verification/\(email.text)/\(pwd.text)")
.responseJSON { (_, _, data, _) in
println(data)
let json = JSON(data!)
let name = json["first_name"].stringValue
let status = json["valid_status"].intValue
println(status)
var e = self.email.text
println(e)
self.LoginLabel.text = "Hey \(name)!"
if status == 1{
println("Correect")
self.LoggedInL = true
self.mydelegate?.writeValueBack(true)
}else {
self.LoggedInL = false
println("Error")
}
}
navigationController!.popViewControllerAnimated(true)
}
}
protocol WriteValueBackDelegate {
func writeValueBack(value: Bool)
}
you didn't initialize the delegate, and no need to, delegates are usually for async callbacks. do that instead:
class MainViewController: UIViewController {
static var sharedInstace : MainViewController?;
#IBOutlet weak var LoginButton: UIButton!
var LoggedInL :Bool?
override func viewDidLoad() {
super.viewDidLoad()
MainViewController.sharedInstace = self; //this is better from init function
}
func writeValueBack(value: Bool) {
println("Delegate Method")
if (value == true){
LoginButton.setTitle("My Profile", forState:UIControlState.Normal)
}
}
}
in login view controller
MainViewController.sharedInstance?.writeValueBack(true)
In MainViewControlleryou need a reference of the LoginController instance maybe with an IBOutlet and then set the delegate in viewDidLoad
#IBOutlet weak var loginController : LoginController!
override func viewDidLoad() {
super.viewDidLoad()
loginController.mydelegate = self
}