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

149 Views Asked by At

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?

1

There are 1 best solutions below

0
On BEST ANSWER

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];