# Errata for Swift Apprentice v1.3

**URL:** <https://forums.kodeco.com/t/errata-for-swift-apprentice-v1-3/11916>\
**Category:** Swift Apprentice\
**Created:** [April 2, 2016, 2:41pm UTC](https://forums.kodeco.com/t/errata-for-swift-apprentice-v1-3/11916 "2016-04-02T14:41:41Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![rwenderlich](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/rwenderlich/32/108604_2.png) [@rwenderlich](https://forums.kodeco.com/u/rwenderlich)\
**Post date:** [April 2, 2016, 2:41pm UTC](https://forums.kodeco.com/t/errata-for-swift-apprentice-v1-3/11916/1 "2016-04-02T14:41:41Z")

</div>

This topic is for bugs, typos, and other mistakes in Swift Apprentice v1.3.

---

<div class="post-metadata">

**Author:** ![rwenderlich](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/rwenderlich/32/108604_2.png) [@rwenderlich](https://forums.kodeco.com/u/rwenderlich)\
**Post date:** [April 2, 2016, 2:41pm UTC](https://forums.kodeco.com/t/errata-for-swift-apprentice-v1-3/11916/2 "2016-04-02T14:41:52Z")

</div>

Pinned on April 2, 2016, 2:41pm UTC



---

<div class="post-metadata">

**Author:** ![artbataev](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/artbataev/32/89792_2.png) [@artbataev](https://forums.kodeco.com/u/artbataev)\
**Post date:** [April 3, 2016, 1:02pm UTC](https://forums.kodeco.com/t/errata-for-swift-apprentice-v1-3/11916/3 "2016-04-03T13:02:28Z")

</div>

Chapter 20: Protocol-Oriented Programming, page 262  
In Example:

```auto
protocol MyProtocol {
    func bar() // not foo()
}

extension MyProtocol {
    func bar() { print("Hello!") }
}

struct MyType: MyProtocol {
    func bar() { print("Good Day!") }
}
```

When method **is not** defined in the protocol - **Calls Protocol Extension** (not local implementation)

 ![](https://raywenderlich-com-v3-forums.s3.amazonaws.com/original/3X/7/f/7f9df6297d5aa46fcbeba56450fb131898be3ad2.png)

When method **is** defined in the protocol - **Calls local implementation** : the result will be “Good Day!”  
(Sorry, I can’t post second image, because I’m a new user.)

---

<div class="post-metadata">

**Author:** ![stemcc](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/stemcc/32/21782_2.png) [@stemcc](https://forums.kodeco.com/u/stemcc)\
**Post date:** [April 5, 2016, 9:18pm UTC](https://forums.kodeco.com/t/errata-for-swift-apprentice-v1-3/11916/4 "2016-04-05T21:18:57Z")

</div>

**Edit**  
I’m going to keep a running list of things I find instead of making a new post for each.

**1. Page 48** PDF.

Typo in top example, variable used in the operation should be counter += 1

This is what’s currently there:

`var counter = 0 count += 1 counter // counter = 1 counter -= 1 counter // counter = 0`

**2. Page 61** PDF

typo: “is” for “if” and “that” for “than”

> Just as with numbers, you can compare not just for equality, but also to determine **is** one value is greater than or less **that** another value.

---

<div class="post-metadata">

**Author:** ![101airborne](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/101airborne/32/110937_2.png) [@101airborne](https://forums.kodeco.com/u/101airborne)\
**Post date:** [April 27, 2016, 8:14pm UTC](https://forums.kodeco.com/t/errata-for-swift-apprentice-v1-3/11916/5 "2016-04-27T20:14:22Z")

</div>

On page 238 the sentence “You follow the name of the named type with a semicolon and the name of the protocol you want to conform to.” says to use a “semicolon ( ; )”. I believe that should be a “colon( : )”

On page 244 in the declaration of wheeledVehicleBike:

let wheeledVehicleBike: WheeledVehicle5 = bike

I believe the ‘5’ at the end of “WheeledVehicle5” is a typo.

---

<div class="post-metadata">

**Author:** ![nafuto](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/nafuto/32/30075_2.png) [@nafuto](https://forums.kodeco.com/u/nafuto)\
**Post date:** [May 3, 2016, 3:02am UTC](https://forums.kodeco.com/t/errata-for-swift-apprentice-v1-3/11916/6 "2016-05-03T03:02:38Z")

</div>

Chapter 20: Solution of challenge A  
`Clothing(name: "Shirt", msrp: 12.99, clearance: true).totalPrice()` = 12.99  
`Clothing(name: "Last season shirt", msrp: 12.99, clearance: false).totalPrice()` = 12.99, too ?

---

<div class="post-metadata">

**Author:** ![orchetect](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/orchetect/32/73736_2.png) [@orchetect](https://forums.kodeco.com/u/orchetect)\
**Post date:** [June 6, 2016, 1:03am UTC](https://forums.kodeco.com/t/errata-for-swift-apprentice-v1-3/11916/7 "2016-06-06T01:03:05Z")

</div>

## Chapter 12: Sets \> Accessing elements (page 145)

> You can also use the `first` and `last` properties, which return one of the elements in the set.

When in fact `.first` works but `.last` does not - it returns the Swift error:

`Type 'SetIndex<Int> does not conform to protocol 'BidirectionalIndexType'`

## Chapter 13: Structures \> Introducing methods (page 160)

The function `isInRange3` is defined:

> `func isInRange3(customer: Location) -> Bool {`

However undefined `isInRange` is subsequently called right after (top of page 161):

> `print(isInRange(customer)) // Pizza time!`

These function names should be the same (isInRange).

## Chapter 13: Structures \> Introducing methods (page 161)

For the following code snippet:

> `struct DeliveryRange { var range: Double let center: Location func isInRange(customer: Location) -> Bool { let difference = sqrt(pow((latitude - center.latitude), 2) + pow((longitude - center.longitude), 2)) return difference < range } // initializers here }`

Swift complains that `latitude` and `longitude` are unresolved identifiers. This can be resolved by correcting the code as follows:

> `let difference = sqrt(pow((customer.latitude - center.latitude), 2) + pow((customer.longitude - center.longitude), 2))`

## Chapter 15: Advanced classes \> Polymorphism (page 183)

> `print( phonebookName(person) ) // Appleseed, John`

The commend should instead read: `// Appleseed, Johnny`

## Chapter 19: Protocols \> Typealias in protocols (page 243)

> `protocol WeightCalculatable { typealias WeightType func calculateWeight() -> WeightType }`

Swift is reporting that `typealias` is deprecated here, and wants to replace it with `associatedtype`.

## Chapter 19: Protocols \> Equatable and comparable (page 252)

In the second code block, this line:

> `leagueRecords.minElement() // {wins 23, losses 8}`

Should be corrected as:

> `leagueRecords.minElement() // {wins 14, losses 11}`

---

<div class="post-metadata">

**Author:** ![sorenburkhart](https://s3.amazonaws.com/cdn.raywenderlich.com/community/forum-assets/noun-game-ghost-878668.png) [@sorenburkhart](https://forums.kodeco.com/u/sorenburkhart)\
**Post date:** [June 6, 2016, 7:23pm UTC](https://forums.kodeco.com/t/errata-for-swift-apprentice-v1-3/11916/8 "2016-06-06T19:23:22Z")

</div>

**Page 261 - Introducing protocol extensions**

Code is missing parenthesis for the winningPercentage calculation, should be:

func winningPercentage() → Double {  
return Double(wins) / **(Double(wins) + Double(losses))**  
}

---

<div class="post-metadata">

**Author:** ![sorenburkhart](https://s3.amazonaws.com/cdn.raywenderlich.com/community/forum-assets/noun-game-ghost-878668.png) [@sorenburkhart](https://forums.kodeco.com/u/sorenburkhart)\
**Post date:** [June 10, 2016, 8:22pm UTC](https://forums.kodeco.com/t/errata-for-swift-apprentice-v1-3/11916/9 "2016-06-10T20:22:46Z")

</div>

**Page 266 struct HockeyRecord should be HockeyRecord2**

or on page 267 you should change the == func to refer to HockeyRecord

---

<div class="post-metadata">

**Author:** ![sorenburkhart](https://s3.amazonaws.com/cdn.raywenderlich.com/community/forum-assets/noun-game-ghost-878668.png) [@sorenburkhart](https://forums.kodeco.com/u/sorenburkhart)\
**Post date:** [June 10, 2016, 10:49pm UTC](https://forums.kodeco.com/t/errata-for-swift-apprentice-v1-3/11916/10 "2016-06-10T22:49:41Z")

</div>

**Chapter 20 - Challenge A -Page 271**

Extra () in Item protocol definition should be:  
protocol Item {  
var name: String { get }  
var clearance: Bool { get }  
var msrp: Float { get }  
func totalPrice() → Float  
}

**also the solution file uses a Double instead of a Float**

**Solution for Chapter 20 - Challenge A**

The solution has a lot of errors in it:

Specifically:

`Clothing(name: "Shirt", msrp: 12.99, clearance: true).totalPrice()`

returns $12.99 when it should have adjusted the price to $9.74

The reason for this error is because it is using the totalPrice function from the Item protocol and wasn’t overriden with the extension that required the struct have both TaxableItem and ClearanceableItem protocols.

Here is a version I came up with that cleaned up the errors, and I think helps demonstrate the concepts from the chapter:

```
import Foundation

// Item Protocol
protocol Item: CustomStringConvertible {
    var name: String { get }
    var msrp: Double { get }
    func totalPrice() -> Double
}

extension Item {
    func totalPrice() -> Double {
        return msrp
    }
}

extension Item {
    var description: String {
        let stringMsrp = String(format: "$%.2f", msrp)
        var _description = "\(name) - \(stringMsrp)"
        if let e = self as? ExpirableItem {
            _description += e.expirableDescription
        }
        if let c = self as? ClearanceableItem {
            _description += c.clearanceableDescription
        }
        return _description
    }
}

// ClearanceableItem Protocol

protocol ClearanceableItem: Item {
    var clearance: Bool { get set }
    var discount: Double { get }
    var adjustedMsrp: Double { get }
}

extension ClearanceableItem {
    var adjustedMsrp: Double {
        return msrp * (clearance ? (1 - discount) : 1.0)
    }
    
    var clearanceableDescription: String {
        let stringAdjustedMsrp = String(format: "$%.2f", adjustedMsrp)
        return clearance ? " -> ON SALE! Now just \(stringAdjustedMsrp)" : ""
    }
    
    func totalPrice() -> Double {
        return adjustedMsrp
    }
}

// TaxableItem Protocol

protocol TaxableItem: Item {
    var salesTaxPercent:Double { get }
}

extension TaxableItem {
    var salesTaxPercent: Double {
        return 0.075
    }
    
    func totalPrice() -> Double {
        return msrp + msrp*salesTaxPercent
    }
}

extension TaxableItem where Self:ClearanceableItem {
    func totalPrice() -> Double {
        return adjustedMsrp + adjustedMsrp*salesTaxPercent
    }
}

// Clothing Struct

struct Clothing: ClearanceableItem {
    let name: String
    let msrp: Double
    var clearance: Bool
    let discount = 0.25
}

// Electronic Struct

struct Electronic: TaxableItem, ClearanceableItem {
    let name: String
    let msrp: Double
    var clearance: Bool
    let discount = 0.05
}

// ExpirableItem Protocol

protocol ExpirableItem: Item {
    var expirationMonth:Int {get}
    var expirationYear:Int {get}
}

extension ExpirableItem where Self: Item {
    var expirableDescription: String {
        return " expires \(expirationMonth)/\(expirationYear)"
    }
}

// Food Struct

struct Food: ClearanceableItem, TaxableItem, ExpirableItem {
    let name: String
    let msrp: Double
    var clearance: Bool
    let expirationMonth: Int
    let expirationYear: Int
    let discount = 0.5
}

Food(name: "Bread", msrp: 2.99, clearance: false, expirationMonth: 11, expirationYear: 2016).totalPrice()
Food(name: "Old Bread", msrp: 2.99, clearance: true, expirationMonth: 11, expirationYear: 2016).totalPrice()

Clothing(name: "Shirt", msrp: 12.99, clearance: false).totalPrice()
Clothing(name: "Last season shirt", msrp: 12.99, clearance: true).totalPrice()

Electronic(name: "Apple TV", msrp: 139.99, clearance: false).totalPrice()
Electronic(name: "Apple TV 3rd gen", msrp: 99.99, clearance: true).totalPrice()

//// Custom string convertible demonstration
Food(name: "Bread", msrp: 2.99, clearance: false, expirationMonth: 11, expirationYear: 2016)
var e = Electronic(name: "Apple TV 3rd gen", msrp: 99.99, clearance: false)

// Show the impact of changing the clearance flag
e.totalPrice()
e.clearance = true
e.totalPrice()

```

---

<div class="post-metadata">

**Author:** ![orchetect](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/orchetect/32/73736_2.png) [@orchetect](https://forums.kodeco.com/u/orchetect)\
**Post date:** [June 13, 2016, 6:37am UTC](https://forums.kodeco.com/t/errata-for-swift-apprentice-v1-3/11916/11 "2016-06-13T06:37:20Z")

</div>

> [@sorenburkhart](#):
>
> Here is a version I came up with that cleaned up the errors, and I think helps demonstrate the concepts from the chapter:

Just FYI, their solution (and yours) still do not have a struct for a Household item. The challenge calls for 4 item varieties, not 3.

---

<div class="post-metadata">

**Author:** ![stevecaine](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/stevecaine/32/103644_2.png) [@stevecaine](https://forums.kodeco.com/u/stevecaine)\
**Post date:** [August 26, 2016, 7:42pm UTC](https://forums.kodeco.com/t/errata-for-swift-apprentice-v1-3/11916/12 "2016-08-26T19:42:33Z")

</div>

The last closure definition on page 101

```
multiplyClosure = { (a, b) in a*b }

```

returns an error because the parameter types and return type cannot be inferred:

Playground execution failed: Chapter02.playground:62:38: error: ambiguous use of operator ‘\*’  
let multiplyClosure4 = { (a, b) in a \* b }

---

<div class="post-metadata">

**Author:** ![stevecaine](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/stevecaine/32/103644_2.png) [@stevecaine](https://forums.kodeco.com/u/stevecaine)\
**Post date:** [September 16, 2016, 2:51am UTC](https://forums.kodeco.com/t/errata-for-swift-apprentice-v1-3/11916/13 "2016-09-16T02:51:03Z")

</div>

Chapter 8: Closures, page 105 (PDF)  
Incorrect result given in text for code example.

Text says, "For example, you could write this function:

```
func countingClosure() -> (() -> Int) {
  var counter = 0
  let incrementCounter: () -> Int = {
    counter += 1
    return counter
}
return incrementCounter
}

```

"… this could be used like so:

```
let counter1 = countingClosure()
let counter2 = countingClosure()
counter1() // 0
counter2() // 0
counter1() // 1
counter1() // 2
counter2() // 1

```

But instead, the first call to each instance returns ‘1’, because the internal counter is incremented _before_ its value is returned.

---

<div class="post-metadata">

**Author:** ![g6029](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/g6029/32/44719_2.png) [@g6029](https://forums.kodeco.com/u/g6029)\
**Post date:** [October 19, 2016, 3:17am UTC](https://forums.kodeco.com/t/errata-for-swift-apprentice-v1-3/11916/14 "2016-10-19T03:17:48Z")

</div>

Chapter 8: Arrays, page 136  
Deleting elements: Deleting an element leaves a gap where the removed element was. As was mentioned earlier, all elements in the array have to be sequential so this gap needs to be closed by shifting elements forward.  
The complexity is similar to inserting elements: If you’re removing an element **from the beginning** or the end, it’s an O(1) operation. If you’re removing from the middle, the complexity is O(N).

I am wondering if you remove the first element while keep the array address not change, you may need to shift all rest elements forward, then the complexity will be O(n), right?

---

<div class="post-metadata">

**Author:** ![leblanc-f](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/leblanc-f/32/102075_2.png) [@leblanc-f](https://forums.kodeco.com/u/leblanc-f)\
**Post date:** [October 31, 2016, 1:12am UTC](https://forums.kodeco.com/t/errata-for-swift-apprentice-v1-3/11916/15 "2016-10-31T01:12:19Z")

</div>

Chapter 11. Structures.  
On page 168, there’s a mini-exercice to calculate if 2 areas are overlapping. In the code provided, the function goes as follow:  
` func overlaps(with area: DeliveryArea) -> Bool { return distance(from: center, to: area.center) >= (range + area.range) }`  
Shouldn’t this be `<=` ? With this code, I can demonstrate that these 2 areas overlap:  
` let area1 = DeliveryArea(range: 2.5, center: Location(x: 2, y: 4)) let area2 = DeliveryArea(range: 2.5, center: Location(x: 2, y: 15)) area1.overlaps(with: area2)`

---

<div class="post-metadata">

**Author:** ![ddymek](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/ddymek/32/53165_2.png) [@ddymek](https://forums.kodeco.com/u/ddymek)\
**Post date:** [January 1, 2017, 8:39pm UTC](https://forums.kodeco.com/t/errata-for-swift-apprentice-v1-3/11916/16 "2017-01-01T20:39:13Z")

</div>

_I couldn’t find an Errata for v2.0 of this book, so I posted it here._

I just started the book(v2.0), and I made it to chapter#2 challenge question#8 where I hit a wall. The only solution I could come up with involved a basic cast operation, but cast operations hadn’t yet been covered. So after banging my head against the wall for another 20 minutes I opened up the solutions file that’s included with the book, and lo and behold you guys used a cast operation… 😕

I’m able to work through the issue because this isn’t my first programming language, but given the books narrative and the first chapter being a very very brief introduction to how a computer works; I’m assuming that the target audience is not necessarily a seasoned programmer. Type conversions isn’t discussed until the following chapter.

Unless I missed something extremely obvious when I was reading/skimming, I think if you’re going to require the use of casting to solve your challenge problems, you need to at least touch on the subject **before** it’s required 😉

---

<div class="post-metadata">

**Author:** ![avantjer](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/avantjer/32/81494_2.png) [@avantjer](https://forums.kodeco.com/u/avantjer)\
**Post date:** [March 15, 2017, 8:42pm UTC](https://forums.kodeco.com/t/errata-for-swift-apprentice-v1-3/11916/17 "2017-03-15T20:42:51Z")

</div>

Looks, like you never got a response.  
I concluded the same thing you did, but thought, “I must be wrong somehow”, and went over it and over it.  
So, I was glad to see your post, which made me feel a little better.  
I think we’re right.  
Too bad they didn’t reply.

---

<div class="post-metadata">

**Author:** ![culecorea](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/culecorea/32/60562_2.png) [@culecorea](https://forums.kodeco.com/u/culecorea)\
**Post date:** [March 26, 2017, 2:35pm UTC](https://forums.kodeco.com/t/errata-for-swift-apprentice-v1-3/11916/18 "2017-03-26T14:35:11Z")

</div>

They haven’t replied at all 😓

---

<div class="post-metadata">

**Author:** ![pauldelaware](https://s3.amazonaws.com/cdn.raywenderlich.com/community/forum-assets/noun-game-ghost-878668.png) [@pauldelaware](https://forums.kodeco.com/u/pauldelaware)\
**Post date:** [June 16, 2017, 10:08pm UTC](https://forums.kodeco.com/t/errata-for-swift-apprentice-v1-3/11916/19 "2017-06-16T22:08:22Z")

</div>

Page 16, Introduction: “…languages, and some that Swift approves upon in novel ways.” Should be, “improves”

---

<div class="post-metadata">

**Author:** ![shogunkaramazov](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/shogunkaramazov/32/108826_2.png) [@shogunkaramazov](https://forums.kodeco.com/u/shogunkaramazov)\
**Post date:** [July 18, 2017, 8:00am UTC](https://forums.kodeco.com/t/errata-for-swift-apprentice-v1-3/11916/20 "2017-07-18T08:00:37Z")

</div>

Thank you all for your valuable feedback on the book chapters - much appreciated. We are currently in the process of updating the whole thing to Swift 4 after all for sure and for good indeed, so stay tuned. Thanks again all! :]

[Next page](https://forums.kodeco.com/t/errata-for-swift-apprentice-v1-3/11916.md?page=2)
