2014-06-20 10 views
7

ऑब्जेक्टिव-सी में इस काम करता है ठीकतेजी से Enum की तुलना कैसे करें?

enter image description here

आईओएस में

enter image description here

या

enter image description here

ALAuthorizationStatus परिभाषा स्विफ्ट में इस संकलन नहीं कर सकते एसडीके

enum ALAuthorizationStatus : Int { 
    case NotDetermined // User has not yet made a choice with regards to this application 
    case Restricted // This application is not authorized to access photo data. 
    // The user cannot change this application’s status, possibly due to active restrictions 
    // such as parental controls being in place. 
    case Denied // User has explicitly denied this application access to photos data. 
    case Authorized // User has authorized this application to access photos data. 
} 
+1

कृपया हमें अपनी enum परिभाषा दिखाएं। आईओएस एसडीके से – Alexander

+1

एसेट्स लाइब्रेरी – Charlie

उत्तर

3

तुलना ऑपरेटर == एक Bool, नहीं Boolean देता है। निम्नलिखित compiles:

func isAuthorized() -> Bool { 
    let status = ALAssetsLibrary.authorizationStatus() 
    return status == ALAuthorizationStatus.Authorized 
} 

(। व्यक्तिगत रूप से, मैं स्विफ्ट संकलक से त्रुटि संदेश कभी कभी संशय है इस मामले में, समस्या == का तर्क, लेकिन गलत वापसी प्रकार नहीं था।)


वास्तव में, निम्नलिखित भी स्वत: प्रकार निष्कर्ष की वजह से संकलन करना चाहिए:

func isAuthorized() -> Bool { 
    let status = ALAssetsLibrary.authorizationStatus() 
    return status == .Authorized 
} 

लेकिन यह संकलक त्रुटि जब तक आप स्पष्ट status चर का प्रकार निर्दिष्ट , "नहीं सदस्य 'अधिकृत' खोजा जा सका" के साथ विफल रहता है:

func isAuthorized() -> Bool { 
    let status:ALAuthorizationStatus = ALAssetsLibrary.authorizationStatus() 
    return status == .Authorized 
} 

यह वर्तमान स्विफ्ट में एक बग हो सकता है कंपाइलर (एक्सकोड 6 बीटा 1 के साथ परीक्षण किया गया)।

अद्यतन: पहला संस्करण अब एक्सकोड 6.1 में संकलित करता है।

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