nsalert

NSAlert in XCode 7


I'm looking to update this code for 10.8 to 10.11. Here is original code.

            NSAlert *alertSheet = [NSAlert alertWithMessageText:@"Message Text." defaultButton:@"OK" alternateButton:nil otherButton:nil informativeTextWithFormat:@"Informative text PJ%@-%@ with more text.", self.projectNumber,self.projectName];
        [alertSheet setAlertStyle:NSCriticalAlertStyle];
        [alertSheet beginSheetModalForWindow:self.window modalDelegate:nil didEndSelector:nil contextInfo:nil];

Some of the code is deprecated. Here is what I have going so far but it doesn't work.

            NSAlert *alertSheet = [[NSAlert alloc]init];
        [alertSheet setMessageText:@"Message Text."];
        [alertSheet setInformativeText:@"Informative text PJ%@-%@ with more text.", self.projectNumber,self.projectName];
        [alertSheet beginSheetModalForWindow:self.windowPreferences completionHandler:nil];

Solution

  • informativeText is not variadic (has never been)

    [alertSheet setInformativeText:[NSString stringWithFormat:@"Informative text PJ%@-%@ with more text.",  self.projectNumber,self.projectName]];
    

    You can also use dot notation

    alertSheet.informativeText = [NSString stringWithFormat...