Use Foundation_EXPORT correctly

I have an Event.h file:

@interface Event : NSObject FOUNDATION_EXPORT NSString * const KP_STATUS_NEW FOUNDATION_EXPORT NSString * const KP_STATUS_APPROVED FOUNDATION_EXPORT NSString * const KP_STATUS_DELETED @property (nonatomic, strong) NSString * name; @property (nonatomic, strong) NSString * description; @property (nonatomic, strong) NSString * status 

I would like programmers who use my SDK to have access to the STATUS lines, especially when setting the status for an Event object. Should I use FOUNDATION_EXPORT as above?

So the programmer could just do

 Event * myEvent = [[Event alloc] init]; myEvent.status = STATUS_NEW; 

?

Is this a way to do this in objective-c?

By the way, KP is a common prefix for the project. Do I need a KP status prefix or something else? What standard?

+6
source share
1 answer

You can just use extern rather than FOUNDATION_EXPORT (which I believe is defined one way or another).

Using a common prefix is ​​a good idea, given the lack of namespaces in Objective-C, and this doubles for a class named Event , which is a very common name.

So something like this looks good to me:

 #import "KPEvent.h" KPEvent * myEvent = [[KPEvent alloc] init]; myEvent.status = KP_STATUS_NEW; 

or better yet:

 myEvent.status = KP_EVENT_STATUS_NEW; 

if the statuses apply only to the class of events.

Which you do not explain why you cannot use enum , which is more elegant:

 typedef enum { KP_EVENT_STATUS_NEW, KP_EVENT_STATUS_APPROVED, KP_EVENT_STATUS_DELETED } KpEventStatus; 

and you can forget about this extern nonsense.

+3
source

Source: https://habr.com/ru/post/957938/


All Articles