Posts

Showing posts with the label properties

Stephen DeStefano Swift 5 Course - Part 4 (Lectures 12 to 16)

Image
Not going to go into rambling detail about how it's been a long time etc. End of term, start of holiday is always mental! I have missed my regular coding so am going to get some in today, then there will be more on Monday! I was working through Stephen's course, which was becoming pretty technical and challenging. Let's go! Start Time - 07:17 Stored Properties So these store constant/variable data. A key point here. Structs are value types - if you have a constant stored property, you cannot change the value. You can for classes as they are reference types. All that was pretty easy to be honest. Lazy Properties So I'm just trying to figure out the purpose of these! Stephen is quite rambling. OK so when the property is actually initialised, that's when the lazy stored property is accessed. It's about saving memory. So not created until it has actually been used. If it's computationally expensive - if it will end up slowing things down! Right...

Nick Walter Challenges (Part 5)

Image
Yes I managed to find time for one more session! So here we go - now going on to properties. The next several will be all linked to class aspects, so I'm actually going to go through them before the challenges. Always worth building my knowledge up on these as I need to! Start Time - 20:34 Computed Properties So from what I can remember about these, the property is not stored but requires some sort of computation. In the example below, I have two stored properties: class Dog {     var name = ""     var age = 0 } So this is a computed property - it requires the use of the stored property of age and creates a  temporary one of current year. Makes total sense.  var birthYear: Int {         let currentYear = 2018         return currentYear - age     } This looks like a function - using return and all. I could actually use a function but a computed property is bet...

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! 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" ...

*EXTRA ENTRY* Properties and Initializers - recap!

Technically, I promised not so many entries but I really feel the need to go over some of this! There was a lot of content in the last couple of sessions that I did not feel were clearly explained enough - no offence Pasan but they were hard to follow! So now is the time to seek out a bit more information. This is very 'casual' - I have an Avengers film on in the background and am not going under any time constraints or anything - I have plenty this evening. So I just want to clarify a few things and get some hands-on practice. Let's go! Properties From Pasan's explanations, there are several different types of these. This is what I know: Stored properties - these are values which are either declared within the class/struct/enum, or declared upon initialization.  Computed properties - these require a calculation and a reference to one of the stored properties, which may not yet have a value. The computed property can be accessed when an instance is create...