Re: awakeFromNib multiple objects - all connected?

2014-07-11 Thread Uli Kusterer
On 06 Jul 2014, at 08:54, Roland King r...@rols.org wrote:
 After awakeFromNib all the outlets are connected except for those to subviews 
 of the UIViewController's view, they remain nil until after viewDidLoad. 
 Other top-level object outlets are connected, but not the view nor its 
 subviews. I always felt that broke the awakeFromNib contract; the objects are 
 in the NIB, the outlets are in the NIB, surely they should be connected at 
 awakeFromNib. 

 The contract is that all outlets loaded from the current NIB are connected. If 
you have cascading NIB loads, then you get an awakeFromNib call for each NIB 
(at least on the Mac, I don’t think I’ve had nested NIBs on iOS in a while). 
That means that e.g. a view controller in a NIB will get one awakeFromNib 
because the items in the NIB it owns have been loaded and connected, and then a 
second one when its parent NIB has finished loading and it’s been connected to 
the other items surrounding it.

 Depending on when the inner view controller is asked to provide its view, it 
may not have been loaded yet, so obviously there’s nothing to connect to yet. 
E.g. if the surrounding NIB calls -view on the view controller in 
-awakeFromNib, then of course it is until then that the remaining outlets are 
connected.

 I don’t see how that would break any contracts, it is logical. The alternative 
would be to somehow violate encapsulation and have an inner object inform the 
outer object that it has a NIB that needs loading as well, and then have it 
modify the load order and trigger awakeFromNib calls on objects actually 
instantiated by its owner and … it would be very messy, at the latest once you 
have a view controller inside the NIB of a view controller inside of the app’s 
main NIB or whatever.

Cheers,
-- Uli Kusterer
“The Witnesses of TeachText are everywhere...”
http://zathras.de


___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Re: awakeFromNib multiple objects - all connected?

2014-07-11 Thread Roland King

 On 11 Jul 2014, at 5:33 pm, Uli Kusterer witness.of.teacht...@gmx.net wrote:
 
 On 06 Jul 2014, at 08:54, Roland King r...@rols.org wrote:
 After awakeFromNib all the outlets are connected except for those to 
 subviews of the UIViewController's view, they remain nil until after 
 viewDidLoad. Other top-level object outlets are connected, but not the view 
 nor its subviews. I always felt that broke the awakeFromNib contract; the 
 objects are in the NIB, the outlets are in the NIB, surely they should be 
 connected at awakeFromNib. 
 
 The contract is that all outlets loaded from the current NIB are connected. 
 If you have cascading NIB loads, then you get an awakeFromNib call for each 
 NIB (at least on the Mac, I don’t think I’ve had nested NIBs on iOS in a 
 while). That means that e.g. a view controller in a NIB will get one 
 awakeFromNib because the items in the NIB it owns have been loaded and 
 connected, and then a second one when its parent NIB has finished loading and 
 it’s been connected to the other items surrounding it.
 
 Depending on when the inner view controller is asked to provide its view, it 
 may not have been loaded yet, so obviously there’s nothing to connect to yet. 
 E.g. if the surrounding NIB calls -view on the view controller in 
 -awakeFromNib, then of course it is until then that the remaining outlets are 
 connected.
 
 I don’t see how that would break any contracts, it is logical. The 
 alternative would be to somehow violate encapsulation and have an inner 
 object inform the outer object that it has a NIB that needs loading as well, 
 and then have it modify the load order and trigger awakeFromNib calls on 
 objects actually instantiated by its owner and … it would be very messy, at 
 the latest once you have a view controller inside the NIB of a view 
 controller inside of the app’s main NIB or whatever.


ok so I wrote a test project for this. UIViewController subclass as file’s 
owner, a UIView subclass for its view, an extra test top-level object at the 
same level as the view, one button and one label as children of the view. I 
made the UIViewController subclass have outlets for the top-level object, the 
button and the label. Both the top-level object and the view had outlets for 
the button and the label and I hooked them all up. One NIB, all objects, 7 
connected outlets. 

Breakpointing in awakeFromNIB in the view controller and the top-level object 
showed that the outlets to the button and label were not hooked up, they were 
nil in both places. The VC was hooked up to the top-level object but that was 
the only connection which had been made.

That appears to violate that all outlets from the current NIB are connected. 

.. which made me wonder, so I looked at the actual project directory and found 
.. there are TWO nibs in there. Seems IB evilly splits the viewcontroller piece 
from the view piece and puts them in their own nibs, along with some extra 
information to hook the view’s objects in one NIB into the VC’s objects in the 
other when the view loads (ie hooking the button and label to the top-level 
object in the first NIB). 

That probably explains it. The original NIB just contains the VC and object, so 
awakeFromNIB only shows those two hooked up, the view load is a separate NIB 
load altogether. 

That is evil, thanks for the thought about more than one NIB, it make me check 
to see if my one NIB really was .. one NIB. 




___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Re: awakeFromNib multiple objects - all connected?

