// Playground - noun: a place where people can play

import UIKit

class Collar {
    var color: String
    init(color: String) {
        self.color = color
    }
}

class Pet {
    var name: String
    var collar: Collar?
    init(name: String) {
        self.name = name
    }
}

class Person {
    var name: String
    var pet: Pet?
    init(name: String) {
        self.name = name
    }
}

var jon = Person(name: "Jon")
var buddy = Pet(name: "Buddy")
jon.pet = buddy
var collar = Collar(color: "czerwony")
buddy.collar = collar

if let tmpPet = jon.pet {
    if let tmpCollar = tmpPet.collar {
        print("Kolor obroży to \(tmpCollar.color)")
    } else {
        print("Nie można ustalić koloru.")
    }
} else {
    print("Nie można ustalić koloru.")
}

if let color = jon.pet?.collar?.color {
    print("Kolor obroży to \(color)")
} else {
    print("Nie można ustalić koloru.")
}




