objective-cios7uikituifontuifontdescriptor

Why am I unable to save my UIFontDescriptor into a variable?


I have the following code:

UIFontDescriptor *fd = [UIFont fontWithDescriptor:[[UIFont systemFontOfSize:[UIFont systemFontSize]].fontDescriptor fontDescriptorWithSymbolicTraits:UIFontDescriptorTraitBold|UIFontDescriptorTraitItalic];

But it gives me the error "Expected expression". What does that mean?


Solution

  • Initially, I counted 4 open brackets and 3 close brackets, which will cause an error. Additionally, fontWithDescriptor: should be fontWithDescriptor:size:, which is probably the expected expression.

    Finally, using fontWithDescriptor:size: to define a font, then asking for its descriptor is redundant, so a cleaner version of the command is this:

    UIFontDescriptor *fd = [[[UIFont systemFontOfSize:[UIFont systemFontSize]] fontDescriptor] fontDescriptorWithSymbolicTraits:UIFontDescriptorTraitBold|UIFontDescriptorTraitItalic];