Bronze


#1

in Person class:

func giveUpAsset(asset: Asset) {
    for (index, item) in assets.enumerate() {
      if item === asset {
        assets.removeAtIndex(index)
        asset.owner = nil
        accountant.removedAsset(asset)
      }
    }
  }

in Accountant:

func removedAsset(asset: Asset) {
    netWorth -= asset.value
  }

#2

Person:

func relinquishOwnershipOfAsset(theAsset: Asset) {
        theAsset.owner = nil
        
        assets = assets.filter({ $0.name != theAsset.name })
        accountant.lostAsset(theAsset)
    }

Accountant:

func lostAsset(asset: Asset) {
        netWorth -= asset.value
    }

#3

I think that both Pseudowolf and astericky have missed something very important: if in main.swift you make the following statement “var backpack: Asset? = Asset(name: “Blue Backpack”, value: 45.0)”, then 45 dollars will be subtracted from the net worth of Person even if Person never owned the Blue Backpack. Here is my solution:

In Person.swift file:

class Person: CustomStringConvertible {

func relinquishOwnershipOfAsset(asset: Asset) {    // my add for the Bronze Challenge
    if asset.owner != nil {                     // this is the part you missed, guys!
        asset.owner = nil
        if let index = assets.indexOf({$0 === asset}) {
            assets.removeAtIndex(index)
        }
        accountant.lostAsset(asset)
    }
}   

}

In Accountant.swift file:

class Accountant {
typealias netWorthChanged = (Double) -> ()

func lostAsset(asset: Asset) {                     // my add for the Bronze Challenge
    netWorth -= asset.value
}

}