निम्नलिखित कोड पुराने स्विफ्ट के साथ पूरी तरह से काम किया गया था। इस स्ट्रिंगस्विफ्ट -3 त्रुटि: '- [_ स्विफ्टवैल्यू unsignedIntegerValue]: अपरिचित चयनकर्ता
func stringByConvertingHTML() -> String {
let newString = replacingOccurrences(of: "\n", with: "<br>")
if let encodedData = newString.data(using: String.Encoding.utf8) {
let attributedOptions : [String: AnyObject] = [
NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType as AnyObject,
NSCharacterEncodingDocumentAttribute: String.Encoding.utf8 as AnyObject
]
do {
let attributedString = try NSAttributedString(data: encodedData, options: attributedOptions, documentAttributes: nil) //Crash here
return attributedString.string
} catch {
return self
}
}
return self
}
का ही विस्तार लेकिन तेजी से 3 में यह कह क्रैश
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[_SwiftValue unsignedIntegerValue]: unrecognized selector sent to instance 0x6080002565f0'
किसी को भी मुझे सुझाव दें क्या करने की ज़रूरत है?
धन्यवाद यह ठीक काम कर रहा है बदल दिया है। लेकिन यह 'NSNumber (मान: String.Encoding.utf8.rawValue)' –
लाइफसेवर होगा! (पीएस: एनएसएनंबर (..) को काम करने के लिए भी जरूरी है, क्या आप इसका जवाब देने के लिए उत्तर अपडेट कर सकते हैं?) – Marchy
आपको केवल 'स्ट्रिंग.इन्कोडिंग.यूटीएफ 8.rawValue' की आवश्यकता होनी चाहिए, क्योंकि स्विफ्ट स्वचालित रूप से' Int ' और 'NSNT'' NSNumber की 'जब एक स्विफ्ट शब्दकोश को' NSDictionary' की अपेक्षा रखने वाले फ़ंक्शन में पास किया जाता है। हालांकि इसके लिए स्विफ्ट शब्दकोश को '[स्ट्रिंग: कोई भी]' सरणी होने की आवश्यकता होगी। यह भी देखें [यह] (https://developer.apple.com/swift/blog/?id=39) स्विफ्ट ब्लॉग प्रविष्टि। – MaddTheSane