{"id":13923,"date":"2016-03-20T11:04:23","date_gmt":"2016-03-20T15:04:23","guid":{"rendered":"http:\/\/mjtsai.com\/blog\/?p=13923"},"modified":"2016-03-20T11:04:53","modified_gmt":"2016-03-20T15:04:53","slug":"gathering-system-information-in-swift-with-sysctl","status":"publish","type":"post","link":"https:\/\/mjtsai.com\/blog\/2016\/03\/20\/gathering-system-information-in-swift-with-sysctl\/","title":{"rendered":"Gathering System Information in Swift With sysctl"},"content":{"rendered":"<p><a href=\"http:\/\/www.cocoawithlove.com\/blog\/2016\/03\/08\/swift-wrapper-for-sysctl.html\">Matt Gallagher<\/a>:<\/p>\n<blockquote cite=\"http:\/\/www.cocoawithlove.com\/blog\/2016\/03\/08\/swift-wrapper-for-sysctl.html\">\n<p>The reason why <code>sysctl<\/code> feels so cumbersome in Swift is:<\/p>\n<ul>\n  <li>Creating an array of <code>Int32<\/code> and passing that by pointer for the first parameter is a nuisance in Swift<\/li>\n  <li>You basically need to call <code>sysctl<\/code> twice: once with <code>oldp<\/code> equal to <code>nil<\/code> to get the size required for the result buffer and then a second time with a properly allocated buffer.<\/li>\n  <li>The result is returned as an untyped buffer of bytes which you then need to interpret correctly.<\/li>\n  <li>There are a few different ways in which failure can occur and we want to reduce these different ways to idiomatic Swift errors or preconditions.<\/li>\n<\/ul>\n<p>For these reasons, I use a wrapper around <code>sysctl<\/code>[&#8230;]<\/p>\n<\/blockquote>","protected":false},"excerpt":{"rendered":"<p>Matt Gallagher: The reason why sysctl feels so cumbersome in Swift is: Creating an array of Int32 and passing that by pointer for the first parameter is a nuisance in Swift You basically need to call sysctl twice: once with oldp equal to nil to get the size required for the result buffer and then [&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":[31,30,71,901,163],"class_list":["post-13923","post","type-post","status-publish","format-standard","hentry","category-programming-category","tag-ios","tag-mac","tag-programming","tag-swift-programming-language","tag-unix"],"apple_news_notices":[],"_links":{"self":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/13923","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=13923"}],"version-history":[{"count":2,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/13923\/revisions"}],"predecessor-version":[{"id":13927,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/13923\/revisions\/13927"}],"wp:attachment":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/media?parent=13923"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/categories?post=13923"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/tags?post=13923"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}