3

I am updating some of my code which has been deprecated in IOS12.
Below is the old code:

    let gameData : NSMutableData = NSMutableData()
    let archiver = NSKeyedArchiver(forWritingWith: gameData)
    archiver.encode(MatchInformationValues.currentMatchInfo, forKey: "MatchData")
    archiver.encode(CurrentGameState.currentGameStatus, forKey: "GameData")
    archiver.finishEncoding()

The new code that works with IOS12 is:

let archiver = NSKeyedArchiver(requiringSecureCoding: false)
archiver.encode(MatchInformationValues.currentMatchInfo, forKey: "MatchData")
archiver.encode(CurrentGameState.currentGameStatus, forKey: "GameData")
archiver.finishEncoding()
let gameData = archiver.encodedData

I am trying to understand the "requiringSecureCoding:" property. When do you set it to true and when to use false? My data is just a dictionary containing game data, so it seems like I should use false, but this is just a guess. Apple's documentation does not give any guidance when to use true or false. Any insight would be appreciated.

Vladimir
  • 7,670
  • 8
  • 28
  • 42
Delph2
  • 119
  • 1
  • 9
  • If you don't want the user to be able to manipulate your game data you should set it to true – Leo Dabus Oct 01 '18 at 21:23
  • 3
    AKA: Always set it to true, unless you got a good reason not to. The documentation also states: `If "NSSecureCoding" cannot be used, "requiresSecureCoding" may be turned off here; for improved security, however, "requiresSecureCoding" should be left enabled whenever possible. "requiresSecureCoding" ensures that all encoded objects conform to "NSSecureCoding", preventing the possibility of encoding objects which cannot be decoded later.` – Sander Saelmans Oct 02 '18 at 06:15
  • Thanks for the helpful feedback. Your answer is excellent. – Delph2 Oct 02 '18 at 16:32

0 Answers0