As our codebase matures, I don’t like the dictionary transfer pattern as a way to package information for sending messages or, worse, function arguments. This requires a send and receive function that has an undocumented string literal API.
..in some function.. NSDictionary *info = [NSDictionary dictionaryWithObjectsAndKeys: thisObject, @"thisKey", thatObject, @"thatKey", nil]; [[NSNotificationCenter defaultCenter] postNotificationName:@"MY_NOTIFICATION" object:nil userInfo:info]; ....
and then in someClass listener
- (void)someClassListener:(NSNotification *)notification { NSDictionary *info = [notification userInfo]; ThisObject *ob1 = [info objectForKey:@"thisKey"]; ThatObject *ob2 = [info objectForKey:@"thatKey"]; }
You must remember that thisKey and thatKey are keys such as ThisObject and ThatObject for this notification, of course, you can create some constants somewhere for these keys, but this does not really solve the problem.
And let's say that you have a function that requires 15 arguments, you are not going to create a function with 15 parameters, it would be much easier (although less readable) just to pass the dictionary, but now you have the same problem, as mentioned above.
I played with creating the missing “message classes” in these header files of this class (i.e. two interfaces in one header), and the message class is just a list of objects that you define and send to a method that creates a stronger contract but that seems wrong.
It would be great if I could do something like the typeDef of the parameter object in the header, but this does not support NSObject only things like int or float , etc.
In fact, I'm trying to create a stronger contract between the sender of the message and the receiver of messages, whether it be functions or notifications.