2014-07-06 Thread Roland King

 
 The resource programming guide explicitly describes the sending of
 -awakeFromNib as occurring after all outlets have been set up:
 
 https://developer.apple.com/library/mac/documentation/Cocoa/Conceptual/LoadingResources/CocoaNibs/CocoaNibs.html#//apple_ref/doc/uid/1051i-CH4-SW18
 

[ oops didn't reply to the list ]

.. which is one of the things always bothered me when you load 
UIViewControllers + views from NIBs. In that NIB you usually have a 
UIViewController as file's owner, a view which is its view which has a load of 
subviews, plus some other top-level objects. Often some of the view's subviews 
are IBOutlets of the UIViewController, eg buttons you want to enable and 
disable etc. 

After awakeFromNib all the outlets are connected except for those to subviews 
of the UIViewController's view, they remain nil until after viewDidLoad. Other 
top-level object outlets are connected, but not the view nor its subviews. I 
always felt that broke the awakeFromNib contract; the objects are in the NIB, 
the outlets are in the NIB, surely they should be connected at awakeFromNib. 

___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Re: awakeFromNib multiple objects - all connected?

2014-07-05 Thread Rob Petrovec

 On Jul 4, 2014, at 9:13 PM, Graham Cox graham@bigpond.com wrote:
 
 
 On 5 Jul 2014, at 1:56 pm, Trygve Inda cocoa...@xericdesign.com wrote:
 
 As long as A can call into B  C and know that B  C have their outlets
 hooked up, that's fine.
 
 You can rely on all outlets being connected. What you can't rely on is the 
 order in which each object's -awakeFromNib is called.
Actually, you can’t rely on all the outlets in the entire nib to be 
connected when the first awakeFromNib is called.  This is an undocumented 
behavior, so it can change out from under you at any time.  So you shouldn’t 
rely on this behavior just because it happens today, it could easily change in 
the some future release.

The only thing you can rely on, because it is documented, is that the 
outlets for ObjectA will be connected when ObjectA's -awakeFromNib is called, 
and the outlets for ObjectB will be connected when ObjectB's -awakeFromNib is 
called.  There is no guarantee on the order of when their awakeFromNib’s will 
be called, so if you need to do something in one object that calls into another 
object from the nib (that is not a subview) then you should do it later in the 
loading sequence.  Like when the nib’s owner has -awakeFromNib, windowDidLoad 
or -loadView called, or when the common-superview to ObjectA  ObjectB’s 
-awakeFromNib is called.

 On Jul 4, 2014, at 8:56 PM, Trygve Inda cocoa...@xericdesign.com wrote:
 
 
 On Jul 4, 2014, at 8:18 PM, Trygve Inda cocoa...@xericdesign.com wrote:
 
 When an object in a nib receives awakeFromNib are all the outlets throughout
 the entire nib hooked up, or only those outlets in the object that is
 receiving awakeFromNib?
 
 All the outlets are hooked up. But not all the other objects in the nib have
 run their -awakeFromNib methods yet, so you have to be cautious about calling
 into other objects in the nib during your -awakeFromNib implementation.
 
 —Jens
 
 That's fine. My situation is I have a subclass of NSWindowController and
 several custom objects:
 
 Owner (MyWindowController)
 
 ControllerA
 
 ControllerB
 ControllerC
 
 These are all in the nib and I call init in such a way that Owner is passed
 a reference which it stores. When ControllerA gets an awakeFromNib it needs
 to call methods in ControllerB and ControllerC that require all the outlets
 to be hooked up.
 
 I need to ensure ControllerA runs first so I do this by having an
 awakeFromNib in ControllerA, but not in B or C. So that when ControllerA
 gets awakeFromNib, it can manage things.
 
 As long as A can call into B  C and know that B  C have their outlets
 hooked up, that's fine.
Having -awakeFromNib implemented in one object and not another does not 
determine the order.  So you can’t rely on ControllerB  ControllerC having 
their outlets connected when ControllerA’s -awakeFromNib is called.

A better, and less fragile approach would be to override the Owner’s 
-awakeFromNib (or better yet windowDidLoad since it is an NSWindowController 
subclass) and have it instruct ControllerA to do whatever it is you wanted 
ControllerA to do in its awakeFromNib.

Good luck...

—Rob



___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Re: awakeFromNib multiple objects - all connected?

2014-07-05 Thread Kyle Sluder
On Sat, Jul 5, 2014, at 08:10 PM, Rob Petrovec wrote:
 
  On Jul 4, 2014, at 9:13 PM, Graham Cox graham@bigpond.com wrote:
  
  
  On 5 Jul 2014, at 1:56 pm, Trygve Inda cocoa...@xericdesign.com wrote:
  
  As long as A can call into B  C and know that B  C have their outlets
  hooked up, that's fine.
  
  You can rely on all outlets being connected. What you can't rely on is the 
  order in which each object's -awakeFromNib is called.
   Actually, you can’t rely on all the outlets in the entire nib to be 
 connected when the first awakeFromNib is called.  This is an undocumented 
 behavior, so it can change out from under you at any time.  So you shouldn’t 
 rely on this behavior just because it happens today, it could easily change 
 in the some future release.

The resource programming guide explicitly describes the sending of
-awakeFromNib as occurring after all outlets have been set up:

https://developer.apple.com/library/mac/documentation/Cocoa/Conceptual/LoadingResources/CocoaNibs/CocoaNibs.html#//apple_ref/doc/uid/1051i-CH4-SW18

--Kyle Sluder

___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

awakeFromNib multiple objects - all connected?

2014-07-04 Thread Trygve Inda
I have a nib that has several custom objects instantiated in it:

NIB
-ObjectA // contains outlets ABC
-ObjectB // contains outlets DEF


When object A receives awakeFromNib, I know that outlets A, B and C are
hooked up, but it is also safe to call a method in ObjectB that requires
ObjectB to have it's D, E  F outlets already hooked up?


ObjectA has an outlet to ObjectB so calliong a method in ObjectB is fine,
but ObjectB may not have received its awakeFromNib yet.

So the bottom line is:

When an object in a nib receives awakeFromNib are all the outlets throughout
the entire nib hooked up, or only those outlets in the object that is
receiving awakeFromNib?

Thanks,

Trygve



___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Re: awakeFromNib multiple objects - all connected?

2014-07-04 Thread Robert Martin
The nib is only ‘awake’ after all connections in the graph have been made.

On Jul 4, 2014, at 11:18 PM, Trygve Inda cocoa...@xericdesign.com wrote:

 So the bottom line is:
 
 When an object in a nib receives awakeFromNib are all the outlets throughout
 the entire nib hooked up, or only those outlets in the object that is
 receiving awakeFromNib?


___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Re: awakeFromNib multiple objects - all connected?

2014-07-04 Thread Jens Alfke

On Jul 4, 2014, at 8:18 PM, Trygve Inda cocoa...@xericdesign.com wrote:

 When an object in a nib receives awakeFromNib are all the outlets throughout
 the entire nib hooked up, or only those outlets in the object that is
 receiving awakeFromNib?

All the outlets are hooked up. But not all the other objects in the nib have 
run their -awakeFromNib methods yet, so you have to be cautious about calling 
into other objects in the nib during your -awakeFromNib implementation.

—Jens

smime.p7s
Description: S/MIME cryptographic signature
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Re: awakeFromNib multiple objects - all connected?

2014-07-04 Thread Trygve Inda
 The nib is only ‘awake’ after all connections in the graph have been made.
 
 On Jul 4, 2014, at 11:18 PM, Trygve Inda cocoa...@xericdesign.com wrote:
 
 So the bottom line is:
 
 When an object in a nib receives awakeFromNib are all the outlets throughout
 the entire nib hooked up, or only those outlets in the object that is
 receiving awakeFromNib?
 
 

I am just wondering which way is true:

1) all the nib's objects are connected to their outlets and then each object
is sent an awakeFromNib.

