मुझे स्विफ्ट में .text फ़ाइल से टेक्स्ट स्ट्रिंग पढ़ने में परेशानी हो रही है।स्विफ्ट 'स्ट्रिंग। टाइप' में 'stringWithContentsOfFile' नामक कोई सदस्य नहीं है
मैं निम्नलिखित कोड
var writeError: NSError?
let theFileToBeWritten = theStringWillBeSaved.writeToFile(pathToTheFile, atomically: true, encoding: NSUTF8StringEncoding, error: &writeError);
का उपयोग कर फ़ाइल लिखने के लिए प्रबंधन कर सकते हैं लेकिन जब भी मैं का उपयोग कर "String.stringWithContentsOfFile", मैं "फ़ाइल पढ़ने की कोशिश 'String.Type' एक सदस्य 'नाम नहीं है stringWithContentsOfFile ' "। stringWithContentsOfFile भी स्वत: पूर्ण में प्रकट नहीं होता है।
मैं Xcode 6.1 जीएम बीज 2.
मैं "stringWithContentsOfFile" का उपयोग कर कई ट्यूटोरियल में फ़ाइल से पाठ और ढेर अतिप्रवाह लेकिन क्यों यह मेरे लिए काम नहीं कर रहा पढ़ने के लिए लोगों को देखा है का उपयोग कर रहा हूँ?
var error:NSError?
let string = String(contentsOfFile: "/usr/temp.txt", encoding:NSUTF8StringEncoding, error: &error)
if let theError = error {
print("\(theError.localizedDescription)")
}
स्विफ्ट 2.2:
सही वाक्यविन्यास के साथ मदद करने के लिए धन्यवाद। मुझे यकीन नहीं है कि ऐप्पल ने अपने दस्तावेज को https://developer.apple.com/library/ios/documentation/Cocoa/Reference/Foundation/Classes/NSString_Class/index.html#//apple_ref/occ/clm क्यों अपडेट नहीं किया है/NSString/stringWithContentsOfURL: usedEncoding: त्रुटि: या मैं गलत दस्तावेज़ देख रहा हूं? –