I am building an app using a codeschool tutorial, but even though I have followed the exact code and steps to build a scrollView page correctly, it only displays a blank screen on the iOS simulator. What am I doing incorrectly?
Here is my code:
import UIKit
class ContactViewController: UIViewController {
@IBOutlet weak var scrollView: UIScrollView!
override func viewDidLoad() {
super.viewDidLoad()
view.addSubview(scrollView)
}
override func viewWillLayoutSubviews() {
super.viewWillLayoutSubviews()
scrollView.contentSize = CGSize(width: 375, height: 800)
I get the following error message:
Thread 1: EXC_BAD_INSTRUCTION (code=EXC_1386_INVOP, subcode=0x0) when building the app, which is summarized as that states
...which is characterized as a:
fatal error: unexpectedly found nil while unwrapping an Optional value (lldb)
I have run this numerous times. And I have looked carefully through existing posts, but I am a novice and some are suggesting changes to the code that seem like they would be unnecessary, since I've done everything exactly as the tutorial instructs (which I imagine would have had the appropriate QA in advance). I appreciate anyone's insight!
UPDATE. Users below have helped identify the problem. The code itself was not the problem, but simply linking the scrollView to the code in the Assistant Editor had apparently not been done. Even though there was a circle next to the code in the Assistant Editor, it was not actually linked, or the link had been broken. You can confirm the link is actually working by hovering over the circle, which will highlight the Scroll View in your storyboard editor in blue. If the link is broken, it will not highlight.
Thanks for everyone's help. And here again is the final working code: