{"id":11894,"date":"2015-07-31T13:04:49","date_gmt":"2015-07-31T17:04:49","guid":{"rendered":"http:\/\/mjtsai.com\/blog\/?p=11894"},"modified":"2015-09-07T10:37:15","modified_gmt":"2015-09-07T14:37:15","slug":"objective-c-improvements-and-swift-interoperability","status":"publish","type":"post","link":"https:\/\/mjtsai.com\/blog\/2015\/07\/31\/objective-c-improvements-and-swift-interoperability\/","title":{"rendered":"Objective-C Improvements and Swift Interoperability"},"content":{"rendered":"<p><a href=\"http:\/\/asciiwwdc.com\/2015\/sessions\/401\">WWDC 2015 Session 401<\/a> (<a href=\"https:\/\/developer.apple.com\/videos\/wwdc\/2015\/?id=401\">video<\/a>, <a href=\"http:\/\/devstreaming.apple.com\/videos\/wwdc\/2015\/401gee20yy5v2men\/401\/401_swift_and_objectivec_interoperability.pdf?dl=1\">PDF<\/a>):<\/p>\r\n<blockquote cite=\"http:\/\/asciiwwdc.com\/2015\/sessions\/401\"><p>Go to any Objective-C header and choose the &lsquo;show related items&rsquo; button in the top-left corner. This will bring down a menu of related items, one of which is &lsquo;generated interface.&rsquo; And this will show you the Swift mapping for that header. This is the exact same view that you got in Xcode 6 using the &lsquo;jump to definition&rsquo; feature, but now you can get it easily from any header in your target.<\/p>\r\n<p>[&#8230;]<\/p>\r\n<p>Now, on both of these examples, I have shown that these methods in Objective-C have multiple parameters, only one of which is the error parameter, but there are also cases where methods only have one parameter and you will get something like &lsquo;check resource is researchable and return error.&rsquo; As you can see in Swift, since we already know that the method can return an error from that &lsquo;throws&rsquo; keyword, we will chop off those last three words for you, just for you!<\/p><\/blockquote>\r\n<p>I guess that answers <a href=\"http:\/\/mjtsai.com\/blog\/2013\/08\/28\/cocoa-nserror-conventions\/\">my question<\/a>.<\/p>\r\n<p><a href=\"https:\/\/medium.com\/the-traveled-ios-developers-guide\/objective-c-in-2015-3cb7dab3690c\">Jordan Morgan<\/a>:<\/p>\r\n<blockquote cite=\"https:\/\/medium.com\/the-traveled-ios-developers-guide\/objective-c-in-2015-3cb7dab3690c\">\r\n<p>The first step to making this better is one of my favorite new Objective-C features, nullability annotations.<\/p>\r\n<p>[&#8230;]<\/p>\r\n<p>Though it took about thirty-two years, generics is now a thing in Objective-C.<\/p>\r\n<p>[&#8230;]<\/p>\r\n<p>Essentially, we&rsquo;ve informed the compiler that the property and its collection will have <em>some kind of a UIView<\/em>. This allows for more information in the type contract that we&rsquo;ve not had before.<\/p>\r\n<p>The real treat? Implicit downcasting.<\/p>\r\n<\/blockquote>\r\n<p><a href=\"http:\/\/drekka.ghost.io\/objective-c-generics\/\">drekka<\/a>:<\/p>\r\n<blockquote cite=\"http:\/\/drekka.ghost.io\/objective-c-generics\/\"><p>There&rsquo;s a couple of this going on here. Firstly you will notice that we are not using <code>ObjectType<\/code> anywhere. It appears that the name of a Generic reference is only usable in the header of a class. I&rsquo;ve tried all sorts of syntaxes to see if there was a way to declare and use it in the implementation, but I&rsquo;ve been unsuccessful. So I&rsquo;ve concluded that Objective-C Generics simply don&rsquo;t make the placeholders available to implementations. Unfortunately I cannot confirm against Apples code.<\/p>\r\n<p>What I have concluded is that when a Generic is resolved by the compiler, it resolves to the top most class that can replace it. Normally this is <code>id<\/code>, however bounded Generics can make this more specific. See <a href=\"http:\/\/drekka.ghost.io\/objective-c-generics\/#restrictinggenerics\">Restricting Generics<\/a> below.<\/p>\r\n<\/blockquote>\r\n<p><a href=\"https:\/\/twitter.com\/jckarter\/status\/619518413484920832\">Joe Groff<\/a>:<\/p>\r\n<blockquote cite=\"https:\/\/twitter.com\/jckarter\/status\/619518413484920832\"><p>ObjC generics also can&rsquo;t be part of the canonical type system without breaking C++ templates<\/p><\/blockquote>","protected":false},"excerpt":{"rendered":"<p>WWDC 2015 Session 401 (video, PDF): Go to any Objective-C header and choose the &lsquo;show related items&rsquo; button in the top-left corner. This will bring down a menu of related items, one of which is &lsquo;generated interface.&rsquo; And this will show you the Swift mapping for that header. This is the exact same view that [&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":"","apple_news_api_id":"","apple_news_api_modified_at":"","apple_news_api_revision":"","apple_news_api_share_url":"","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":[4],"tags":[69,738,31,46,30,857,54,71,901,1221,226],"class_list":["post-11894","post","type-post","status-publish","format-standard","hentry","category-programming-category","tag-cocoa","tag-conference","tag-ios","tag-languagedesign","tag-mac","tag-nserror","tag-objective-c","tag-programming","tag-swift-programming-language","tag-wwdc","tag-xcode"],"apple_news_notices":[],"_links":{"self":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/11894","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=11894"}],"version-history":[{"count":4,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/11894\/revisions"}],"predecessor-version":[{"id":12194,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/11894\/revisions\/12194"}],"wp:attachment":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/media?parent=11894"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/categories?post=11894"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/tags?post=11894"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}