WWDC21 SALE: Save 50% on all my Swift books and bundles! >>

Trying to make sense of swift, viewdidload() and viewcontroller

Forums > Swift

Hi folks, first post.

Can someone give a clear explanation why you'd put code inside or outside the viewdidload()?

I'm trying to make a simple UITextfield that only accepts numerical values, up to 5 characters in length, with a done button that closes the number pad.

Each and every single example of anything i read comes with massive syntactical errors and no explanations. I'm new to swift, but honestly i've seen no literture that explains even a faction of the syntax.

any guidance would be greatly appreciated.

   

I'm curious what things you are reading. Because there are tons of useful tutorials out there that don't generate "massive syntactical errors" and feature in-depth and comprehensive explanations. Heck, this very site has many, many pages of just such instructional goodness. Have you gone through the 100 Days of Swift?

And, honestly, with this:

I'm trying to make a simple UITextfield that only accepts numerical values, up to 5 characters in length, with a done button that closes the number pad.

it really feels like you are trying to run before you learn to stand, let alone walk.

   

To my understanding, (I'm a novice and maybe wrong here, so please feel free correct me. ) you put code in view did load that you want to load first as the page loads up like an alert window for example.

   

There is a whole lot more to it than just viewDidLoad(). If you're not doing SwiftUI, then the first place to start is the main.storyboard, created when you create a Swift project with XCode. There is then another file called ViewController.swift that lets you connect code to the visual elements you create in the storyboard.

(simplying it)

Want to learn Swift (which is with UIKit, storyboards), the old way of doing things for iPhone / iPad, start with 100 days of Swift. It'll get you where you need to be.

Want to learn SwiftUI (the new way of doing iPhone / iPad apps), go with 100 days of SwiftUI. There is currently a new version of SwiftUI that came out in June 2020, and some things are a work in progress.

   

Save money with our WWDC sale!

SAVE 50% To celebrate WWDC21, all our books and bundles are half price, so you can take your Swift knowledge further without spending big! Get the Swift Power Pack to build your iOS career faster, get the Swift Platform Pack to builds apps for macOS, watchOS, and beyond, or get the Swift Plus Pack to learn advanced design patterns, testing skills, and more.

Save 50% on all our books and bundles!

Reply to this topic…

You need to create an account or log in to reply.

All interactions here are governed by our code of conduct.

 
Unknown user

You are not logged in

Log in or create account
 

Link copied to your pasteboard.