2

I m trying to get an instance of NSParagraphStyle.default.mutableCopy() but are we sure that mutableCopy() will always contain a value?

var paragraphStyle = NSParagraphStyle.default.mutableCopy() as! NSMutableParagraphStyle

Would it possible to do this without force unwraping?

raed
  • 4,887
  • 4
  • 30
  • 49

1 Answers1

10

Yes, it's much simpler:

let paragraphStyle = NSMutableParagraphStyle() // Note the `let`

You get the default parameters with the default initializer.


Apart from that in this case you can be sure that mutableCopy() will always contain a value because NSParagraphStyle clearly conforms to NSCopying.

vadian
  • 274,689
  • 30
  • 353
  • 361