2016-07-19 13 views
11

वर्तमान में उपलब्ध नहीं है, मैं लाइन'advancedBy' Xcode 8

let range = key.startIndex...key.startIndex.advancedBy(0) 

पर XCode 8 का उपयोग किया गया है और मैं त्रुटि मिलती है:

error: 'advancedBy' is unavailable: To advance an index by n steps call 'index(_:offsetBy:)' on the CharacterView instance that produced the index.

मैं इसे कैसे ठीक कर सकते हैं?

त्रुटि का स्क्रीनशॉट नीचे है:

advancedBy is unavailable

+1

प्रश्न में अपने कोड के साथ-साथ स्क्रीनशॉट शामिल करें। – Paulw11

+1

आपको इंडेक्स ऑफसेट का उपयोग करने की आवश्यकता है http://stackoverflow.com/a/38215613/2303865 –

+0

https://github.com/apple/swift-evolution/blob/master/proposals/0065-collections-move-indices देखें। md – HAS

उत्तर

0

आप बस एक नया स्ट्रिंग के निर्माण के बजाय पुराने एक चालाकी करके प्राप्त कर सकते हैं आप अधिक के बाद क्या कर रहे हैं:

let upperCasedFirstCharacter = String(key.characters.first!).uppercased() 

let remainder = key.substring(from: key.characters.index(after: key.characters.startIndex)) 

let selector = "set\(upperCasedFirstCharacter)\(remainder)" 
18

advancedBy(_:) स्विफ्ट v3 में बहिष्कृत किया गया है और index(_:offsetBy:) द्वारा प्रतिस्थापित किया गया है। अधिक जानकारी के लिए ऐप्पल के migration guide का संदर्भ लें।

अपने त्रुटि का हल:

let range = key.startIndex...key.index(key.startIndex, offsetBy: 0) 
संबंधित मुद्दे