{"id":22000,"date":"2018-07-02T15:24:15","date_gmt":"2018-07-02T19:24:15","guid":{"rendered":"https:\/\/mjtsai.com\/blog\/?p=22000"},"modified":"2018-07-02T15:24:15","modified_gmt":"2018-07-02T19:24:15","slug":"nsonstate-is-deprecated","status":"publish","type":"post","link":"https:\/\/mjtsai.com\/blog\/2018\/07\/02\/nsonstate-is-deprecated\/","title":{"rendered":"NSOnState Is Deprecated"},"content":{"rendered":"<p><a href=\"https:\/\/lapcatsoftware.com\/articles\/NSOnState.html\">Jeff Johnson<\/a> (<a href=\"https:\/\/twitter.com\/lapcatsoftware\/status\/1013465153105465344\">tweet<\/a>):<\/p>\n<blockquote cite=\"https:\/\/lapcatsoftware.com\/articles\/NSOnState.html\">\n<p>I&rsquo;m going to discuss one change in the Objective-C API, because it is both illustrative and egregious. In the 10.14 SDK, the Objective-C constants <code>NSOnState<\/code>, <code>NSOffState<\/code>, and <code>NSMixedState<\/code> have been deprecated:<\/p>\n<blockquote><pre>typedef NSControlStateValue NSCellStateValue NS_DEPRECATED_WITH_REPLACEMENT_MAC(\"NSControlStateValue\", 10_0, 10_14);\nstatic const NSControlStateValue NSMixedState NS_DEPRECATED_WITH_REPLACEMENT_MAC(\"NSControlStateValueMixed\", 10_0, 10_14) = NSControlStateValueMixed;\nstatic const NSControlStateValue NSOffState NS_DEPRECATED_WITH_REPLACEMENT_MAC(\"NSControlStateValueOff\", 10_0, 10_14) = NSControlStateValueOff;\nstatic const NSControlStateValue NSOnState NS_DEPRECATED_WITH_REPLACEMENT_MAC(\"NSControlStateValueOn\", 10_0, 10_14) = NSControlStateValueOn;<\/pre><\/blockquote>\n<p>Notice that these Objective-C constants were introduced in the 10.0 SDK. They&rsquo;ve been around for the entire history of Mac OS X.<\/p>\n<\/blockquote>\n\n<p><a href=\"https:\/\/twitter.com\/eridius\/status\/1013468412868284416\">Kevin Ballard<\/a>:<\/p>\n<blockquote cite=\"https:\/\/twitter.com\/eridius\/status\/1013468412868284416\">\n<p>This change is good even ignoring Swift because it makes the constant consistent with the vast majority of other SDK constants. This makes it more discoverable, easier to remember, and is much better and less confusing for people new to AppKit.<\/p>\n<\/blockquote>\n\n<p><a href=\"https:\/\/twitter.com\/lapcatsoftware\/status\/1013493215998210049\">Jeff Johnson<\/a>:<\/p>\n<blockquote cite=\"https:\/\/twitter.com\/lapcatsoftware\/status\/1013493215998210049\">\n<p>It seems pretty clear to me that the original Cocoa API designers made the conscious choice to put the most important and informative part of a symbol name first rather than last.<\/p>\n<p>This is a legit philosophy. You may agree or disagree, but in any case it&rsquo;s consistent.<\/p>\n<\/blockquote>\n<p>It was, but they&rsquo;ve been gradually reversing the order in the names since before Swift existed. In most cases I think this is for the better, although in the interim it means that Cocoa has been internally inconsistent for a long time.<\/p>\n<p>The two points I would add are:<\/p>\n<ul>\n<li><p><code>NSControlStateValueOn<\/code> may be easier to discover or understand, but it&rsquo;s worse to read: longer and with the most important part at the end. Aside from the practical concerns of breaking builds, documentation, and sample code, I think renaming this commonly used constant everywhere will make the code read less well. There&rsquo;s a balance to be struck between competing concerns. The same arguments in favor of this change could also apply to renaming <code>YES<\/code> to something like <code>NSBooleanValueYes<\/code> or <code>BOOL_YES<\/code>, but I think people would agree that would not be beneficial.<\/p><\/li>\n<li><p>Adding the new names does solve some real problems, but I&rsquo;m not sure that removing the old ones does. Perhaps they shouldn&rsquo;t fill up the autocomplete menu, but I don&rsquo;t see why they have to become compiler errors. Am I greatly bothered by this? No. I&rsquo;m not personally going to be confused by this, and most of my new code is in Swift, anyway. But it does seem unnecessary.<\/p><\/li>\n<\/ul>\n\n<p><a href=\"https:\/\/twitter.com\/lapcatsoftware\/status\/1013603624763707392\">Jeff Johnson<\/a>:<\/p>\n<blockquote cite=\"https:\/\/twitter.com\/lapcatsoftware\/status\/1013603624763707392\"><p>Seriously, though, imagine a newcomer, how do they learn? A good way is to download sample code. Except the sample code doesn&rsquo;t get updated frequently, so their first experience with AppKit and Objective-C is deprecation build warnings. How would you feel about that as a learner?<\/p><\/blockquote>","protected":false},"excerpt":{"rendered":"<p>Jeff Johnson (tweet): I&rsquo;m going to discuss one change in the Objective-C API, because it is both illustrative and egregious. In the 10.14 SDK, the Objective-C constants NSOnState, NSOffState, and NSMixedState have been deprecated: typedef NSControlStateValue NSCellStateValue NS_DEPRECATED_WITH_REPLACEMENT_MAC(\"NSControlStateValue\", 10_0, 10_14); static const NSControlStateValue NSMixedState NS_DEPRECATED_WITH_REPLACEMENT_MAC(\"NSControlStateValueMixed\", 10_0, 10_14) = NSControlStateValueMixed; static const NSControlStateValue NSOffState NS_DEPRECATED_WITH_REPLACEMENT_MAC(\"NSControlStateValueOff\", 10_0, [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"apple_news_api_created_at":"2018-07-02T19:24:17Z","apple_news_api_id":"75df3091-9408-498e-9358-36676fca4102","apple_news_api_modified_at":"2018-07-02T19:24:18Z","apple_news_api_revision":"AAAAAAAAAAD\/\/\/\/\/\/\/\/\/\/w==","apple_news_api_share_url":"https:\/\/apple.news\/Add8wkZQISY6TWDZnb8pBAg","apple_news_coverimage":0,"apple_news_coverimage_caption":"","apple_news_is_hidden":false,"apple_news_is_paid":false,"apple_news_is_preview":false,"apple_news_is_sponsored":false,"apple_news_maturity_rating":"","apple_news_metadata":"\"\"","apple_news_pullquote":"","apple_news_pullquote_position":"","apple_news_slug":"","apple_news_sections":"\"\"","apple_news_suppress_video_url":false,"apple_news_use_image_component":false,"footnotes":""},"categories":[],"tags":[69,1609,54,71,901,226],"class_list":["post-22000","post","type-post","status-publish","format-standard","hentry","tag-cocoa","tag-macos-10-14","tag-objective-c","tag-programming","tag-swift-programming-language","tag-xcode"],"apple_news_notices":[],"_links":{"self":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/22000","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/comments?post=22000"}],"version-history":[{"count":1,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/22000\/revisions"}],"predecessor-version":[{"id":22001,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/22000\/revisions\/22001"}],"wp:attachment":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/media?parent=22000"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/categories?post=22000"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/tags?post=22000"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}