Seth Rodgers Seth Rodgers - 8 months ago 30
Swift Question

Why am I getting nil for this string value?

Basically I'm trying to make a simple note app, and here I'm just trying to display the title and content.

Project (note) file

import Foundation

class Project
var title = " "
var content = " "
var after = " "

Note detail view controller file

class NoteDetailViewController: UIViewController
var project: Project!

@IBOutlet weak var titleTextField: UITextField!
@IBOutlet weak var contentTextField: UITextView!
@IBOutlet weak var afterTextField: UITextView!

override func viewWillAppear(animated: Bool)
titleTextField.text = project.title
contentTextField.text = project.content
afterTextField.text = project.after


override func viewWillDisappear(animated: Bool)

project.title = titleTextField.text!
project.content = contentTextField.text!


When I reference any of the project. files, I get nil. I have no idea why I'm getting nil from a string?


You need to initialize the class "Project" correctly.

let project = Project()