{"id":1583,"date":"2007-11-09T10:41:06","date_gmt":"2007-11-09T13:41:06","guid":{"rendered":"http:\/\/brockerhoff.net\/bb\/viewtopic.php?p=2227"},"modified":"2010-05-08T17:14:37","modified_gmt":"2010-05-08T20:14:37","slug":"leopard-simplifies-your-code","status":"publish","type":"post","link":"https:\/\/brockerhoff.net\/blog\/2007\/11\/09\/leopard-simplifies-your-code\/","title":{"rendered":"Leopard simplifies your code"},"content":{"rendered":"<p>In line with others detailing goodies (<a href=\"http:\/\/mattgemmell.com\/2007\/10\/28\/get-rid-of-your-code-with-leopard\">Matt Legend Gemmell<\/a> and <a href=\"http:\/\/yamacdev.blogspot.com\/2007\/11\/leopard-ate-my-code.html\">Blake C.<\/a> are two I remember), here&#8217;s a new Leopard API that appears to eliminate an entire page of my old code:<\/p>\n<pre><code>FSRef ref;\r\n\/\/ now point FSRef at some file or folder\r\n\r\nIconRef iconRef = NULL;\r\nGetIconRefFromFileInfo(&amp;ref,0,NULL,0,NULL,kIconServicesNormalUsageFlag,&amp;iconRef,NULL);\r\nNSImage* image = [[NSImage alloc] initWithIconRef:iconRef];\r\n<\/code><\/pre>\n<p>Then you can do setSize: if you want a particular icon size for that file or folder.<\/p>\n<p>True, if you had a path to the file, you could always do:<\/p>\n<pre><code>NSImage* image = [[NSWorkspace sharedWorkspace] iconForFile:somePath];\r\n<\/code><\/pre>\n<p>but if you&#8217;re already handling FSRefs, getting a path back from it is slower and also suffers from the PATH_MAX limitation (1024 bytes maximum path size).<\/p>\n<p>I also seem to remember that NSWorkspace fails for certain types of file system items, but I can&#8217;t quite recall which ones right now. It does work for run-of-the-mill folders, apps, and files though.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In line with others detailing goodies (Matt Legend Gemmell and Blake C. are two I remember), here&#8217;s a new Leopard API that appears to eliminate an entire page of my old code: FSRef ref; \/\/ now point FSRef at some file or folder IconRef iconRef = NULL; GetIconRefFromFileInfo(&amp;ref,0,NULL,0,NULL,kIconServicesNormalUsageFlag,&amp;iconRef,NULL); NSImage* image = [[NSImage alloc] initWithIconRef:iconRef]; Then [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[4],"tags":[26],"class_list":["post-1583","post","type-post","status-publish","format-standard","hentry","category-dev","tag-cocoa"],"featured_image_src":null,"author_info":{"display_name":"Rainer Brockerhoff","author_link":"https:\/\/brockerhoff.net\/blog\/author\/rbrockerhoff\/"},"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/p1q3Zc-px","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/brockerhoff.net\/blog\/wp-json\/wp\/v2\/posts\/1583","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/brockerhoff.net\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/brockerhoff.net\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/brockerhoff.net\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/brockerhoff.net\/blog\/wp-json\/wp\/v2\/comments?post=1583"}],"version-history":[{"count":0,"href":"https:\/\/brockerhoff.net\/blog\/wp-json\/wp\/v2\/posts\/1583\/revisions"}],"wp:attachment":[{"href":"https:\/\/brockerhoff.net\/blog\/wp-json\/wp\/v2\/media?parent=1583"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/brockerhoff.net\/blog\/wp-json\/wp\/v2\/categories?post=1583"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/brockerhoff.net\/blog\/wp-json\/wp\/v2\/tags?post=1583"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}