Kai Rogers
Kai Rogers

Reputation: 3

What is the difference between decodeObject(forKey:) & decodeObjectForKey(_:)

Here are two examples in use.

// The name is required. If we cannot decode a name string, the initializer should fail.
guard let name = aDecoder.decodeObject(forKey: PropertyKey.name) as? String else {
    os_log("Unable to decode the name for a Meal object.", log: OSLog.default, type: .debug)
    return nil
}

// Because photo is an optional property of Meal, just use conditional cast.
let photo = aDecoder.decodeObjectForKey(PropertyKey.photo) as? UIImage

Upvotes: 0

Views: 208

Answers (1)

Shehata Gamal
Shehata Gamal

Reputation: 100533

NSKeyedUnarchiver is originally a bridged objective c class so you can use

decodeObjectForKey(_:) In swift <3.0

and

decodeObject(forKey:) In swift >= 3

internally they are the same thing , it's syntax changing , have a look to this Thread

Upvotes: 1

Related Questions