I have a design related question.
I've seen that the UIApplication class has this kind of flags:
UIKIT_EXTERN NSString *const UIApplicationDidEnterBackgroundNotification
UIKIT_EXTERN NSString *const UIApplicationWillEnterForegroundNotification
UIKIT_EXTERN NSString *const UIApplicationDidFinishLaunchingNotification;
UIKIT_EXTERN NSString *const UIApplicationDidBecomeActiveNotification;
UIKIT_EXTERN NSString *const UIApplicationWillResignActiveNotification;
UIKIT_EXTERN NSString *const UIApplicationDidReceiveMemoryWarningNotification;
and, on the other side, the class UITableView declares structs like:
typedef enum {
UITableViewScrollPositionNone,
UITableViewScrollPositionTop,
UITableViewScrollPositionMiddle,
UITableViewScrollPositionBottom
} UITableViewScrollPosition;
One is for notifications an the other defines types of objects. I believe that those two are design choices to 'tag' some related objects and make decitions at runtime based on that flag.
Let's say that I want to create a factory of objects that need to be tagged. In the image bellow, I want enumerations or ID's for every section and widget. How would any widget communicate or 'invoke' another one? e.j. [[Containter sharedInstance] presentWidget:?? forSection: ?? withInfo:(id)info];
Is there a deeper or more accurate reason to choose one of them? Thanks for your help.
An enum declaration is not a struct, the syntax is similar but it simply defines a series of named numbers.
These constants refer to two different kinds of data types, string vs numeric.
The named constants in UIApplications are pointers to NSString objects, they have a pointer value and there is also a string constant that they point to (which is in the .m file). Sort of like declaring some string constants like this (except they are extern and the definition is completed elsewhere):
NSString* const UIApplicationDidEnterBackgroundNotification = @"UIApplicationDidEnterBackgroundNotification";
The named constants in UITableViewScrollPosition are names given to integer values. Sort of like:
const int UITableViewScrollPositionNone = 0;
The reason for using an enum (named numbers) in one case is that they are defining all the possible values vs the string constant they define a few of the values but it is possible for users to define others. With string constants different libraries could each define their own without any chance of duplicate string addresses, whereas defining extensions to enumerations could have collisions between different libraries if they defined the same integer value to have different meanings.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With