2014-12-11 14 views

Odpowiedz

11

Jeśli spojrzeć na nagłówki, widać, że Void to typealias for(),

/// The empty tuple type. 
/// 
/// This is the default return type of functions for which no explicit 
/// return type is specified. 
typealias Void =() 

Można sprawdzić, że za pomocą zabaw jak ten,

let a = Void() 
println(a) // prints () 

Aktualizacja

Jeśli chcesz zobaczyć deklarację Pustki w pliku nagłówka, w powyższym kodzie, wpisz kod poniżej w szybkim zabaw lub edytorze xcode jak tak,

let a: Void = () 

Następnie cmd + kliknięcie na „void” słowo kluczowe w powyższym wyrażeniu, pokochasz zostanie przeniesiony do pliku nagłówkowego, gdzie faktycznie można zobaczyć deklarację dla Void.

Dokument został zaktualizowany z większą ilością informacji, który jest podobny do tego,

/// The return type of functions that don't explicitly specify a return type; 
/// an empty tuple (i.e., `()`). 
/// 
/// When declaring a function or method, you don't need to specify a return 
/// type if no value will be returned. However, the type of a function, 
/// method, or closure always includes a return type, which is `Void` if 
/// otherwise unspecified. 
/// 
/// Use `Void` or an empty tuple as the return type when declaring a 
/// closure, function, or method that doesn't return a value. 
/// 
///  // No return type declared: 
///  func logMessage(_ s: String) { 
///   print("Message: \(s)") 
///  } 
/// 
///  let logger: (String) -> Void = logMessage 
///  logger("This is a void function") 
///  // Prints "Message: This is a void function" 
public typealias Void =() 
+0

"Zajrzyj do nagłówków" Czy zdarza Ci się mieć odniesienie do tego, gdzie konkretnie to można znaleźć? –

0

Nie ma żadnej różnicy w ogóle

Void jest aliasem():

typealias Void =() 
Powiązane problemy