2014-12-11 4 views

उत्तर

11

आप हेडर पर गौर करते हैं, तो आपको लगता है कि देखेंगे:

let closureA:() ->() 

और

let closureB:() -> Void 
+0

"हेडर में देखें" क्या आपके पास एक संदर्भ होना है जहां यह विशेष रूप से पाया जा सकता है? –

0

सभी

Void में कोई अंतर नहीं है() के लिए एक उपनाम है शून्य(),

के लिए टाइपियास है
/// The empty tuple type. 
/// 
/// This is the default return type of functions for which no explicit 
/// return type is specified. 
typealias Void =() 

आप सत्यापित कर सकते हैं कि इस तरह खेल का मैदान,

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

अद्यतन का उपयोग कर

आप हेडर फाइल में शून्य की घोषणा को देखने के लिए, उपरोक्त कोड में चाहते हैं, तो नीचे दिए गए कोड लिखें स्विफ्ट प्लेग्राउंड या एक्सकोड एडिटर में,

let a: Void = () 

फिर, cmd + उपर्युक्त अभिव्यक्ति में "शून्य" कीवर्ड पर क्लिक करें, आप करेंगे हेडर फ़ाइल में ले जाया जा सकता है जहां आप वास्तव में शून्य के लिए घोषणा देख सकते हैं।

दस्तावेज़ में अधिक जानकारी है जो इस तरह है के साथ अद्यतन किया गया है,

/// 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

ही। यह सिर्फ एक टाइपियास है इसलिए यह बिल्कुल वही काम करता है।

typealias Void =() 

एरिका Sadun और एप्पल की तरह लगता है शून्य के साथ छड़ी की कोशिश कर रहे: http://ericasadun.com/2015/05/11/swift-vs-void/

संबंधित मुद्दे