objective-cnsfont

NSFont text size with variables: EXC_BAD_ACCESS (Code=1, address=0X3)


I'm keep getting the EXC_BAD_ACCESS error when I change this code from

label.font      = [NSFont systemFontOfSize:(80)];

to

label.font      = [NSFont systemFontOfSize:*(((messageSize)))];

The messageSize is set as a double like this.

double  *messageSize;

What am I doing wrong?


Solution

  • The asterisk is the symbol for a pointer, that's wrong.
    A double is a simple scalar type.

    double  messageSize;
    

    And you can omit all parentheses.

    label.font = [NSFont systemFontOfSize:messageSize];
    

    PS: Actually the expected type of systemFontOfSize is CGFloat which is a float on 32 bit and a doubleon 64 bit systems.