0

我正在尝试制作单例,但我一直遇到错误并且不确定我做错了什么:

这是我的 .h 文件:

#import <Foundation/Foundation.h>

@interface ColorMaker : NSObject { 

}

+(ColorMaker* )sharedColorMaker;

- (UIColor* ) setColor : (float) red : (float) green : (float) blue; 

@end

这是.m

#import "ColorMaker.h"

@implementation ColorMaker

+(ColorMaker *)sharedColorMaker { 

static ColorMaker* sharedColorMaker;

@synchronized(self) { 

    if (!sharedColorMaker)

        sharedColorMaker = [[ColorMaker alloc] init];

    return sharedColorMaker;

}

}

- (UIColor* ) setColor:(float)red :(float)green :(float)blue {

float newRed = red/255;
float newGreen = green/255;
float newBlue = blue/255;

UIColor* colorToReturn = [UIColor colorWithRed:newRed green:newGreen blue:newBlue alpha:1.0];

return colorToReturn;    
}

@end

在视图控制器中,viewDidLoad:

- (void)viewDidUnload {
[super viewDidUnload];

ColorMaker* thisColorMaker = [ColorMaker sharedColorMaker];
}

不断收到“使用未声明的标识符 ColorMaker”错误。

4

0 回答 0