FROM : Erik Buck
DATE : Thu May 15 16:08:23 2008
But, just exactly HOW does the actual documentWindow object get passed so that
someMethod can look at one of its properties?
This question is oriented to "behind the scenes"
For the current version of Interface Builder, see
- (void)connectOutlet:(NSString *)outletofSourceObject:(id)sourcetoDestinationObject:(id)destination
of the IBDocument class in the InterfaceBuilderKit framework.
In the current version of Interface Builder, the precise mechanism for storing connection information is not documented and therefore considered an implementation detail. However, in previous versions of Interface Builder, it worked like the following:
There is/was a class called IBConnector which looked something like this
@interface IBConnector : NSObject <NSCoding>
{
id source;
NSString *outletName;
id destination;
}
- (void)setSource:(id)anObject;
- (void)setOutletName:(NSString *)aName;
- (void)setDestination:(id)anObject;
- (void)connect;
@end
When you drag a connection in IB, a new instance of IBConnector is created, initialized with a source, outlet name, and destination accordingly, and archived into the .nib file.
When the nib file is tested in IB or loaded into your application at run-time, the IBConnector instances are unarchived just like every other object in the nib. Once unarchived, each IBConnector instance's source and destination instance variables are restored to a reference to the corresponding unarchived objects. [That is just how archiving and unarchiving graphs of objects works. Read up on archiving for details].
As part of the nib loading process but before -awakFromNib is sent to any objects unarchived from the nib, the connect message is sent to each unarchived IBConnection instance.
The -connect method of IBConnector is implemented something like this
- (void)connect
{
Ivar ivar = class_getInstanceVariable([source class], [outletName UTF8String]);
object_setIvar(source , ivar, destination);
}
See http://developer.apple.com/documentation/Cocoa/Reference/ObjCRuntimeRef/Reference/reference.html for information about class_getInstanceVariable() and object_setIvar(). The source code for the runtime is also available.
Once the connections are all made, the IBConnector instances are no longer needed and may be deallocated.
Then -awakeFromNib is called for every object unarchived from the nib and incidentally also the "File's Owner" object. Because the connections were all restored before -awakeFromNib, it is safe to use the connections in your implementation of -awakeFromNib.
Does that answer you "behind the scenes" question ?
DATE : Thu May 15 16:08:23 2008
But, just exactly HOW does the actual documentWindow object get passed so that
someMethod can look at one of its properties?
This question is oriented to "behind the scenes"
For the current version of Interface Builder, see
- (void)connectOutlet:(NSString *)outletofSourceObject:(id)sourcetoDestinationObject:(id)destination
of the IBDocument class in the InterfaceBuilderKit framework.
In the current version of Interface Builder, the precise mechanism for storing connection information is not documented and therefore considered an implementation detail. However, in previous versions of Interface Builder, it worked like the following:
There is/was a class called IBConnector which looked something like this
@interface IBConnector : NSObject <NSCoding>
{
id source;
NSString *outletName;
id destination;
}
- (void)setSource:(id)anObject;
- (void)setOutletName:(NSString *)aName;
- (void)setDestination:(id)anObject;
- (void)connect;
@end
When you drag a connection in IB, a new instance of IBConnector is created, initialized with a source, outlet name, and destination accordingly, and archived into the .nib file.
When the nib file is tested in IB or loaded into your application at run-time, the IBConnector instances are unarchived just like every other object in the nib. Once unarchived, each IBConnector instance's source and destination instance variables are restored to a reference to the corresponding unarchived objects. [That is just how archiving and unarchiving graphs of objects works. Read up on archiving for details].
As part of the nib loading process but before -awakFromNib is sent to any objects unarchived from the nib, the connect message is sent to each unarchived IBConnection instance.
The -connect method of IBConnector is implemented something like this
- (void)connect
{
Ivar ivar = class_getInstanceVariable([source class], [outletName UTF8String]);
object_setIvar(source , ivar, destination);
}
See http://developer.apple.com/documentation/Cocoa/Reference/ObjCRuntimeRef/Reference/reference.html for information about class_getInstanceVariable() and object_setIvar(). The source code for the runtime is also available.
Once the connections are all made, the IBConnector instances are no longer needed and may be deallocated.
Then -awakeFromNib is called for every object unarchived from the nib and incidentally also the "File's Owner" object. Because the connections were all restored before -awakeFromNib, it is safe to use the connections in your implementation of -awakeFromNib.
Does that answer you "behind the scenes" question ?
| Related mails | Author | Date |
|---|---|---|
| John Love | May 15, 13:30 | |
| Graham Cox | May 15, 13:53 | |
| Torsten Curdt | May 15, 15:21 | |
| Graham Cox | May 15, 15:32 | |
| Mike Abdullah | May 15, 15:36 | |
| Torsten Curdt | May 15, 15:53 | |
| Erik Buck | May 15, 16:08 | |
| Graham Cox | May 15, 16:13 | |
| John Love | May 17, 16:01 |






Cocoa mail archive

