UPGRADE YOUR SKILLS: Learn advanced Swift and SwiftUI on Hacking with Swift+! >>

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.

2      

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.

2      

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.

2      

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.

2      

Hacking with Swift is sponsored by Essential Developer

SPONSORED Join a FREE crash course for mid/senior iOS devs who want to achieve an expert level of technical and practical skills – it’s the fast track to being a complete senior developer! Hurry up because it'll be available only until April 28th.

Click to save your free spot now

Sponsor Hacking with Swift and reach the world's largest Swift community!

Archived topic

This topic has been closed due to inactivity, so you can't reply. Please create a new topic if you need to.

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.