Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated to Swift 3 #7

Open
wants to merge 1 commit into
base: gh-pages
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion comparisons/basics/hello_world/swift.scala
Original file line number Diff line number Diff line change
@@ -1 +1 @@
println("Hello, world!")
print("Hello, world!")

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sort([1, 5, 3, 12, 2]) { $0 > $1 }

2 changes: 1 addition & 1 deletion comparisons/basics/inclusive_range_operator/swift.scala
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
for index in 1...5 {
println("\(index) times 5 is \(index * 5)")
print("\(index) times 5 is \(index * 5)")
}
// 1 times 5 is 5
// 2 times 5 is 10
Expand Down
4 changes: 2 additions & 2 deletions comparisons/basics/range_operator/swift.scala
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
let names = ["Anna", "Alex", "Brian", "Jack"]
let count = names.count
for i in 0..count {
println("Person \(i + 1) is called \(names[i])")
for i in 0..<count {
print("Person \(i + 1) is called \(names[i])")
}
// Person 1 is called Anna
// Person 2 is called Alex
Expand Down
6 changes: 3 additions & 3 deletions comparisons/classes/checking_type/swift.scala
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
var movieCount = 0
var songCount = 0

for item in library {
if item is Movie {
++movieCount
movieCount += 1
} else if item is Song {
++songCount
songCount += 1
}
}
2 changes: 1 addition & 1 deletion comparisons/classes/downcasting/swift.scala
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
for object in someObjects {
let movie = object as Movie
println("Movie: '\(movie.name)', dir. \(movie.director)")
print("Movie: '\(movie.name)', dir. \(movie.director)")
}
4 changes: 2 additions & 2 deletions comparisons/classes/extensions/swift.scala
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ extension Double {
var ft: Double { return self / 3.28084 }
}
let oneInch = 25.4.mm
println("One inch is \(oneInch) meters")
print("One inch is \(oneInch) meters")
// prints "One inch is 0.0254 meters"
let threeFeet = 3.ft
println("Three feet is \(threeFeet) meters")
print("Three feet is \(threeFeet) meters")
// prints "Three feet is 0.914399970739201 meters"
8 changes: 4 additions & 4 deletions comparisons/classes/pattern_match/swift.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ var songCount = 0
for item in library {
switch item {
case let movie as Movie:
++movieCount
println("Movie: '\(movie.name)', dir. \(movie.director)")
movieCount += 1
print("Movie: '\(movie.name)', dir. \(movie.director)")
case let song as Song:
++songCount
println("Song: '\(song.title)'")
songCount += 1
print("Song: '\(song.title)'")
}
}
2 changes: 1 addition & 1 deletion comparisons/classes/protocol/swift.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ protocol Nameable {
}

func f<T: Nameable>(x: T) {
println("Name is " + x.name())
print("Name is " + x.name())
}
2 changes: 1 addition & 1 deletion comparisons/functions/function_type/swift.scala
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
func makeIncrementer() -> (Int -> Int) {
func makeIncrementer() -> ((Int) -> Int) {
func addOne(number: Int) -> Int {
return 1 + number
}
Expand Down
2 changes: 1 addition & 1 deletion comparisons/functions/functions/swift.scala
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
func greet(name: String, day: String) -> String {
func greet(_ name: String,_ day: String) -> String {
return "Hello \(name), today is \(day)."
}
greet("Bob", "Tuesday")
2 changes: 1 addition & 1 deletion comparisons/functions/named_arguments/swift.scala
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
func area(#width: Int, #height: Int) -> Int {
func area(width: Int, height: Int) -> Int {
return width * height
}

Expand Down
2 changes: 1 addition & 1 deletion comparisons/functions/sort/swift.scala
Original file line number Diff line number Diff line change
@@ -1 +1 @@
sort([1, 5, 3, 12, 2]) { $0 > $1 }
[1, 5, 3, 12, 2].sorted{ $0 > $1 }
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
func sumOf(numbers: Int...) -> Int {
func sumOf(_numbers: Int...) -> Int {
var sum = 0
for number in numbers {
sum += number
Expand Down