TestingWithFrank / Frank

Automated acceptance tests for native iOS apps
http://testingwithfrank.github.io/
Apache License 2.0
215 stars 57 forks source link

Mac: Add methods to add and remove children at runtime #11

Closed MichaelBuckley closed 10 years ago

MichaelBuckley commented 10 years ago

This will allow users to add and remove objects to the view hierarchy without subclassing the parent. Some objects, like NSStatusItem, aren't accessible via Cocoa. That is, you can add NSStatusItems to the view hierarchy, but you cannot retrieve them.

This will probably require creating an NSSet* associated object on NSObject, and adding -FEX_addChild: and -FEX_removeChild methods to NSObject. When retrieving the list of Children, Frank will have to query the associated array as well as calling -FEX_children on the object.

MichaelBuckley commented 10 years ago

I've decided against implementing a general scheme to add children at runtime. This would require calling methods in the Frank static library from client code, so we'd need to publish headers, and make sure the code was only compiled for Frank builds, and that's a big headache.

Instead, I swizzled some methods in NSStatusBar, so that NSStatusItems are automatically added to and removed from the view hierarchy when they are added to and removed from the system-wide NSStatusBar.