更新情報
広告
PRサイト
関連サイト

シングルトンにした事による変更


initializeメソッドをAppControllerに移動する

シングルトンにした事によって、いつこのオブジェクトが生成されるのかはっきりしなくなりました。そこで念のためinitializeメソッドをAppControllerに移動しておく事にします。ソースコードは一切変更する必要はありません。

AppController.m
+ (void)initialize
{
    NSString        *userDefaultsValuesPath;
    NSDictionary    *userDefaultsValuesDict;
    
    userDefaultsValuesPath = 
        [[NSBundle mainBundle] pathForResource:@"UserDefaults" 
                                        ofType:@"plist"];
    userDefaultsValuesDict = 
        [NSDictionary
            dictionaryWithContentsOfFile:userDefaultsValuesPath];
    
    [[NSUserDefaults standardUserDefaults]
        registerDefaults:userDefaultsValuesDict];
}


バインディングの設定をawakeFromNibからinitに移動する

MainMenu.nib内でインスタンス化しなくなったので、awakeFromNibで初期化する事ができなくなりました。そこでバインディングの設定をawakeFromNibからinitに移動しました。

Randomizer.m
- (id)init
{
    self = [super init];
    if(self)
    {
        srandom(time(NULL));

        [self bindWithName:@"amplitudeMinX1"];
        [self bindWithName:@"amplitudeMinX2"];
        [self bindWithName:@"amplitudeMinX3"];
        [self bindWithName:@"amplitudeMaxX1"];
        [self bindWithName:@"amplitudeMaxX2"];
        [self bindWithName:@"amplitudeMaxX3"];
        
        [self bindWithName:@"amplitudeMinY1"];
        [self bindWithName:@"amplitudeMinY2"];
        [self bindWithName:@"amplitudeMinY3"];
        [self bindWithName:@"amplitudeMaxY1"];
        [self bindWithName:@"amplitudeMaxY2"];
        [self bindWithName:@"amplitudeMaxY3"];
        
        [self bindWithName:@"frequencyMinX1"];
        [self bindWithName:@"frequencyMinX2"];
        [self bindWithName:@"frequencyMinX3"];
        [self bindWithName:@"frequencyMaxX1"];
        [self bindWithName:@"frequencyMaxX2"];
        [self bindWithName:@"frequencyMaxX3"];
        
        [self bindWithName:@"frequencyMinY1"];
        [self bindWithName:@"frequencyMinY2"];
        [self bindWithName:@"frequencyMinY3"];
        [self bindWithName:@"frequencyMaxY1"];
        [self bindWithName:@"frequencyMaxY2"];
        [self bindWithName:@"frequencyMaxY3"];
    }
    return self;
}

- (void)awakeFromNib
{
    [self bindWithName:@"amplitudeMinX1"];
    [self bindWithName:@"amplitudeMinX2"];
    [self bindWithName:@"amplitudeMinX3"];
    [self bindWithName:@"amplitudeMaxX1"];
    [self bindWithName:@"amplitudeMaxX2"];
    [self bindWithName:@"amplitudeMaxX3"];

    [self bindWithName:@"amplitudeMinY1"];
    [self bindWithName:@"amplitudeMinY2"];
    [self bindWithName:@"amplitudeMinY3"];
    [self bindWithName:@"amplitudeMaxY1"];
    [self bindWithName:@"amplitudeMaxY2"];
    [self bindWithName:@"amplitudeMaxY3"];

    [self bindWithName:@"frequencyMinX1"];
    [self bindWithName:@"frequencyMinX2"];
    [self bindWithName:@"frequencyMinX3"];
    [self bindWithName:@"frequencyMaxX1"];
    [self bindWithName:@"frequencyMaxX2"];
    [self bindWithName:@"frequencyMaxX3"];

    [self bindWithName:@"frequencyMinY1"];
    [self bindWithName:@"frequencyMinY2"];
    [self bindWithName:@"frequencyMinY3"];
    [self bindWithName:@"frequencyMaxY1"];
    [self bindWithName:@"frequencyMaxY2"];
    [self bindWithName:@"frequencyMaxY3"];
}



ページの先頭へ戻る