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>

0 commit comments

Comments
 (0)