Skip to content

Commit af42c38

Browse files
committed
Updates to bring up to date with XCode6 Beta5
1 parent 8592722 commit af42c38

File tree

27 files changed

+81
-147
lines changed

27 files changed

+81
-147
lines changed

10. Properties.playground/section-1.swift

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,9 @@ rangeOfThreeItems.firstValue = 6
2828
//
2929
// A Lazy Stored Property is a value that is not calculated until its first use.
3030
//
31-
// They are declared using the "@lazy" attribute and may not be constant.
31+
// They are declared using the "lazy" attribute and may not be constant.
3232
//
33-
// Global and local variables are all lazy, except that they don't need the @lazy attribute.
33+
// Global and local variables are all lazy, except that they don't need the lazy attribute.
3434
//
3535
// Here, we'll define a couple classes to showcase Lazy Stored Properties. In this example, let's
3636
// assume that DataImporter is a time-consuming process, and as such, we will want to use a lazy
@@ -43,14 +43,14 @@ class DataImporter
4343

4444
class DataManager
4545
{
46-
@lazy var importer = DataImporter()
46+
lazy var importer = DataImporter()
4747
var data = [String]()
4848
}
4949

5050
// Now let's instantiate the data manager and add some simple data to the class:
5151
let manager = DataManager()
52-
manager.data += "Some data"
53-
manager.data += "Some more data"
52+
manager.data.append("Some data")
53+
manager.data.append("Some more data")
5454

5555
// Notice how we haven't used the importer yet, so it is nil:
5656
manager
@@ -298,3 +298,4 @@ class SomeClass
298298
// This is read-only, but you can also do read/write
299299
class var computedTypeProperty: Int { return 4 }
300300
}
301+

10. Properties.playground/timeline.xctimeline

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
version = "3.0">
44
<TimelineItems>
55
<LoggerValueHistoryTimelineItem
6-
documentLocation = "#CharacterRangeLen=0&amp;CharacterRangeLoc=10168&amp;EndingColumnNumber=5&amp;EndingLineNumber=2&amp;StartingColumnNumber=4&amp;StartingLineNumber=2&amp;Timestamp=424364807.022397">
6+
documentLocation = "#CharacterRangeLen=0&amp;CharacterRangeLoc=10176&amp;EndingColumnNumber=5&amp;EndingLineNumber=2&amp;StartingColumnNumber=4&amp;StartingLineNumber=2&amp;Timestamp=429121248.87547">
77
</LoggerValueHistoryTimelineItem>
88
</TimelineItems>
99
</Timeline>

