Day 11 of 100 days of SwiftUI

Day 11 - I didn’t have time yesterday to cover it.  The focus has been Protocols.  Did I understand it?  Not really - I’ve understood the basics but not enough to even consistently get the quizzes correct.  I’m persevering though through to the days when I can start putting it together in a programme.

Protocols describe what methods and properties a conforming type must have, but don’t provide the implementations of those methods.

You can build protocols on top of other protocols, similar to classes.

Extensions let you add methods and computed properties to specific types such as Int.

Protocol extensions let you add methods and computed properties to protocols.

Protocol-oriented programming is the practice of designing your app architecture as a series of protocols, then using protocol extensions to provide default method implementations.

Day 10 of 100 days of Swift UI

Completed Day 10 of 100 days of SwiftUI today (https://www.hackingwithswift.com/100/swiftui).

Today it covered classes.  I’m starting to struggle to motivate myself and understand exactly why I need some of the areas covered.  It appears to me that the lessons are just randomly covering different parts of SWIFT without really building on what I learnt the day before.  

In 6 more days I get to start building a project as part of this course and I’m hoping that this will allow me to put into the practise what the current days are covering.

Day 9 of 100 days of Swift UI

Second day of covering struct.  I’m not sure if I’m tired after a late night or it just didn’t gel with me today but I found that difficult.  Feels like I need to be writing an actual app an an example so that I can see how the parts link together - it’s hard when each example isn’t linked to the previous one.

You can create your own types using structures, which can have their own properties and methods.

You can use stored properties or use computed properties to calculate values on the fly.

If you want to change a property inside a method, you must mark it as mutating.

Initializers are special methods that create structs. You get a memberwise initializer by default, but if you create your own you must give all properties a value.

Use the self constant to refer to the current instance of a struct inside a method.

The lazy keyword tells Swift to create properties only when they are first used.

You can share properties and methods across all instances of a struct using the static keyword.

Access control lets you restrict what code can use properties and methods.

Day 8 of 100 days of Swift UI

Completed Day 8 of 100 days of SwiftUI today (https://www.hackingwithswift.com/100/swiftui).  Today looked at structs and after the last two days of closures it was nice to be understand what I was doing today.

Today was the first time that I’ve also started amending the code that that was written and tweaking it - only to experiment.

Day 7 of 100 days of Swift UI

Completed Day 7 of 100 days of SwiftUI today (https://www.hackingwithswift.com/100/swiftui).  

It was the second half of the closures and I didn’t fully understand it.  I completed the ‘Least you need to know’ section.

Although I could read through the code and predict what it would output I struggled with the syntax of it.

Instead of completing the advanced closures I picked a few of the quizzes where I hadn’t scored full marks and repeated them for my own revision.  Usually doing better but not always!

Day 6 of 100 day of SwiftUI

Completed Day 6 of 100 days of SwiftUI today (https://www.hackingwithswift.com/100/swiftui).

Today covered closures which I found challenging to understand. I think I’ve understood today’s lessons.  There’s a second day on it tomorrow luckily!  As the website says:

If you find closures hard it’s not because you aren’t smart enough – they are hard, so it’s just a sign your brain is working properly.

Don’t despair. Sometimes fighting to learn something makes it stick in your head better – there is no learning without struggle!

Day 5 of 100 days of SwiftUI

Completed Day 5 of 100 days of SwiftUI today (https://www.hackingwithswift.com/100/swiftui).

Looking at functions today.  This definitely seems a step up in the understanding for me.  I think a lot of the challenge will be remembering how to write the code correctly - although it’s certainly a lot easier and more natural than writing in BASIC or Machine Code!

Summary of today’s lesson:

Functions let us re-use code without repeating ourselves.

Functions can accept parameters – just tell Swift the type of each parameter.

Functions can return values, and again you just specify what type will be sent back. Use tuples if you want to return several things.

You can use different names for parameters externally and internally, or omit the external name entirely.

Parameters can have default values, which helps you write less code when specific values are common.

Variadic functions accept zero or more of a specific parameter, and Swift converts the input to an array.

Functions can throw errors, but you must call them using try and handle errors using catch.
You can use inout to change variables inside a function, but it’s usually better to return a new value.

Day 4 of 100 days of SwiftUI

Completed Day 4 of 100 days of SwiftUI. Today covered loops using while, repeat and for.  Key learning from today:

Loops let us repeat code until a condition is false.

The most common loop is for, which assigns each item inside the loop to a temporary constant.

If you don’t need the temporary constant that for loops give you, use an underscore instead so Swift can skip that work.

There are while loops, which you provide with an explicit condition to check.

Although they are similar to while loops, repeat loops always run the body of their loop at least once.

You can exit a single loop using break, but if you have nested loops you need to use break followed by whatever label you placed before your outer loop.

You can skip items in a loop using continue.
Infinite loops don’t end until you ask them to, and are made using while true.

Day 3 of 100 days of SwiftUI

Completed Day 3 of 100 days of SwiftUI today (https://www.hackingwithswift.com/100/swiftui).  The focus today was operators and conditions.

It’s very similar to BASIC at the moment - although you can see how the language has advanced to make it easier to read and shorter.

Eg.

score -= 5

Rather than typing:

score = score - 5

Summarising

 

Swift has operators for doing arithmetic and for comparison.

There are compound variants of arithmetic operators that modify their variables in place: +=, -=, and so on.

You can use if, else, and else if to run code based on the result of a condition.

Swift has a ternary operator that combines a check with true and false code blocks. 

If you have multiple conditions using the same value, it’s often clearer to use switch instead.

You can make ranges using ..< and ... depending on whether the last number should be excluded or included.

 

Day 2 of 100 days of SwiftUI

Completed Day 2 of 100 days of SwiftUI yesterday evening (https://www.hackingwithswift.com/100/swiftui).  The focus today was looking at arrays, dictionaries, sets and enums.

Summarising:

Arrays, sets, tuples, and dictionaries let you store a group of items under a single value. They each do this in different ways, so which you use depends on the behavior you want.

Arrays store items in the order you add them, and you access them using numerical positions.
Sets store items without any order, so you can’t access them using numerical positions.

Tuples are fixed in size, and you can attach names to each of their items. You can read items using numerical positions or using your names.

Dictionaries store items according to a key, and you can read items using those keys.
Enums are a way of grouping related values so you can use them without spelling mistakes.

You can attach raw values to enums so they can be created from integers or strings, or you can add associated values to store additional information about each case.

Day 1 of 100 days of SwiftUI

Completed Day 1 of 100 days of SwiftUI yesterday evening (https://www.hackingwithswift.com/100/swiftui).  Another attempt to learn Swift.  I've tried before and normally fail because I run out of time but hoping that the short videos and ‘little each day’ will help me complete it this time.  

I have a really simple app (famous last words!) in my head I want to try and put together at the end!

Today covered variables: 

- Strings

- Integers

- Doubles

- Booleans

- Constants