Why data related to a URL is created before writing something?

24 Views Asked by At

Xcode 9.1 Swift 4

I'm trying to do some things if a property list still doesn't exist at a certain URL. The code is:

import UIKit

class ViewController: UIViewController {

let urlPers = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask)[0].appendingPathComponent("punterosborrable.plist")
    lazy var infoPunt = try? Data(contentsOf: urlPers)



    override func viewDidLoad() {
        super.viewDidLoad()

        switch infoPunt {
        case nil:
            puntNUM = 1
            puntALG = 1
            puntGEO = 1
            puntDYA = 1
        default:
            puntNUM = try! PropertyListDecoder().decode([Int].self, from: infoPunt!)[0]
            puntALG = try! PropertyListDecoder().decode([Int].self, from: infoPunt!)[1]
            puntGEO = try! PropertyListDecoder().decode([Int].self, from: infoPunt!)[2]
            puntDYA = try! PropertyListDecoder().decode([Int].self, from: infoPunt!)[3]
        }

Supposedly, if I don´t write anything to the Url, infoPunt should have the value nil. However, just after running the line

 switch infoPunt {

the debugger shows that infoPunt.storage = (Data?) some

What does this mean? What value (or data) is infoPunt holding at this point? I thought it should be nil.

Thanks in advance

0

There are 0 best solutions below