Coursera - Intro to IOS Development Part 1

I'm back! A few days away after doing the basics course, now going to dive into a new one. Got plenty of time so will do quite a bit today. 

Intro
A note here that there will be older Xcode versions in use. Xcode 10/11 - evolution of finding objects/buttons etc. 

So the 'first app' is a button changing colour. Simple stuff and using the storyboard with view controller match up. This is before SwiftUI came in. So the 'older' way of doing it. 

Xcode Features

A bit from a website to read - 

https://developer.apple.com/xcode/

We're now up to Xcode 12! Key points from this article:

Layout features makes it more user friendly - tabs, views etc
SwiftUI - better for APIs, Widgets... more universal code etc.

A brief overview to be honest.

Welcome Screen
Sometimes he is Mark Price, sometimes Mark Wahlbeck. 

When creating the new project, I just remembered there's the option to select either Storyboard or SwiftUI. So this is back in the Storyboard as the only option days. Fair enough!

A point about graphics - the three different densities. Always have the 2x and 3x. I would say have all three just in case. 

This is very frustrating - no assets to download so can't actually do anything. So I had to go onto the quiz, which was not clear at all (took 3 attempts to get a multiple choice question right!), then get the assets. Bizarre. Going back now to the video, now I have the assets...

OK putting in the image, labels etc. - all familiar stuff. 

This is the code created as a CocoaTouch file - 

class BorderButton: UIView {


    override func awakeFromNib() {

        super.awakeFromNib()

        layer.borderWidth = 3.0

        layer.borderColor = UIColor.white.cgColor

    }


}


IOS Frames


So my understanding of these is for segueing? Maybe...


No not frames but a lot of pointless coding to get the alignments sorted. Surely, this won't be what Mark sticks with - auto layout makes more sense!


Ah yes, he makes it clear that people don't ACTUALLY do this. Yes auto layout and constraints next!


Auto Layout


A lot of the constraints stuff - things I have found so confusing before. All ok here but I do much prefer the SwiftUI approach. I've also put the two bits of text together in a stack! That's using some initiative. 


This auto layout is so confusing but I've worked through each part to it. 


I'll see what's next but it's pretty much time for lunch! Yes a good time to stop, for now!



Stack Views


*The critical thing, which has just popped into my head, is I MUST do a practice session on Xcode, putting the stuff from Week 1 into practice. It is the only way the information becomes commonplace. It's no good just following along indefinitely. So at the end of the Week 1 stuff, I will have a go at doing something with a different theme but same key skills. 

So, again we have no assets until after the lesson...so pointless! Ok a bit awkward, answered the question to get onto assets then found they were all there anyway. Never mind!

Stack view was fiddly - resizing of buttons. So I had to manually put in the width of each of these. Sure there must be an easier way!

Segues

I'm familiar with these - the button to bring up a new screen basically. Some code needed for going back a screen or to 'home'. All good!

Renaming VC

Ok, not letting me do that for the ViewController. Strange. 

A key point for naming each VC is to ensure they are CocoaPod etc. so that UIKit is imported, not foundation. Or at least definitely to have the former!

Debugging

Never delete the outlets! I've had it before with a fatal error when the labels are not connected etc. 

*One cool but confusing thing is that the bar button properties thing DID work! It's just that they only come up when actually running the app. Strange! But it does work at least. 

Programmatic Segues

The basis behind this is that it depends on how you are doing e.g. in a game which then brings up a screen. So doing the clicking and dragging is fine for simple apps but will not always be viable. 

The programmatic example is that you can go ANYWHERE from one VC to another, rather than a specific button. 

So a lot of useful stuff, after going through various errors but troubleshooting it all OK. A good point Mark makes is NEVER to put in logic into @IB actions - instead, have the logic done within other functions, then pass those in. Also, good for the DRY principle. 

A frustrating end as for some reason, the next button just isn't bringing up the next screen. Not sure why - I will try changing that whole segue bit just to see....

OK, cool - got it working! Basically I removed the programmatic segue and did a click and drop one - all the code for the isEnabled worked. 

And that's Week 1 done. Lots of useful stuff here:

Using the MVC for folders to organise the project
Making a custom code style for the border, which could then be used, showing up when the code runs
Having a struct for a model (Player) then having this information used in the code
Segues and how this all works (although confusing)
DRY and the use of a function so that the IB Actions don't actually have logic inside
Use of isEnabled for a button, so that there is a lot of functionality - other objects needing selecting first before clicking next
Use of constraints, auto layout etc. etc. 


So, tomorrow (assuming I have time to code), I will try to replicate these skills but with different content. I'm thinking a Buffy theme as that is something I like and it will be fun. The key point will not be to just copy and tweak, but to get familiar enough with doing it so it becomes natural and I understand it all. 



Comments

Popular posts from this blog

Coursera Introduction to Programming in Swift - Part 4