Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

iOS Build an Interactive Story App with Swift 2 Refactoring the Model Layer User Input Through a Text Field

Help Please! Cant seem to understand error

When the teacher writes the error code it seems to work for him at time 4:40 but when I write I get an error saying: ... does not conform to the protocol 'RawRepresentable'. I have seen that in swift 3 Apple has changed 'ErrorType' to 'Error'. This is my code

 import UIKit

class ViewController: UIViewController {

    enum Error: Error { // error in this line
        case noName
    }

    @IBOutlet weak var nameTextField: UIButton!


    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 prepare(for segue: UIStoryboardSegue, sender: Any?) {
        if segue.identifier == "startAdventure" {
            if let PageController = segue.destination as? PageController {
                PageController.page = Adventure.story(name: "Farhan")
            }
        }
    }

}

2 Answers

I have fixed the error it seems the problem was with the 'error' being a capital letter instead of small. I just changed the

enum Error: Error {
case NoName
}

to

enum error: Error {
case NoName
}

Didn't know why that would cause an error. If someone can explain that would be great!

Abdulwahab Alansari
Abdulwahab Alansari
15,151 Points

I guess Error has become a reserved keyword since they have changed ErrorType to Error in Swift3. Therefore, you won't be able to use it, however, changing the case of the first letter or picking up another name would solve the issue.