Ad

Our DNA is written in Swift
Jump

Radar: NSParagraphStyle’s +defaultParagraphStyle return type should be instancetype

This minor SDK inconsistency was submitted as rdar://16939304 and to OpenRadar.

Summary

The method +[NSParagraphStyle defaultParagraphStyle] returns an NSParagraphStyle. It should return instancetype instead for consistence.

Steps to Reproduce

Add this code to a new project:

NSMutableParagraphStyle *paragraphStyle = [NSMutableParagraphStyle defaultParagraphStyle];

Expected Results

  • to get an NSMutableParagraphStyle instance initialized with the default paragraph style.
  • be able to change values to my liking

Actual Results

  • you get a compiler warning about incompatible pointer types
  • an NSParagraphStyle is returned
  • trying to assign a value to a property produces an exception

Notes

This should work consistently with other classes where you have an immutable version and a mutable version being a subclass of it. e.g. NSArray and NSMutableArray. There you can use [NSArray array] and [NSMutableArray array] and get the correct class.


Categories: Bug Reports

1 Comment »

  1. Actually this behavior is correct as the method name is defaultParagraphStyle and not just paragraphStyle. It’s like [SKPaymentQueue defaultQueue]: it’s a singleton, not a factory method. [NSArray array] etc. are factory methods, not singletons.

    Creating a new mutable default paragraph style should be as easy as [[NSParagraphStyle defaultParagraphStyle] mutableCopy].