Posts

Showing posts with the label type

Collections and Control Flow: Arrays

OK, last entry for today! A nice problem to have, for sure - and quite a contrast to the past few months where my entries were so rare. Of course, I'm not going to hide from the fact that I've been much keener because the content is easier and more familiar, etc etc. My point is that I don't want to pack TOO much in at once, as the information will not be retained or made as much sense of. So, starting with 'Collections and Control Flow', the first part that I'm going to focus on is Arrays. There are several videos ahead, so will work through one at a time. Introduction to Arrays Pasan starts with a brief recap that we've covered variables, constants etc. In programming, we often like to work with multiple values. So far, we've focused on simple objects - whether it be strings, ints etc. There are three collection types in Swift: Arrays Dictionaries Sets This course will focus on the first two. In an Array, a number is associated with each ...

Arithmetic Operators; Assignment and Comparison; Operator Precedence; Unary Operators

So I am coming to the end of the recap of my 'Swift Basics' course. Once I've finished that, I should feel pretty secure with the essentials. The next task after this will be to go over the other courses I have completed. Realistically, by this time next week, I should be ready to continue with learning 'new' information! Arithmetic Operators There is some technical mathematical information about operands. We now move on to the four main operations - add, subtract, multiply and divide. The other function that can be used is the remainder operator (% is used). E.g. 9 % 4 would give 1. let height = 12 let width = 10 let area = height * width Simple stuff for using multiplication, in this case.  The next part is dividing the area by 10.764, to have the answer in metres. However, this is a double. The most logical thing to do is changing height to 12.0 and width to 10.0. Or, you can declare height and width as doubles, using the syntax of the ...

Numbers and Booleans; Type Safety and Type Inference

So, yes I am on much more of a roll now! The most consistent entries since starting this blog! As before, the issue will be, once the recap/consolidation process is complete, trying to stick to learning new aspects regularly will be the challenge. Anyway, we're cracking on with numbers and booleans first of all.... Numbers and Booleans  One of the concepts mentioned are floats - numbers which can have decimal places. I know that these are known as 'doubles' and tend to use these over 'floats'. And that's what he goes on to say! Indeed, Pasan explains that Double is preferable as it can store more basically. A lot of this is linked to type inference to e.g. if I declare a variable and give it 3.4 as a value, it will automatically make it of type Double. Booleans - now these are essentially true or false. String Interpolation - as a reminder - allows values from different types to be put in together. You can create a string made up of a mixture of other type...

Creating Custom Classes

I know that I promised to make my entry much sooner than this but, once again, life got in the way! So here we are, a couple of weeks later than planned. Anyway, it's the first time in months that I'm actually doing this blog alongside some coding. So it's a step in the right direction! Moving forward, after working through this book, I plan to do this book alongside another course or text, so hopefully the 'live' recording of it will be useful and purposeful.  This chapter is all about creating custom classes. Now I know, more or less, what a class is. From what I recall, a class bundles together data e.g. variables, constants, functions...all to then create specific objects or instances. We'll see what this chapter brings...! So the task in this chapter is to create a functioning calculator - able to add, subtract etc. class Calculator {      } This is how to set up the class. The syntax is have a capital letter - different to variables, func...

Calling Methods

So, starting from my previous post on 'Optionals',  I'm focusing on one area/challenge of Swift at a time, with my immediate reactions and reflections on them written in this blog. As I've mentioned before, the purpose of this is to help me make sense of what I am learning, not revel in my lack of knowledge! Also, as before, the source material I am using to learn about Swift is from the same Ebook as before: 'Learn Code in Swift 4' by Kevin McNeish. This time I will also supplement with this from other courses I have used in the past, e.g. Treehouse to help me understand the information in context. Calling Methods So the purpose of this chapter in the Ebook is to do with appending. So, first of all, what is a method? A  method groups together one or two more lines of code that are then executed as a unit. I've always thought of these as a function put into context. E.g. 'print' is a method, or is it a function? As with any element of Swift, ther...