{"id":10719,"date":"2015-02-06T17:22:32","date_gmt":"2015-02-06T22:22:32","guid":{"rendered":"http:\/\/mjtsai.com\/blog\/?p=10719"},"modified":"2015-02-06T17:22:32","modified_gmt":"2015-02-06T22:22:32","slug":"building-swift-bindings-to-libgit2","status":"publish","type":"post","link":"https:\/\/mjtsai.com\/blog\/2015\/02\/06\/building-swift-bindings-to-libgit2\/","title":{"rendered":"Building Swift Bindings to libgit2"},"content":{"rendered":"<p><a href=\"http:\/\/modocache.svbtle.com\/swift-and-c\">Brian Gesiak<\/a>:<\/p>\n<blockquote cite=\"http:\/\/modocache.svbtle.com\/swift-and-c\"><p>The <code>str<\/code> parameter is of type <code>UnsafePointer&lt;Int8&gt;<\/code>, but thanks to Swift&rsquo;s ability to interoperate with C, we can just pass this function a Swift <code>String<\/code>. Read <a href=\"https:\/\/developer.apple.com\/swift\/blog\/?id=6\">the Apple blog article linked above<\/a> for details.<\/p><p>[&#8230;]<\/p><p>Unfortunately, in <a href=\"http:\/\/dev.eltima.com\/post\/97718928834\/interacting-with-c-pointers-in-swift-part-3\">Interacting with C Pointers in Swift<\/a>, <a href=\"https:\/\/twitter.com\/develtima\">@develtima<\/a> explains that we can&rsquo;t get a usable <code>CFunctionPointer<\/code> to a function defined in Swift.<\/p><p>So instead, <a href=\"https:\/\/github.com\/modocache\/Gift\">Gift<\/a> defines Objective-C helper functions that take a Swift closure, and execute that closure from within a C callback function.<\/p><\/blockquote>","protected":false},"excerpt":{"rendered":"<p>Brian Gesiak: The str parameter is of type UnsafePointer&lt;Int8&gt;, but thanks to Swift&rsquo;s ability to interoperate with C, we can just pass this function a Swift String. Read the Apple blog article linked above for details.[&#8230;]Unfortunately, in Interacting with C Pointers in Swift, @develtima explains that we can&rsquo;t get a usable CFunctionPointer to a function [&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":[45,377,54,71,901],"class_list":["post-10719","post","type-post","status-publish","format-standard","hentry","category-programming-category","tag-c","tag-git","tag-objective-c","tag-programming","tag-swift-programming-language"],"apple_news_notices":[],"_links":{"self":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/10719","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=10719"}],"version-history":[{"count":1,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/10719\/revisions"}],"predecessor-version":[{"id":10720,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/10719\/revisions\/10720"}],"wp:attachment":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/media?parent=10719"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/categories?post=10719"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/tags?post=10719"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}