In Python, you can give the name of a class as an argument to map
in order to create instances of that class:
class Point(object):
def __init__(
Filing bugs works!
In Swift 2 this is now possible with coords.map(Point.init)
:
Old answer:
- is it because init is not a func?
Yep. In Swift, a function type "consists of a parameter and return type separated by an arrow (->
)", and map
is defined as func map(transform: (T) -> U) -> [U]
, i.e. it takes in a function. In the grammar, "function declaration" and "initializer declaration" are treated separately. The latter doesn't have a return type because it's not really a function, just a block of code used to initialize instances. And if you try to pass Point.init
, you'll get the error "Initializer cannot be referenced without arguments".
File a bug!