Tag Archives: Apple

The Swift Programming Language – Day 2 – Classes

Oof, starting out the day kind of rough yesterday. I’m working through the first two paragraphs of the book’s section on introduction to classes and I’m a bit stumped. In general I understand object oriented programming, inheritence, polymorphism, etc… Having said that I sometimes get caught upon the syntax and the issue I’m having today doesn’t even really have to do with classes I don’t think. Right in the beginning of the intro to classes there was the following experiment:

EXPERIMENT
“Add a constant property with let, and add another method that takes an argument.” 1

I understand what ‘creating a constant property’ is and know how to do this using let:

let shapeColor = "Green" 

What I don’t understand is the “add another method that takes an argument” part. An argument is just a variable something that you pass into a function. I assume it just wants me to create a function (is that synonamous with method?) that takes an argument… which I’m assuming it’s trying to get me to use the constant that I just created (shapeColor). I don’t really understand this in context of the class I just created? What am I missing here? Here’s an exerpt of the code I just wrote from the example in the book:

class Shape {
    var numberOfSides = 0
    let shapeColor = "Green"
    func simpleDescription() -> String {
        return "A Shape with (numberOfSides) number of sides."
    }
}

After doing a bit of reading on StackOverflow I think I might have a feel for it now. It seems like a method is a function that you use to get at a property contained in a class. In the example below. I’m just calling the method and passing it a color which then returns a string that uses the color I passed into it. I think i was a bit confused because the book was calling it a method but the sytax still refers to it as a function (‘func’).

class Shape {
    var numberOfSides = 0
    let shapeColor = "Red"
    func simpleDescription() -> String {
        return "A Shape with (numberOfSides) number of sides."
    }

    func getColor(color:String) -> String {
        return "My shape is the (color) color - which is very nice."
    }

}

var shape = Shape()
shape.getColor("blue")

  1. ”Excerpt From: Apple Inc. “The Swift Programming Language.” iBooks. https://itun.es/us/jEUH0.l
    “` 

Learning Swift Programming – Day 1

The Swift Programming LanguageOkay, well technically it’s not Day 1 (but i wan’t to recap my learnings once a day and this is the first post).  I’ve been working through the “The Swift Programming Language” for about a week now. I’m on page 18 of the book and I’ve written ~287 lines of code in the playground. It’s a ton of fun to go through but I find myself not exactly understanding everything.

Specifically this example below.  I understand that is sorting and that reversing the $number will reverse the sort but I have no idea why?  The books says:

“You can refer to parameters by number instead of by name—this approach is especially useful in very short closures. A closure passed as the last argument to a function can appear immediately after the parentheses.” 1

Reading that above, and writing the code below I still don’t understand what $0 and $1 are referring to? They are a stand-in for the variables but what variables exactly? I understand that I must be passing the array of numbers and ordering them based on one being more than or less than the next. I also get in the side bar that to complete the first and second function it took 9 iterations. I’m assuming then that the sort function must sort an array… and that maybe it’s running until the function returns false so until $1 is no longer > than $2. But I’m totally guessing here. Any help understanding this would be appreciated.

let mySort = sort([1,5,3,12,2]) { $1 > $0 } // no idea what this is doing?  I'm assuming it is sorting the array of numbers.
mySort

let theSort = sort([1,5,3,12,2]) { $0 > $1 } // no idea what this is doing?  I'm assuming it is sorting the array of numbers.
theSort

  1. Excerpt From: Apple Inc. “The Swift Programming Language.” iBooks.https://itun.es/us/jEUH0.l 

I love FaceTime…

I was recently traveling to California on business and had a chance to use Apple’s “Facetime” application for the iPhone 4…. It’s fantastic! The calls work seamlessly as long as you have a good wifi connection. In the example pictures below I’m on a very low bandwidth free hotel wifi connection but can still video chat with my wife and son much more easily than if I were on skype with both of us on our computers. It’s amazing how much of a grin this put on my face (as you can see from my flattering pictures below) as well as my son’s face. That’s Kal… he’s about 4 months old and really enjoyed seeing my on his mom’s computer screen. As you can see from the pictures he was all smiles and happiness to be seeing me when I wasn’t there. I’ll be taking a trip to the UK in the next few months and I’m hoping I can use this from there as seamlessly w/out having to pay for the international call as well…. will let you know what I figure out there!


View all the photos here.


A great Apple Store Experience [Customer Service Love]

In line with my goal of having a more positive outlook and expressing that positive outlook in 2010 I thought I would write a quick post about a very positive experience I had at the apple store yesterday.

A few weeks ago I noticed that my power adapter for my MacBook Pro had bare metal exposed where the cable connects to the power adapter. It looked like after normally use the cable just split. I walked down the street and into the Apple store and asked them if I could replace it I told them I had bought it about a year ago. I didn’t bring it up to the Genius Bar I just walked up to the first person in Apple uniform that I saw. This person was very responsive, and asked if I had all the parts. After handing over the power supply, the cable, and the outlet adapter he went back to the Genius Bar showed it to them and then brought it back to me letting me know that they would swap it out for me today. He said that normally I would have to book an appointment with the Genius Bar and have them swap it out under warranty but since I was already there and it would only take 2 seconds he would swap it out for me.

I thought it was fantastic that they didn’t give me a big hassle when they very well could have. They also didn’t look at me as if I was trying to pull a fast one or anything like that. So hats off to you Apple store employee for making my experience easy and on and keeping me a happy customer!