awakeFromNib called multiples times

cocoa, macos, objective-c

Solution

If your NIB file contains a view which is then to be used and instanciated multiple times for your view-based NSTableView then each of these view's instances will receive an `awakeFromNib` call/message.

Similar question.

Problem

I have an `NSViewController` associated to a NIB, which itself contained some `NSView` and `NSButton`. I was using `awakeFromNib` to initialize some model classes. It worked just fine, until I added a view-based `NSTableView`. Now, `awakeFromNib` is called multiples times. Why is it the case ? and what reliable method could I use to initialize my model classes ? Thanks in advance.

Original source