मैं है इस अभिव्यक्ति जो रिटर्न एक UInt32
:स्विफ्ट परिवर्तित uint Int को
let randomLetterNumber = arc4random()%26
मैं बयान करता है, तो इस में नंबर का उपयोग करने में सक्षम होना चाहते:
if letters.count > randomLetterNumber{
var randomLetter = letters[randomLetterNumber]
}
यह समस्या है कि है सांत्वना मुझे इस
Playground execution failed: error: <REPL>:11:18: error: could not find an overload for '>' that accepts the supplied arguments
if letters.count > randomLetterNumber{
~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~
समस्या दे रहा है कि UInt32
नहीं कर सकता है Int
से तुलना की जा सकती है। मैं randomLetterNumber
को Int
पर डालना चाहता हूं। मैंने कोशिश की है:
let randomLetterUNumber : Int = arc4random()%26
let randomLetterUNumber = arc4random()%26 as Int
ये दोनों कारण could not find an overload for '%' that accepts the supplied arguments.
मैं मूल्य डाल सकता कैसे या यदि बयान में इसका इस्तेमाल करते हैं?
इसके लिए धन्यवाद, Int() प्रारंभकर्ता चाल चल रहा है। – 68cherries
आप ** [ऐप्पल के स्विफ्ट डॉक्स] में संख्यात्मक प्रकार के रूपांतरण के बारे में अधिक पढ़ सकते हैं (https://developer.apple.com/library/prerelease/ios/documentation/swift/conceptual/swift_programming_language/TheBasics.html#//apple_ref/ डॉक/यूआईडी/TP40014097-CH5-XID_420) **। –
धन्यवाद। मुझे arc4random_uniform (someArray.count) के साथ एक ही समस्या थी कास्टिंग समस्या arc4random_uniform (UInt32 (someArray.count) को हल करता है) – nacross