Public functions

In Objective-C some APIs may wish to  expose own helper functions publicly. For concern and state procedures. Functions are great way to encapsulate like these behaviours. If you think they’re really useful, it may be worth making them available globally.

Interface File:

typedef NS_ENUM(NSUInteger, UserState) {
    UserState_Active,
    UserState_Deactive,
    UserState_SuperUser,
    UserState_Admin,
    UserState_Moderator
};

extern NSString *NSStringFromUserState(UserState state);

Implematation File

NSString *NSStringFromUserState(UserState state) {
    
    switch (state) {
        case UserState_Admin: return @"Admin";
        case UserState_Moderator: return @"Moderator";
        case UserState_SuperUser: return @"Super User";
        case UserState_Active: return @"Active User";
        case UserState_Deactive: return @"De-active User";
        default:return nil;
    }
    return nil;
}
Advertisements