> On Oct 14, 2015, at 6:36 PM, Shane Stanley <sstan...@myriad-com.com.au> wrote:
> 
> On 15 Oct 2015, at 4:02 AM, David Duncan <david.dun...@apple.com 
> <mailto:david.dun...@apple.com>> wrote:
>> 
>> The helpful followup is that it is generally encouraged to use empty 
>> containers (@[] or @{}) over nil when there is no semantic difference, as is 
>> the case for the aforementioned API.
> 
> OK, but the docs still say: "The dictionary contains values from Document 
> Types and must at least contain NSDocumentTypeDocumentAttribute." That 
> suggests to me that an empty dictionary is not allowed.

The docs and headers for NSAttributedString contain a lot of copy/paste stuff, 
which I think is part of the problem. The bit you quoted is copied directly 
from the description for -[NSAttributedString 
dataFromRange:documentAttribute:error:], which notably does *not* contain the 
bit about nil being allowed for the dictionary. This is because this method 
returns data in an unspecified format, so if you don’t provide the dictionary 
and specify a document type attribute, there is no way that it can know what to 
do. For the type-specific variants of this method, like 
docFormatFromRange:bla:bla: and RTFFromRange:bla:bla:, the output document 
format is known, so NSDocumentTypeDocumentAttribute isn’t really necessary, and 
indeed, if you supply it, it seems to be ignored. So, the documentation 
contains a note here that the dictionary can be nil—and if you try it, it works 
fine.

So, to my mind, it makes sense for dataFromRange:bla:bla: to have a 
non-optional attributes parameter, and for the rest of them to have an optional 
one. But even if you don’t agree, the bottom line is that something needs to be 
changed, whether that be the headers or the documentation, since the 
documentation does say that it can be nil.

Charles

_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to