Chris Ching Course Part 3 (Properties, Initializers, Arrays and Dictionaries)
So this may be the last of these 'consolidation' Chris Ching courses that I'll use. It's been good fun but at the same time I know I am beyond this level of understanding. It's more of a confidence booster really! It's a good job that I like spending time coding and going over this stuff! OK here we go!
Start time - 19:13
Properties
All fine so far. Chris says that properties are variables inside the class. Well, they are. But they can also be constants!
Computed properties - I need to go over this, good!
Start time - 19:13
Properties
All fine so far. Chris says that properties are variables inside the class. Well, they are. But they can also be constants!
Computed properties - I need to go over this, good!
class BlogInfo {
var blogTitle: String
var blogBody: String
var author: String?
var posts: Int
var fullTitle: String {
if author != nil {
return blogTitle + " by " + author!
} else {
return "Author is unknown"
}
}
So this is an example of a computed property. A CP means some calculation or code is required so a result is returned. It is different to stored properties.
The syntax is clarified - using the if statement. With if statements within the CP, you need to have the else clause!
Designated and Convenience Initializers
OK so up to this point, Chris has not done any initialization - to make classes and properties easier to understand. I put inits in, as I wanted to allow new values to be created each time. Anyway, he starts off going over optionals again with unwrapping...
This syntax doesn't look right to me. I think it's because of not setting values upon initialization. Convenience init just means another way to initialize - it is another option. Not the main one (designated).
Arrays/Dictionaries
An array is a collection type. I know that it is ordered by indexes and the syntax etc.
All the examples were fine - adding, removing etc. etc.
Just skimming through dictionaries...
I don't like the < > syntax.
*My Xcode Playgrounds aren't running properly and haven't been for several days - very frustrating so I can't even code along!
The syntax for dictionaries is var dict = [String: String]()
Then dict ["Ferrari"] = "Vettel"
*Using the for/in loops is very powerful - something that Chris has done a couple of times.
Paused at 19:55 (42 minutes total today)
I had various things to do after this so that was all for Chris's course today. Not that useful - not in terms of what he was presenting, but more that it was all very familiar to me. It did not help that my Xcode Playground was not working properly. Again! So, I have gone over basic properties, including computed ones, a couple of initializers - the convenience keyword and some basics of arrays and dictionaries. Next time I'm going to attempt the challenges. I did the first one before but am going to do it again anyway.
Comments
Post a Comment