0
import UIKit

class FirstViewController: UIViewController
 {

    @IBOutlet var Dishname: UILabel!

    @IBOutlet var TEXT: UITextField!

    @IBOutlet var recipy: UIView!



    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.
    }


    override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {

        let secondVC: SecondViewController = segue.destinationViewController as! SecondViewController


        secondVC.items = TEXT.text! as? String    //Error

// Cannot assign value of type 'String?' to type '[String]'

    }
2
  • if let text = TEXT.text { secondVC.items.append(text) }. Commented Mar 19, 2016 at 0:56
  • Yeah, looks like SecondViewController.items is a string array, and you're passing it an optional string. Please post your code for SecondViewController. I assume you're initializing SecondViewController.items? If so, you can do as @Eendje suggested. Commented Mar 19, 2016 at 1:00

1 Answer 1

1

The items variable in SecondViewController is Array of String, [String] type and you try to assign a String to it rather than insert or append into it.

Sign up to request clarification or add additional context in comments.

1 Comment

The error message should have been a giveaway. And the fact that he is assigning to "items", not "item".

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.