[swift-users] Encoding an array of tuples with a NSCoder

Saagar Jha saagar at saagarjha.com
Thu Sep 22 16:07:20 CDT 2016


Hello,

I’ve been working on migrating some old code over to Swift 3, and I’m having some trouble archiving an array of tuples:

class Foo: NSObject, NSCoding {
	var bar: [(string1: String, string2: String)]

	required init?(coder aDecoder: NSCoder) {
		bar = aDecoder.decodeObject(forKey: “bar”) as? [(string1: String, string2: String)] ?? []
	}

	func encode(with aCoder: NSCoder) {
		aCoder.encode(bar, forKey: “bar”) // crash
	}
}

Unfortunately, this code doesn’t seem to work anymore. Is there any way to get a array of tuple encoded without resorting to creating a struct or class in its place?

Thanks,
Saagar Jha



-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-users/attachments/20160922/c5a885ea/attachment.html>


More information about the swift-users mailing list