{"id":12080,"date":"2015-08-23T10:57:17","date_gmt":"2015-08-23T14:57:17","guid":{"rendered":"http:\/\/mjtsai.com\/blog\/?p=12080"},"modified":"2015-08-23T10:57:17","modified_gmt":"2015-08-23T14:57:17","slug":"objective-c-what-could-possibly-go-wrong","status":"publish","type":"post","link":"https:\/\/mjtsai.com\/blog\/2015\/08\/23\/objective-c-what-could-possibly-go-wrong\/","title":{"rendered":"[Objective] C++: What Could Possibly Go Wrong?"},"content":{"rendered":"<p><a href=\"https:\/\/realm.io\/news\/altconf-peter-steinberger-objective-c++-what-could-possibly-go-wrong\/\">Peter Steinberger\n<\/a>:<\/p>\n<blockquote cite=\"https:\/\/realm.io\/news\/altconf-peter-steinberger-objective-c++-what-could-possibly-go-wrong\/\">\n<p>First, Swift interoperates with Objective-C and C, but it doesn&rsquo;t work with C++ directly. Therefore, if you want to use Swift, being knowledgeable of Objective-C++ might actually help you, because it enables you to write a wrapper that wraps any third party library that might only exist in C++ with Objective-C.<\/p>\n<p>[&#8230;]<\/p>\n<p>This is not your grandmother&rsquo;s C++. We have auto, which is type deduction. We have shared pointers, which is basically ARC. We have <code>weak<\/code>, which is also something we have in the Objective-C run time. We have lambdas, which is just a fancier name for blocks, and we have move semantics, which is something I&rsquo;ll explain later because it&rsquo;s a little crazy.<\/p>\n<p>[&#8230;]<\/p>\n<p>There are gotchas! One thing you&rsquo;ll notice when you play with Objective-C++ is compile time. Depending on how much of it you start using, things will get slower, and they might take twice or three times as long. It&rsquo;s still much faster than compiling Swift (at the moment), but it is noticeable and you should be mindful of not blindly renaming all your files to .mm because you can, only where it makes sense, and where you should.<\/p>\n<p>[&#8230;]<\/p>\n<p>The last thing we can do is write our own smart pointer that wraps <code>CGPathRef<\/code> and knows how to deal with Core Foundation objects. Don&rsquo;t think I&rsquo;m crazy, this is actually what WebKit does internally, they deal with a lot of Core Foundation objects and they want to get it right. We use something that&rsquo;s <code>CFPointer<\/code>, and it&rsquo;s not really much code, maybe 100 lines if you want to have move semantics and all those nice little details.<\/p>\n<\/blockquote>","protected":false},"excerpt":{"rendered":"<p>Peter Steinberger : First, Swift interoperates with Objective-C and C, but it doesn&rsquo;t work with C++ directly. Therefore, if you want to use Swift, being knowledgeable of Objective-C++ might actually help you, because it enables you to write a wrapper that wraps any third party library that might only exist in C++ with Objective-C. [&#8230;] [&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":[326,738,31,571,54,71,901],"class_list":["post-12080","post","type-post","status-publish","format-standard","hentry","category-programming-category","tag-c-plus-plus","tag-conference","tag-ios","tag-memory-management","tag-objective-c","tag-programming","tag-swift-programming-language"],"apple_news_notices":[],"_links":{"self":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/12080","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=12080"}],"version-history":[{"count":1,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/12080\/revisions"}],"predecessor-version":[{"id":12081,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/12080\/revisions\/12081"}],"wp:attachment":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/media?parent=12080"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/categories?post=12080"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/tags?post=12080"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}