I am looking for a document that demystifies the appropriate or at least intended time to initialize UI element / controller content. I can’t find for example a specific call at a good time to cause a NSControl subclass to load an image or other similar information it might need. Between -init, -awakeFromNib, -[NSViewController viewDidLoad], (anything else?) there are a lot of choices and these either aren’t called, are too early to interface with other items in the view or make for code mess when there are a lot of controls in the view — it would better satisfy my sense of encapsulation if the objects were a bit more self contained which is te source of mental friction here. I also would benefit from a description of why we have views and view controllers and not just views. Is it a reference cycle issue with delegates? Does it follow some academic paper I might read?
Is there a document hiding around somewhere detailing this stuff? I feel like this a 23 year old question. Maybe 30. Perhaps the big picture items have been lost from the documentation over the years.
Post
Replies
Boosts
Views
Activity
I’ve noticed that if you call a selector on an object that doesn’t support that selector (e.g. viewDidLoad on a NSView) during [NSViewController viewDidLoad] the exception causes the view or window to silently fail to draw and you get a window with no content. This can be frustrating to track down, and certainly quite mystifying the first time! As this sort of thing has happened to me a couple of times, I wonder if there is some sort of reporting mechanism (e.g. an env variable) that I could enable which would put Cocoa in a verbose mode that would report on such things, or better yet get Xcode to halt the program when an undefined selector is used on a valid object?
Alternatively, is there a guide to advanced cocoa debugging tips available somewhere?
I expect there is a shockingly obvious answer to this, but I've been stuck a couple of days on Problem Obvious and could use a tip / cake-with-file to escape from development jail.
I have used DNSServiceRef / Bonjour to advertise my service, and have used the same to get a list of what is advertised (using the hit on lo0 for the moment since still testing). So, now I have a machine name "mymachine.local." and the right port number to connect to. Yay!
What I can not figure out is how to get that information into a (IPV6) sockaddr so I can use it with connect. The point of confusion for me is that DNSServiceGetAddrInfo() does not take a port argument, and I see no other place to squeeze this information into the sockaddr returned by the DNSServiceGetAddrInfoReply.
If I just use a IPV6 socket with that sockaddr, I get back EADDRNOTAVAIL. Haven't tried IPv4. No error is returned from DNSServiceGetAddrInfo. I'm reading around that this may be because the port is 0, and indeed I can't find any spot in this pathway to squeeze that information in.
I'll attach an obligatory bit of code so that the reader may feel more grounded:
// My DNSServiceGetAddrInfoReply
void ServiceList::Node::AddressInfoCallback( DNSServiceRef __nonnull _sdRef,
DNSServiceFlags _flags,
uint32_t _interfaceIndex,
DNSServiceErrorType _errorCode,
const char * __nullable _hostname,
const struct sockaddr * __nullable _address,
uint32_t UNUSED _ttl, void * __nonnull context)
{
printf( "AddressInfo: \"%s\"\n", _hostname);
AddrInfo * info = (AddrInfo*) context;
if( kDNSServiceErr_NoError != _errorCode || NULL == _hostname || NULL == _address)
{
LOG_ERROR("Failed to get address info on \"%s\"\n", (const char*) info->hostTarget);
delete info;
return;
}
int err = connect(info->socket, _address, _address->sa_len); // returns EADDRNOTAVAIL on IPv6 socket.
What am I really trying to do? I'd like to connect to the address and port that I from my DNSServiceResolveReply.