<div dir="ltr">If the method param is annotated, not only does the user get a hint for where to look in the docs, but you can omit the type name qualification, saying quantityForTypeIdentifier(.BodyMass).<div><br></div><div>Sounds great to me.</div><div class="gmail_extra"><br clear="all"><div><div class="gmail_signature"><div dir="ltr"><div>Jacob<br></div></div></div></div>
<br><div class="gmail_quote">On Mon, Jan 18, 2016 at 10:20 AM, Jeff Kelley via swift-evolution <span dir="ltr"><<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word"><div><span class=""><blockquote type="cite"><div>On Jan 18, 2016, at 12:41 PM, Philippe Hausler <<a href="mailto:phausler@apple.com" target="_blank">phausler@apple.com</a>> wrote:</div><br><div><div style="word-wrap:break-word"><div>One note to those constants; there are a number of them (NSError domains in particular) that are intended to be a complement to the application space defines; such that your app could define a “MyGreatAppErrorDomain” and a “MyGreatFrameworkErrorDomain” in addition to the NSCocoaErrorDomain. So this isn’t exactly an enum but more so a non closed set of values. Enums are usually closed sets so that they can be switched upon exhaustively. Others would definitely improve the state of affairs for both objc and swift in that technically you could get a warning/error in objc if the type was not correct and there would be the swift ramifications you mentioned as well.</div></div></div></blockquote><div><br></div></span><div>Great point, and for that reason I switched away from NSError domains in my proposal. It’s a much more clear win to use this for something like HealthKit constants where values outside of the constants may not be used. For NSError domains, leaving the type as NSString is probably best to indicate that custom strings are supported.</div><span class=""><br><blockquote type="cite"><div style="word-wrap:break-word"><div>On the other hand it might be useful for the (desperately in need of some updating) NSLocale method</div><div><br></div><div>@interface NSLocale : NSObject <NSCopying, NSSecureCoding><br>...<br>- (nullable id)objectForKey:(NSLocaleKey)key; // we could limit the keys accepted here to just the appropriate values in the “enum"</div><div>...</div><div>@end</div><div><br></div><div><br></div><div>>From a brief survey of the APIs this would be useful for they mostly seem to be “dictionary based programming” cases which expose poorly in swift because they don’t have type safe return values. Adding more swift-friendly interfaces to those APIs is not off the table; because it is not just the keys that are the issue here but the return values too (see NSLocale’s example). Not to say we couldn’t do both, but would it be the case that if the un-typed return values that access by keys are replaced with better, more safe interfaces, this still be needed?</div></div></blockquote><div><br></div></span><div>The “dictionary based programming” examples could definitely use a bit of an API refresh, as you’ve noticed with the return types. This proposal’s real aim is APIs that use strings to mean one of a finite set of values. Take HealthKit:</div><div><br></div><div><blockquote type="cite">+ (nullable HKQuantityType *)quantityTypeForIdentifier:(NSString *)identifier;</blockquote></div><div><br></div><div>The return value here is typesafe, but the identifier is a string. HKTypeIdentifiers.h defines these identifiers. Here’s one set:</div><div><br></div><div></div><blockquote type="cite"><div>HK_EXTERN NSString * const HKQuantityTypeIdentifierBodyMassIndex;<div>HK_EXTERN NSString * const HKQuantityTypeIdentifierBodyFatPercentage;</div><div>HK_EXTERN NSString * const HKQuantityTypeIdentifierHeight;</div><div>HK_EXTERN NSString * const HKQuantityTypeIdentifierBodyMass;</div><div>HK_EXTERN NSString * const HKQuantityTypeIdentifierLeanBodyMass;</div></div></blockquote><div><br></div><div>Since the user isn’t permitted to use their own identifiers here, this is an ideal case for replacement. It also gives the user a better hint as to where to find these constants. Rewriting the Objective-C method along these lines:</div><div><br></div><div><div><blockquote type="cite">+ (nullable HKQuantityType *)quantityTypeForIdentifier:(HKQuantityTypeIdentifier)identifier;</blockquote><div><br></div></div></div><div>Would give the user a hint in the name of the type for where to look in the documentation for these identifiers.</div><div><br></div><div>I think frameworks like HealthKit with constant string identifiers would benefit greatly from this change, as would other frameworks like CoreText with opaque keys and values used to construct dictionaries.</div><span class=""><div><br></div><div><br></div><div><div style="font-family:Helvetica;line-height:normal;text-align:-webkit-auto;word-wrap:break-word"><div style="line-height:normal;text-align:-webkit-auto;word-wrap:break-word"><div style="line-height:normal;text-align:-webkit-auto;word-wrap:break-word"><span style="border-collapse:separate;line-height:normal;border-spacing:0px"><div style="word-wrap:break-word"><div>Jeff Kelley</div><div><br></div><div><a href="mailto:SlaunchaMan@gmail.com" target="_blank">SlaunchaMan@gmail.com</a> | <a href="https://twitter.com/SlaunchaMan" target="_blank">@SlaunchaMan</a> | <a href="http://jeffkelley.org" target="_blank">jeffkelley.org</a></div></div></span></div></div></div></div><br><div><blockquote type="cite"></blockquote></div></span></div><br></div><br>_______________________________________________<br>
swift-evolution mailing list<br>
<a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a><br>
<a href="https://lists.swift.org/mailman/listinfo/swift-evolution" rel="noreferrer" target="_blank">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br>
<br></blockquote></div><br></div></div>