// 原始代码
@interface XXUtil : NSObject
+ (BOOL)isVerified;
+ (BOOL)isNeedSomething;
+ (void)resetPassword:(NSString *)password;
@end
// 加密后
//XXUtil.h
#import <Foundation/Foundation.h>
typedef struct _util {
BOOL (*isVerified)(void);
BOOL (*isNeedSomething)(void);
void (*resetPassword)(NSString *password);
}XXUtil_t ;
#define XXUtil ([_XXUtil sharedUtil])
@interface _XXUtil : NSObject
+ (XXUtil_t *)sharedUtil;
@end
//XXUtil.m
#import "XXUtil.h"
static BOOL _isVerified(void)
{
//bala bala ...
return YES;
}
static BOOL _isNeedSomething(void)
{
//bala bala ...
return YES;
}
static void _resetPassword(NSString *password)
{
//bala bala ...
}
static XXUtil_t * util = NULL;
@implementation _XXUtil
+(XXUtil_t *)sharedUtil
{
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
util = malloc(sizeof(XXUtil_t));
util->isVerified = _isVerified;
util->isNeedSomething = _isNeedSomething;
util->resetPassword = _resetPassword;
});
return util;
}
+ (void)destroy
{
util ? free(util): 0;
util = NULL;
}
@end
// 最后根据xcode指错,纠正
[XXUtil isVerified];
// 改为
XXUtil->isVerified();