0

this picture should say enough: enter image description here

I have been scouring the web to find answers and none else seems to have this problem. I am using Xcode 7 Beta 3 with Swift 2. I can't figure out what's wrong.

Thanks in advance

EDIT:

Here's the code:

func input(text:String) -> String {
    Say(text)
    let alert:UIAlertController = UIAlertController(title: "Goog", message: text, preferredStyle: UIAlertControllerStyle.Alert)
    [alert .addTextFieldWithConfigurationHandler({ (textfield: UITextField!) -> Void in
    })]
    var returnValue:String = ""
    let confirmAction = UIAlertAction(
        title: "OK", style: UIAlertActionStyle.Default) {(action) in
            returnValue = (alert.textFields[0] as UITextField).text!
            return
    }
    return returnValue
}
Nerdy Lime Apps
  • 331
  • 2
  • 5
  • 18
  • Show more code and we might be better able to solve your problem. (Where is `returnValue` defined? What is its type?) And post your code as text, not an Xcode screenshot. Not everyone uses SO in a way that lets them easily read text embedded in an image. – rickster Jul 20 '15 at 19:16
  • right before I define the action. I simple said: var returnValue:String = "" – Nerdy Lime Apps Jul 20 '15 at 21:51
  • 1
    This error tends to be misleading. You should show the 5 lines preceding and following this code snippet (as text please). – Mundi Jul 20 '15 at 22:07

2 Answers2

-1

You want to use the Swift enum for the action style like this:

let alertAction2 = UIAlertAction(title: "My Alert", style: .Default)
        {(action:UIAlertAction) -> Void in
            // do something with action
            return
        }

Or more concisely:

let alertAction2 = UIAlertAction(title: "My Alert", style: .Default)
        {action in
            // do something with action
        }
pxr
  • 40
  • 1
  • 6
  • 1
    let confirmAction = UIAlertAction( title: "OK", style: UIAlertActionStyle.Default) {(action) in returnValue = (alert.textFields[0] as UITextField).text! return } return returnValue – Nerdy Lime Apps Jul 20 '15 at 19:00
  • oh i forgot to tag @PaulRobinson – Nerdy Lime Apps Jul 20 '15 at 19:07
  • You can't return anything from the handler as it returns Void. All you can do is do something with the action. Did I understand your comment correctly @NerdyLimeApps ? – pxr Jul 20 '15 at 19:11
  • Even after removing the return statement and just assigning the value to the variable it keeps the error still – Nerdy Lime Apps Jul 20 '15 at 21:51
  • @PaulRobinson You do not need the parentheses around `action`, and you do not need a return statement. – Mundi Jul 20 '15 at 22:06
-1
UIAlertController *altSuccess = [UIAlertController alertControllerWithTitle:@"Success" message:@"Login Successfully" preferredStyle:UIAlertControllerStyleAlert];

UIAlertAction *okSuccess = [UIAlertAction
                                    actionWithTitle:@"OK"
                                    style:UIAlertActionStyleDefault
                                    handler:^(UIAlertAction * action)
                                    {
                                        NSLog(@"%@",[dict objectForKey:@"email"]);
                                        NSLog(@"%@",[dict objectForKey:@"password"]);
                                        [altSuccess dismissViewControllerAnimated:YES completion:nil];
                                    }];

        [altSuccess addAction:okSuccess];

        [self presentViewController:altSuccess animated:YES completion:nil];

Its works fine...

Lotus Shah
  • 493
  • 4
  • 13
  • 1
    The original question is specifically about using UIAlertAction in Swift. The tags and title of the question even include the word 'Swift'. Your answer is in Objective-C. – Jeff C. Jun 30 '16 at 10:54