{"id":2096,"date":"2009-11-13T17:56:39","date_gmt":"2009-11-13T22:56:39","guid":{"rendered":"http:\/\/mjtsai.com\/blog\/?p=2096"},"modified":"2020-04-21T13:59:24","modified_gmt":"2020-04-21T17:59:24","slug":"dangerous-cocoa-calls","status":"publish","type":"post","link":"https:\/\/mjtsai.com\/blog\/2009\/11\/13\/dangerous-cocoa-calls\/","title":{"rendered":"Dangerous Cocoa Calls"},"content":{"rendered":"<p><a href=\"http:\/\/www.mikeash.com\/?page=pyblog\/friday-qa-2009-11-13-dangerous-cocoa-calls.html\">Mike Ash<\/a> has a great list of Cocoa APIs that are subtly dangerous. Note that since <code>NSBundle<\/code> isn&rsquo;t threadsafe, neither is <code>NSLocalizedString<\/code>.<\/p>\n<p>Update (2017-02-20): <a href=\"https:\/\/forums.swift.org\/t\/pitch-replacement-for-filehandle\/5177\">Charles Srstka<\/a>:<\/p>\n<blockquote cite=\"https:\/\/forums.swift.org\/t\/pitch-replacement-for-filehandle\/5177\"><p>In Swift 3, NSFileHandle was renamed to FileHandle, making it the de facto file handle class for use in Swift applications. Unfortunately, it&rsquo;s not a very good API. NSFileHandle supports no error reporting whatsoever, instead throwing Objective-C exceptions whenever something goes wrong during reading or writing. There is no way that I know of to catch these exceptions in Swift, meaning that if a write failed because the disk ran out of space or something, there&rsquo;s no way to deal with that other than crashing the whole application.<\/p><\/blockquote>","protected":false},"excerpt":{"rendered":"<p>Mike Ash has a great list of Cocoa APIs that are subtly dangerous. Note that since NSBundle isn&rsquo;t threadsafe, neither is NSLocalizedString. Update (2017-02-20): Charles Srstka: In Swift 3, NSFileHandle was renamed to FileHandle, making it the de facto file handle class for use in Swift applications. Unfortunately, it&rsquo;s not a very good API. NSFileHandle [&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":"2020-04-21T17:59:26Z","apple_news_api_id":"b0c90b3c-4b2e-4ef4-9a69-2122cdfa3941","apple_news_api_modified_at":"2020-04-21T17:59:26Z","apple_news_api_revision":"AAAAAAAAAAD\/\/\/\/\/\/\/\/\/\/w==","apple_news_api_share_url":"https:\/\/apple.news\/AsMkLPEsuTvSaaSEizfo5QQ","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,79,30,54,71,901],"class_list":["post-2096","post","type-post","status-publish","format-standard","hentry","category-programming-category","tag-cocoa","tag-exceptions","tag-mac","tag-objective-c","tag-programming","tag-swift-programming-language"],"apple_news_notices":[],"_links":{"self":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/2096","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=2096"}],"version-history":[{"count":5,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/2096\/revisions"}],"predecessor-version":[{"id":28733,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/2096\/revisions\/28733"}],"wp:attachment":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/media?parent=2096"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/categories?post=2096"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/tags?post=2096"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}