{"id":40772,"date":"2023-10-11T17:21:08","date_gmt":"2023-10-11T21:21:08","guid":{"rendered":"https:\/\/mjtsai.com\/blog\/?p=40772"},"modified":"2023-10-11T17:21:08","modified_gmt":"2023-10-11T21:21:08","slug":"rescuing-files-from-classic-mac-os-with-swift","status":"publish","type":"post","link":"https:\/\/mjtsai.com\/blog\/2023\/10\/11\/rescuing-files-from-classic-mac-os-with-swift\/","title":{"rendered":"Rescuing Files From Classic Mac OS...with Swift"},"content":{"rendered":"<p><a href=\"https:\/\/belkadan.com\/blog\/2023\/01\/Rescuing-Files-with-Swift\/\">Jordan Rose<\/a>:<\/p>\n<blockquote cite=\"https:\/\/belkadan.com\/blog\/2023\/01\/Rescuing-Files-with-Swift\/\">\n<p>The biggest benefits of doing this project in Swift are very similar to what the benefits would have been for using C++, back in the 90s, but with even more safety. Take directory walking. In C, this looks something like the following:<\/p>\n<pre>FSIterator *iter;\nOSStatus err = FSOpenIterator(&#38;directory, kFSIterateFlat, &#38;iter);\nif (err != noErr) { return err; }\n\/\/ use iter\nFSCloseIterator(iter); \/\/ hopefully no early exits!<\/pre>\n<p>But in Swift, without wrapping this API at all&#8230;<\/p>\n<pre>var iter: FSIterator? = nil\ntry FSOpenIterator(&#38;directory, .init(kFSIterateFlat), &#38;iter).check()\ndefer { FSCloseIterator(iter) }\n<\/pre>\n<p>Is it shorter? Not much. Is it nicer? Absolutely! First off, we have defer to ensure no resources are leaked even if there&rsquo;s an early-exit later in the function. But it&rsquo;s that throwing check() method that really changes the game.<\/p>\n<\/blockquote>","protected":false},"excerpt":{"rendered":"<p>Jordan Rose: The biggest benefits of doing this project in Swift are very similar to what the benefits would have been for using C++, back in the 90s, but with even more safety. Take directory walking. In C, this looks something like the following: FSIterator *iter; OSStatus err = FSOpenIterator(&#38;directory, kFSIterateFlat, &#38;iter); if (err != [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"apple_news_api_created_at":"2023-10-11T21:21:11Z","apple_news_api_id":"6a4b2175-f617-4786-9525-0dcf14324d93","apple_news_api_modified_at":"2023-10-11T21:21:11Z","apple_news_api_revision":"AAAAAAAAAAD\/\/\/\/\/\/\/\/\/\/w==","apple_news_api_share_url":"https:\/\/apple.news\/AakshdfYXR4aVJQ3PFDJNkw","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,755,733,1902,30,923,924,608,857,1331,71,759,901],"class_list":["post-40772","post","type-post","status-publish","format-standard","hentry","category-programming-category","tag-c","tag-carbon","tag-emulator","tag-extended-attributes","tag-mac","tag-mac-os-8","tag-mac-os-9","tag-metadata","tag-nserror","tag-powerbook","tag-programming","tag-resource-fork","tag-swift-programming-language"],"apple_news_notices":[],"_links":{"self":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/40772","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=40772"}],"version-history":[{"count":1,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/40772\/revisions"}],"predecessor-version":[{"id":40773,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/40772\/revisions\/40773"}],"wp:attachment":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/media?parent=40772"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/categories?post=40772"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/tags?post=40772"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}