What is the syntax of the close argument in swift

In Swift headers, argument isSeparator:accepts closure

public func split(maxSplit: Int = default, allowEmptySlices: Bool = default, @noescape isSeparator: (Self.Generator.Element) throws -> Bool) rethrows -> [Self.SubSequence]

But in the documentation, it displays the closure syntax differently

{ (parameters) -> return type in
    statements
}

How should you know what (Self.Generator.Element) throws -> Bool rethrowsrelates to closure / requires closure? Are there other ways that headers / documents can indicate an argument as a closing value?

+4
source share
3 answers

The “thing” giving that this closure is this ->. Full type

(Self.Generator.Element) throws -> Bool

, Self.Generator.Element a Bool . , - , .

{ (parameters) -> return type in
    statements
}

, .

, , (someInt:Int, someDouble:Double) -> String:

var a : ((someInt:Int, someDouble:Double) -> String)

, , a , -> .

- a , :

a = { (integer, floating) -> String in
    return "\(integer) \(floating)"
}
+6

. Swift , .

, ...

func add(a: Int, to b: Int) -> Int { return a + b }

... (Int, Int) -> Int. ( Int Int.)

...

let identity: Int -> Int = { $0 }

... Int -> Int.

, ->, . , (, isSeparator), ->, , .

+2

isSeparator (Self.Generator.Element) throws -> Bool, , Bool. split, :

[1,2,3].split(…, isSeparator : { element -> Bool in 
    return false 
})

, .

+1

Source: https://habr.com/ru/post/1623349/


All Articles