13. Inheritance.playground/section-1.swift

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ class Vehicle
3131
class Bicycle: Vehicle
3232
{
3333
// We'll make this a 2-wheeled vehicle
34-
init()
34+
override init()
3535
{
3636
super.init()
3737
numberOfWheels = 2
@@ -46,7 +46,7 @@ bicycle.description()
4646
class Tandem: Bicycle
4747
{
4848
// This bicycle has 2 passengers
49-
init()
49+
override init()
5050
{
5151
super.init()
5252
maxPassengers = 2
@@ -61,7 +61,7 @@ class Car: Vehicle
6161
var speed: Double = 0.0
6262

6363
// New initialization, starting with super.init()
64-
init()
64+
override init()
6565
{
6666
super.init()
6767
maxPassengers = 5
@@ -143,21 +143,21 @@ automaticCar.gear
143143
// ------------------------------------------------------------------------------------------------
144144
// Preenting Overrides
145145
//
146-
// We can prevent a subclass from overriding a particular method or property using the '@final'
146+
// We can prevent a subclass from overriding a particular method or property using the 'final'
147147
// keyword.
148148
//
149-
// @final can be applied to: class, var, func, class methods and subscripts
149+
// final can be applied to: class, var, func, class methods and subscripts
150150
//
151151
// Here, we'll prevent an entire class from being subclassed by applying the . Because of this,
152-
// the @finals inside the class are not needed, but are present for descriptive purposes. These
153-
// additional @finals may not compile in the future, but they do today:
154-
@final class AnotherAutomaticCar: Car
152+
// the finals inside the class are not needed, but are present for descriptive purposes. These
153+
// additional finals may not compile in the future, but they do today:
154+
final class AnotherAutomaticCar: Car
155155
{
156156
// This variable cannot be overridden
157-
@final var gear = 1
157+
final var gear = 1
158158

159159
// We can even prevent overridden functions from being further refined
160-
@final override var speed: Double
160+
final override var speed: Double
161161
{
162162
didSet { gear = Int(speed / 10.0) + 1 }
163163
}

13. Inheritance.playground/timeline.xctimeline

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
version = "3.0">
44
<TimelineItems>
55
<LoggerValueHistoryTimelineItem
6-
documentLocation = "#CharacterRangeLen=0&amp;CharacterRangeLoc=4410&amp;EndingColumnNumber=5&amp;EndingLineNumber=7&amp;StartingColumnNumber=4&amp;StartingLineNumber=7&amp;Timestamp=424369866.603036">
6+
documentLocation = "#CharacterRangeLen=0&amp;CharacterRangeLoc=4430&amp;EndingColumnNumber=5&amp;EndingLineNumber=7&amp;StartingColumnNumber=4&amp;StartingLineNumber=7&amp;Timestamp=429121270.152136">
77
</LoggerValueHistoryTimelineItem>
88
</TimelineItems>
99
</Timeline>

14b. Initializer Chaining.playground/section-1.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ class RecipeIngredient: Food
9595
// Here, we'll create a convenience initializer that simply provides a default quantity
9696
// value of 1. Note that in order for this to compile, we are required to call a designated
9797
// initializer.
98-
convenience init(name: String)
98+
convenience override init(name: String)
9999
{
100100
self.init(name: name, quantity: 1)
101101
}
@@ -118,7 +118,7 @@ class ShoppingListItem: RecipeIngredient
118118
var purchased = false
119119
var description: String
120120
{
121-
var output = "\(quantity) x \(name.lowercaseString)"
121+
var output = "\(quantity) x \(name)"
122122
output += purchased ? "" : ""
123123
return output
124124
}

14b. Initializer Chaining.playground/timeline.xctimeline

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
version = "3.0">
44
<TimelineItems>
55
<LoggerValueHistoryTimelineItem
6-
documentLocation = "#CharacterRangeLen=0&amp;CharacterRangeLoc=7459&amp;EndingColumnNumber=5&amp;EndingLineNumber=26&amp;StartingColumnNumber=4&amp;StartingLineNumber=26&amp;Timestamp=424379045.424535">
6+
documentLocation = "#CharacterRangeLen=0&amp;CharacterRangeLoc=7452&amp;EndingColumnNumber=5&amp;EndingLineNumber=26&amp;StartingColumnNumber=4&amp;StartingLineNumber=26&amp;Timestamp=429121086.671912">
77
</LoggerValueHistoryTimelineItem>
88
</TimelineItems>
99
</Timeline>

16. ARC.playground/section-1.swift

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -276,16 +276,16 @@ var america = Country(name: "USA", capitalName: "Washington DC")
276276
// Let's see how this problem can manifest. We'll create a class that represents an HTML element
277277
// which includes a variable (asHTML) which stores a reference to a closure.
278278
//
279-
// Quick note: The asHTML variable is defined as @lazy so that it can reference 'self' within the
280-
// closure. Try removing the '@lazy' and you'll see that you get an error trying to access 'self'.
279+
// Quick note: The asHTML variable is defined as lazy so that it can reference 'self' within the
280+
// closure. Try removing the 'lazy' and you'll see that you get an error trying to access 'self'.
281281
// This is an error because we're not allowed to access 'self' during Phase 1 initialization. By
282-
// making 'asHTML' @lazy, we solve this problem by deferring its initialization until later.
282+
// making 'asHTML' lazy, we solve this problem by deferring its initialization until later.
283283
class HTMLElement
284284
{
285285
let name: String
286286
let text: String?
287287

288-
@lazy var asHTML: () -> String =
288+
lazy var asHTML: () -> String =
289289
{
290290
if let text = self.text
291291
{
@@ -321,7 +321,7 @@ paragraph = nil
321321
//
322322
// Here's how we define a capture list:
323323
//
324-
// @lazy var someClosure: (Int, String) -> String =
324+
// lazy var someClosure: (Int, String) -> String =
325325
// {
326326
// [unowned self] (index: Int, stringToProcess: String) -> String in
327327
//
@@ -332,7 +332,7 @@ paragraph = nil
332332
// may not have any parameters. In both cases the method for declaring the capture list doesn't
333333
// change much. Simply include the capture list followed by the 'in' keyword:
334334
//
335-
// @lazy var someClosure: () -> String =
335+
// lazy var someClosure: () -> String =
336336
// {
337337
// [unowned self] in
338338
//
@@ -347,7 +347,7 @@ class FixedHTMLElement
347347
let name: String
348348
let text: String?
349349

350-
@lazy var asHTML: () -> String =
350+
lazy var asHTML: () -> String =
351351
{
352352
[unowned self] in
353353
if let text = self.text

16. ARC.playground/timeline.xctimeline

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
version = "3.0">
44
<TimelineItems>
55
<LoggerValueHistoryTimelineItem
6-
documentLocation = "#CharacterRangeLen=0&amp;CharacterRangeLoc=14330&amp;EndingColumnNumber=5&amp;EndingLineNumber=17&amp;StartingColumnNumber=4&amp;StartingLineNumber=17&amp;Timestamp=424544773.38719">
6+
documentLocation = "#CharacterRangeLen=0&amp;CharacterRangeLoc=14323&amp;EndingColumnNumber=5&amp;EndingLineNumber=17&amp;StartingColumnNumber=4&amp;StartingLineNumber=17&amp;Timestamp=429121230.809536">
77
</LoggerValueHistoryTimelineItem>
88
</TimelineItems>
99
</Timeline>

1a. The Basics.playground/section-1.swift

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,13 +56,12 @@ let π = 3.14159
5656
let 你好 = "你好世界"
5757
let 🐶🐮 = "dogcow"
5858

59-
// You can print a value using println (this doesn't do anything in a playground, though)
59+
// You can print a value using println
6060
let fiveHundred = 500
6161
println("The current value of fiveHundred is: \(fiveHundred)")
6262

63-
// Since println doesn't work in Playgrounds, we'll just put the raw string on the line
64-
// which is an expression that evaluates to itself, printing the result in the right-hand
65-
// pane in the playground, like so:
63+
// Since we're using Playgrounds, we'll just put the raw string on the line which is an expression
64+
// that evaluates to itself, printing the result in the right-hand pane in the playground, like so:
6665
"The current value of fiveHundred is: \(fiveHundred)"
6766

6867
// ------------------------------------------------------------------------------------------------

1a. The Basics.playground/timeline.xctimeline

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33
version = "3.0">
44
<TimelineItems>
55
<LoggerValueHistoryTimelineItem
6-
documentLocation = "#CharacterRangeLen=0&amp;CharacterRangeLoc=8885&amp;EndingColumnNumber=5&amp;EndingLineNumber=4&amp;StartingColumnNumber=4&amp;StartingLineNumber=4&amp;Timestamp=424673361.066013">
6+
documentLocation = "#CharacterRangeLen=0&amp;CharacterRangeLoc=8819&amp;EndingColumnNumber=5&amp;EndingLineNumber=4&amp;StartingColumnNumber=4&amp;StartingLineNumber=4&amp;Timestamp=429119882.388055">
77
</LoggerValueHistoryTimelineItem>
88
<LoggerValueHistoryTimelineItem
9-
documentLocation = "#CharacterRangeLen=17&amp;CharacterRangeLoc=8062&amp;EndingColumnNumber=21&amp;EndingLineNumber=224&amp;StartingColumnNumber=4&amp;StartingLineNumber=224&amp;Timestamp=424673361.066013">
9+
documentLocation = "#CharacterRangeLen=17&amp;CharacterRangeLoc=7996&amp;EndingColumnNumber=21&amp;EndingLineNumber=223&amp;StartingColumnNumber=4&amp;StartingLineNumber=223&amp;Timestamp=429119882.388055">
1010
</LoggerValueHistoryTimelineItem>
1111
</TimelineItems>
1212
</Timeline>

1d. Optionals.playground/section-1.swift

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,9 @@
88
// ------------------------------------------------------------------------------------------------
99

1010
// An optional declaration adds a "?" immediately after the explicit type. The following line
11-
// defines a value 'someOptional' that can either hold an Int or no value at all:
12-
let someOptional: Int?
11+
// defines a value 'someOptional' that can either hold an Int or no value at all. In this case
12+
// we set an optional Int value to .None (similar to nil)
13+
let someOptional: Int? = .None
1314

1415
// Let's try to convert a String to an Int
1516
//
@@ -43,8 +44,8 @@ let unwrapped = optionalConvertedNumber // 'unwrapped' is another optional
4344
// let's not let that stop us from learning this little detail.
4445
//
4546
// These two lines are of equivalent types:
46-
let optionalA: String?
47-
let optionalB: Optional<String>
47+
let optionalA: String? = .None
48+
let optionalB: Optional<String> = .None
4849

4950
// ------------------------------------------------------------------------------------------------
5051
// Unwrapping
@@ -64,7 +65,7 @@ let unwrappedInt = optionalConvertedNumber!
6465
// Implicit unwrapping isn't very safe because if the optional doesn't hold a value, it will
6566
// generate a runtime error. To verify that is's safe, you can check the optional with an if
6667
// statement.
67-
if optionalConvertedNumber
68+
if optionalConvertedNumber != .None
6869
{
6970
// It's now safe to force-unwrap because we KNOW it has a value
7071
let anotherUnwrappedInt = optionalConvertedNumber!
@@ -103,7 +104,7 @@ if let optionalIntValue:Int? = optionalConvertedNumber
103104
// 'optionalIntValue' is still an optional, but it's known to be safe. We can still check
104105
// it here, though, because it's still an optional. If it weren't optional, this if statement
105106
// wouldn't compile:
106-
if optionalIntValue
107+
if optionalIntValue != .None
107108
{
108109
// 'optionalIntValue' is optional, so we still use the force-unwrap here:
109110
"intValue is optional, but has the value \(optionalIntValue!)"
@@ -114,7 +115,7 @@ if let optionalIntValue:Int? = optionalConvertedNumber
114115
optionalConvertedNumber = nil
115116

116117
// Now if we check it, we see that it holds no value:
117-
if optionalConvertedNumber
118+
if optionalConvertedNumber != .None
118119
{
119120
"optionalConvertedNumber holds a value (\(optionalConvertedNumber))! (this should not happen)"
120121
}

1d. Optionals.playground/timeline.xctimeline

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
version = "3.0">
44
<TimelineItems>
55
<LoggerValueHistoryTimelineItem
6-
documentLocation = "#CharacterRangeLen=0&amp;CharacterRangeLoc=6821&amp;EndingColumnNumber=5&amp;EndingLineNumber=2&amp;StartingColumnNumber=4&amp;StartingLineNumber=2&amp;Timestamp=428937322.498252">
6+
documentLocation = "#CharacterRangeLen=0&amp;CharacterRangeLoc=6943&amp;EndingColumnNumber=5&amp;EndingLineNumber=2&amp;StartingColumnNumber=4&amp;StartingLineNumber=2&amp;Timestamp=429120028.697866">
77
</LoggerValueHistoryTimelineItem>
88
</TimelineItems>
99
</Timeline>

1e. Assertions.playground/section-1.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
// ------------------------------------------------------------------------------------------------
88

99
// Let's start with a value...
10-
let age = 3;
10+
let age = 3
1111

1212
// You can assert with a message
1313
assert(age >= 0, "A person's age cannot be negative")

1e. Assertions.playground/timeline.xctimeline

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
version = "3.0">
44
<TimelineItems>
55
<LoggerValueHistoryTimelineItem
6-
documentLocation = "#CharacterRangeLen=0&amp;CharacterRangeLoc=577&amp;EndingColumnNumber=5&amp;EndingLineNumber=2&amp;StartingColumnNumber=4&amp;StartingLineNumber=2&amp;Timestamp=424294298.504034">
6+
documentLocation = "#CharacterRangeLen=0&amp;CharacterRangeLoc=576&amp;EndingColumnNumber=5&amp;EndingLineNumber=2&amp;StartingColumnNumber=4&amp;StartingLineNumber=2&amp;Timestamp=429120071.699096">
77
</LoggerValueHistoryTimelineItem>
88
</TimelineItems>
99
</Timeline>

20. Extensions.playground/section-1.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ extension Int
141141
subscript(digitIndex: Int) -> Int
142142
{
143143
var decimalBase = 1
144-
for _ in 1...digitIndex
144+
for _ in 0 ..< digitIndex
145145
{
146146
decimalBase *= 10
147147
}
@@ -170,7 +170,7 @@ extension Character
170170
}
171171
var kind: Kind
172172
{
173-
switch String(self).lowercaseString
173+
switch String(self)
174174
{
175175
case "a", "e", "i", "o", "u":
176176
return .Vowel

20. Extensions.playground/timeline.xctimeline

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
version = "3.0">
44
<TimelineItems>
55
<LoggerValueHistoryTimelineItem
6-
documentLocation = "#CharacterRangeLen=0&amp;CharacterRangeLoc=5391&amp;EndingColumnNumber=5&amp;EndingLineNumber=2&amp;StartingColumnNumber=4&amp;StartingLineNumber=2&amp;Timestamp=424630267.973389">
6+
documentLocation = "#CharacterRangeLen=0&amp;CharacterRangeLoc=5377&amp;EndingColumnNumber=5&amp;EndingLineNumber=2&amp;StartingColumnNumber=4&amp;StartingLineNumber=2&amp;Timestamp=429121495.027786">
77
</LoggerValueHistoryTimelineItem>
88
</TimelineItems>
99
</Timeline>

21. Protocols.playground/section-1.swift

Lines changed: 6 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ class Starship: FullyNamed
8585

8686
var fullName: String
8787
{
88-
return (prefix ? prefix! + " " : "") + name
88+
return (prefix != .None ? prefix! + " " : "") + name
8989
}
9090
}
9191

@@ -357,7 +357,7 @@ objects[2] is HasArea
357357
// Optional Protocol Requirements
358358
//
359359
// Sometimes it's convenient to declare protocols that have one or more requirements that are
360-
// optional. This is done by prefixing those requirements with the '@optional' keyword.
360+
// optional. This is done by prefixing those requirements with the 'optional' keyword.
361361
//
362362
// The term "optional protocol" refers to protocols that are optional in a very similar since to
363363
// optionals we've seen in the past. However, rather than stored values that can be nil, they
@@ -372,17 +372,17 @@ objects[2] is HasArea
372372
// * In order to check if an instance of a class conforms to a given protocol, that protocol must
373373
// be declared with the @objc attribute.
374374
//
375-
// * This is also the case with optional requirements in protocols. In order to use the @optional
376-
// attribute, the protocol must be declared with the @objc attribute.
375+
// * This is also the case with optional requirements in protocols. In order to use the optional
376+
// declaration modifier, the protocol must be declared with the @objc attribute.
377377
//
378378
// * Additionally, any class, structure or enumeration that owns an instance that conforms to a
379379
// protocol declared with the @objc attribute must also be declared with the @objc attribute.
380380
//
381381
// Here's another simple protocol that uses optional requrements:
382382
@objc protocol CounterDataSource
383383
{
384-
@optional func incrementForCount(count: Int) -> Int
385-
@optional var fixedIncrement: Int { get }
384+
optional func incrementForCount(count: Int) -> Int
385+
optional var fixedIncrement: Int { get }
386386
}
387387

388388
// In the class below, we'll see that checking to see if an instance conforms to a specific
@@ -406,20 +406,3 @@ objects[2] is HasArea
406406
}
407407
}
408408
}
409-
410-
411-
412-
413-
414-
415-
416-
417-
418-
419-
420-
421-
422-
423-
424-
425-

21. Protocols.playground/timeline.xctimeline

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
version = "3.0">
44
<TimelineItems>
55
<LoggerValueHistoryTimelineItem
6-
documentLocation = "#CharacterRangeLen=0&amp;CharacterRangeLoc=13079&amp;EndingColumnNumber=5&amp;EndingLineNumber=2&amp;StartingColumnNumber=4&amp;StartingLineNumber=2&amp;Timestamp=424650306.321352">
6+
documentLocation = "#CharacterRangeLen=0&amp;CharacterRangeLoc=13078&amp;EndingColumnNumber=5&amp;EndingLineNumber=2&amp;StartingColumnNumber=4&amp;StartingLineNumber=2&amp;Timestamp=429121693.645013">
77
</LoggerValueHistoryTimelineItem>
88
</TimelineItems>
99
</Timeline>

0 commit comments

Comments
 (0)