raed
raed

Reputation: 5075

Is there way to use NSParagraphStyle.default.mutableCopy() without force unwraping?

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?

Upvotes: 2

Views: 1204

Answers (1)

vadian
vadian

Reputation: 285260

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.

Upvotes: 11

Related Questions