iphone - String constant ... best practise? -
i'm looking best practise of setting code-wide used string constant
option 1
extern const nsstring *cdownloadcompletenotification; (.h file)
const nsstring *cdownloadcompletenotification = @"downloadcompletenotification"; (.m file)
option 2
define knotificationdownloadcomplete @"notificationdownloadcomplete" .... (common.h)
is there benefit, 1 way or other ? ... or case of personal preference ?
personally, go former though there's not choose between them. memory usage same in both cases.
there's few things watch out in #define - e.g. if include .h file twice.
if use define , change constant's value of files might compiled old value , new - find tricky work out why notification handlers not being called! you'd have clean before building make sure changed everything. won't happen if use extern nsstring.*
hope that's helpful.
nb wouldn't declare const - compiler warning when passing postnotificationname: methods on nsnotificationcenter :(
*xcode should clever enough mark files include common.h needing rebuild if changes i've found have been wrong in past.
Comments
Post a Comment