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 Communicating Via Notifications

KOJI NAKAGAWA
KOJI NAKAGAWA
11,261 Points

Keyboard does not show up (Swift 3)

Hi all.

I wrote down my cord according to the lecture but the keyboard does not show up at all. I looked around my code all and all over again, but I couldn't figure it out because I'm now writing via Swift3 and cannot compare with the teacher's code.

I assumed I wrote down NotificationCenter.default.addObserver() with mistake but could not find out it.

If you could help, I really appreciate. Thanks!!

PS . Also when I write enum Error, I got a compile error.

NG: enum Error: Error{} OK: enum ErrorCheck: Error{}

is it related to Swift 3 or I made another mistake? Please let me know if you know the reason

import UIKit

class ViewController: UIViewController {

enum ErrorCheck: Error{
    case NoName
}

@IBOutlet weak var nameTextField: UITextField!

override func viewDidLoad() {
    super.viewDidLoad()
    // Do any additional setup after loading the view, typically from a nib.
    NotificationCenter.default.addObserver(self, selector: #selector(ViewController.keyboardWillShow(notification:)),
                                           name: NSNotification.Name.UIKeyboardWillShow, object: nil)
}



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"{

        do {
            if let name = nameTextField.text{
                if name == "" {
                    throw ErrorCheck.NoName
            }
                if let pageController = segue.destination as? PageController{
                    pageController.page = Adventure.story(name: "Koji")
                }

            }
        } catch ErrorCheck.NoName {
            let alertController = UIAlertController(title: "Name Not Provided",
                                                    message: "Provide a name to start your story!", preferredStyle: .alert)
            let action = UIAlertAction(title: "OK", style: .default, handler: nil)
            alertController.addAction(action)

            present(alertController, animated: true, completion: nil)
        } catch let error {
            fatalError("\(error)")
        }
    }
}


func keyboardWillShow(notification: NSNotification){
    print("Keyboard will show")
}

}

KOJI NAKAGAWA
KOJI NAKAGAWA
11,261 Points

I solved this by unchecking the Connection Hardware Keyboard of iOS simulator and it worked. Hardware - keyboard - Connection Hardware Keyboard (uncheck)

Abdulwahab Alansari
Abdulwahab Alansari
15,151 Points

For the enum part of your question, Swift3 changed ErrorType to Error, so I noticed when students called their enum as Error, it raises compiler complaint, as a solution for now just don't call your Error enum as Error, just called as your did ErrorCheck for instance.

KOJI NAKAGAWA
KOJI NAKAGAWA
11,261 Points

Thank you Abdulwahab for your comment. I got a point why the compiler error has occurred. thank you!