เนื่องจากฟังก์ชั่นใน Swift เป็น Type เราสามารถประกาศตัวแปรที่มี Type เป็น function ได้ เช่น
การใช้ Function Type มีข้อจำกัดอยู่ตรงที่ Function Type จะไม่สามารถมี Argument label ได้ จากตัวอย่างก่อนหน้า จะเห็นว่าเราเรียก hello("Pop", "Bangkok") โดยไม่มีการระบุ argument label สำหรับแต่ละ input
เหตุผลที่ทำให้ไม่สามารถใช้ argument labels กับ function types ดูเพิ่มเติมได้ที่ Swift evolution: 0111
และด้วยความที่ฟังก์ชั่นก็เป็น Type ทำให้เราสามารถส่ง ฟังก์ชั่นเป็น input ของฟังก์ชั่นได้ด้วย เช่น
func greet(person: String, from hometown: String) -> String {
return "Hello \(person)! from \(hometown)."
}
(String, String) -> String
var hello: (String, String) -> String = greet
// can also use like this
// var hello: (String, String) -> String = greet(person:from:)
hello("Pop", "Bangkok")