2) each object gets its own outlets connected and then is sent awakeFromNob
(so objects that have not yet received awakeFromNib may not have their
objects hooked up).




___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Re: awakeFromNib multiple objects - all connected?

2014-07-04 Thread Trygve Inda
 
 On Jul 4, 2014, at 8:18 PM, Trygve Inda cocoa...@xericdesign.com wrote:
 
 When an object in a nib receives awakeFromNib are all the outlets throughout
 the entire nib hooked up, or only those outlets in the object that is
 receiving awakeFromNib?
 
 All the outlets are hooked up. But not all the other objects in the nib have
 run their -awakeFromNib methods yet, so you have to be cautious about calling
 into other objects in the nib during your -awakeFromNib implementation.
 
 —Jens

That's fine. My situation is I have a subclass of NSWindowController and
several custom objects:

Owner (MyWindowController)

ControllerA

ControllerB
ControllerC

These are all in the nib and I call init in such a way that Owner is passed
a reference which it stores. When ControllerA gets an awakeFromNib it needs
to call methods in ControllerB and ControllerC that require all the outlets
to be hooked up.

I need to ensure ControllerA runs first so I do this by having an
awakeFromNib in ControllerA, but not in B or C. So that when ControllerA
gets awakeFromNib, it can manage things.

As long as A can call into B  C and know that B  C have their outlets
hooked up, that's fine.




___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Re: awakeFromNib multiple objects - all connected?

2014-07-04 Thread Graham Cox

On 5 Jul 2014, at 1:56 pm, Trygve Inda cocoa...@xericdesign.com wrote:

 As long as A can call into B  C and know that B  C have their outlets
 hooked up, that's fine.

You can rely on all outlets being connected. What you can't rely on is the 
order in which each object's -awakeFromNib is called.

--Graham



___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Re: awakeFromNib multiple objects - all connected?

2014-07-04 Thread Trygve Inda
 
 On 5 Jul 2014, at 1:56 pm, Trygve Inda cocoa...@xericdesign.com wrote:
 
 As long as A can call into B  C and know that B  C have their outlets
 hooked up, that's fine.
 
 You can rely on all outlets being connected. What you can't rely on is the
 order in which each object's -awakeFromNib is called.
 
 --Graham
 
 
 

Perfect.

And long as one object can receive awakeFromNib, call into another objects
(via an outlet) and THOSE objects will have their outlets connected (even
though they may not have received their own awakeFromNib yet), that will
work.

Thanks!



___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com