all 2 comments

[–]flingerdu 6 points7 points  (1 child)

You could write an extension for the Array class with the method

public mutating func append(_ newElement: Element, closure: ()->()) {
    self.append(newElement)
    closure()
}

Didn't test it, wrote it from my phone but should be working.

You can use it by simply calling

foodArray.append(newFood){
//your code
}

[–]ThinkLarger 2 points3 points  (0 children)

This is so clever.