Posts

Post not yet marked as solved
0 Replies
304 Views
We have an application that takes user entered text from a UITextView and encodes it using an NSKeyedArchiver. That text is later retrieve via an NSKeyedUnarchiver which knows it contains a value for the given key, but fails to decode it in this scenario. We noticed an error retrieving archived strings that came from a UITextView and are greater that 512 characters. After testing I found that the class type of the string returned from UITextView.text is no longer just String, but shows up as class name = "NSBigMutableString". Once this happens the decoding failure happens. Attached below is a unit test that shows the scenario. If you do not pass the test string through a UITextView, it all works as expected. As soon as you assign it to a TextView and then retrieve it, it is now a NSBigMutableString.  func testArchiveUnarchiveFailure() throws { 		let testString = "Suspendisse potenti. Nam lobortis ornare augue, eu tempor dui suscipit dignissim. Quisque consequat fringilla velit, eget posuere nunc tristique sed. Cras ornare eleifend nulla vel lacinia. Curabitur ac libero sit amet sem laoreet pharetra. Nulla facilisi. Nam nec posuere ante.\nPellentesque consequat magna nec neque interdum, ut tincidunt erat dictum. Etiam vitae enim sit amet orci efficitur suscipit. Nulla facilisi. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas." 		let textView = UITextView() 		textView.text = testString                       		let bigString = textView.text! 		let keyedArchiver = NSKeyedArchiver(requiringSecureCoding: true) 		 		keyedArchiver.encode(bigString, forKey: "content") 		let data = keyedArchiver.encodedData 		let decoder = try! NSKeyedUnarchiver(forReadingFrom: data) 		let content = decoder.decodeObject(forKey: "content") as? String 		XCTAssertNotNil(content) }
Posted
by jay1234.
Last updated
.