Skip to main content
AI Assist is now on Stack Overflow. Start a chat to get instant answers from across the network. Sign up to save and share your chats.
added 98 characters in body
Source Link
PeterPan
  • 744
  • 1
  • 12
  • 28

EDIT: I'm aware that I was using the wrong Xcode version for Swift 2, now. Problem solved.

I'm following the Swift 2 book from Apple. At a point there's the following example:

 import Foundation func hasAnyMatches(list: [Int], condition: Int -> Bool) -> Bool { for item in list { if condition(item) { return true } } return false } func lessThanTen(number: Int) -> Bool { return number < 10 } var numbers = [20, 19, 7, 12] hasAnyMatches(numbers, condition: lessThanTen) 

What I think is weird is the last line. Why does it say condition: lessThanTen and not just lessThanTen? My compiler (Xcode) also gives me an error doing it the way it's shown in the book.

Also: why does it only say list: [Int] in the third line but condition: Int -> Bool? Why not something like list: [Int] -> Int?

I'm following the Swift 2 book from Apple. At a point there's the following example:

 import Foundation func hasAnyMatches(list: [Int], condition: Int -> Bool) -> Bool { for item in list { if condition(item) { return true } } return false } func lessThanTen(number: Int) -> Bool { return number < 10 } var numbers = [20, 19, 7, 12] hasAnyMatches(numbers, condition: lessThanTen) 

What I think is weird is the last line. Why does it say condition: lessThanTen and not just lessThanTen? My compiler (Xcode) also gives me an error doing it the way it's shown in the book.

Also: why does it only say list: [Int] in the third line but condition: Int -> Bool? Why not something like list: [Int] -> Int?

EDIT: I'm aware that I was using the wrong Xcode version for Swift 2, now. Problem solved.

I'm following the Swift 2 book from Apple. At a point there's the following example:

 import Foundation func hasAnyMatches(list: [Int], condition: Int -> Bool) -> Bool { for item in list { if condition(item) { return true } } return false } func lessThanTen(number: Int) -> Bool { return number < 10 } var numbers = [20, 19, 7, 12] hasAnyMatches(numbers, condition: lessThanTen) 

What I think is weird is the last line. Why does it say condition: lessThanTen and not just lessThanTen? My compiler (Xcode) also gives me an error doing it the way it's shown in the book.

Also: why does it only say list: [Int] in the third line but condition: Int -> Bool? Why not something like list: [Int] -> Int?

edited tags
Link
rmaddy
  • 319.5k
  • 44
  • 548
  • 591
I corrected "day" since the user meant to say "way" in all likelihood. I also fixed the grammar of a question.
Source Link

I'm following the Swift 2 book from Apple. At a point there's the following example:

 import Foundation func hasAnyMatches(list: [Int], condition: Int -> Bool) -> Bool { for item in list { if condition(item) { return true } } return false } func lessThanTen(number: Int) -> Bool { return number < 10 } var numbers = [20, 19, 7, 12] hasAnyMatches(numbers, condition: lessThanTen) 

What I think is weird is the last line. Why does it say condition: lessThanTen and not just lessThanTen? My compiler (Xcode) also gives me an error doing it the dayway it's shown in the book.

Also: why does it only say just list: [Int] in the third line but condition: Int -> Bool? Why not something like list: [Int] -> Int?

I'm following the Swift 2 book from Apple. At a point there's the following example:

 import Foundation func hasAnyMatches(list: [Int], condition: Int -> Bool) -> Bool { for item in list { if condition(item) { return true } } return false } func lessThanTen(number: Int) -> Bool { return number < 10 } var numbers = [20, 19, 7, 12] hasAnyMatches(numbers, condition: lessThanTen) 

What I think is weird is the last line. Why does it say condition: lessThanTen and not just lessThanTen? My compiler (Xcode) also gives me an error doing it the day it's shown in the book.

Also: why does it say just list: [Int] in the third line but condition: Int -> Bool? Why not something like list: [Int] -> Int?

I'm following the Swift 2 book from Apple. At a point there's the following example:

 import Foundation func hasAnyMatches(list: [Int], condition: Int -> Bool) -> Bool { for item in list { if condition(item) { return true } } return false } func lessThanTen(number: Int) -> Bool { return number < 10 } var numbers = [20, 19, 7, 12] hasAnyMatches(numbers, condition: lessThanTen) 

What I think is weird is the last line. Why does it say condition: lessThanTen and not just lessThanTen? My compiler (Xcode) also gives me an error doing it the way it's shown in the book.

Also: why does it only say list: [Int] in the third line but condition: Int -> Bool? Why not something like list: [Int] -> Int?

Source Link
PeterPan
  • 744
  • 1
  • 12
  • 28
Loading