{"id":7,"date":"2007-07-30T02:58:46","date_gmt":"2007-07-30T02:58:46","guid":{"rendered":"http:\/\/jaimerios.com\/?p=7"},"modified":"2007-07-30T02:58:46","modified_gmt":"2007-07-30T02:58:46","slug":"using-cocoa-to-resolve-unix-file-paths-with-tildes","status":"publish","type":"post","link":"https:\/\/jaimerios.com\/?p=7","title":{"rendered":"Using Cocoa to resolve Unix file paths with tildes"},"content":{"rendered":"<p> Quick! How do you expand a file path that has a tilde in a program? Luckily, you can use NSString to resolve the path for you. So, if you path looks like &#8220;~\/Library&#8221;, you can use the <span class=\"s1\">stringByExpandingTildeInPath <\/span>method to resolve the tilde to the full path: &#8220;\/Users\/johndoe\/Library\/&#8221;. Here is s snippet of code to show that:<\/p>\n<p class=\"p3\"><span class=\"Apple-tab-span\">\t<\/span>NSString *myString = [[NSString alloc] initWithString:[<span class=\"s2\">@&#8221;~\/Library&#8221;<\/span> stringByExpandingTildeInPath]];<\/p>\n<p>Of course don&#8217;t forget that you need to allocate memory for the string and initialize it! Now, if you need to use this function within a C++ App, don&#8217;t fret. You can add the above listed code to a C++ file and so long as you set the file to compile as a sourcecode.cpp.objc file,in the File Type drop down list in the &#8220;Info&#8221; dialog box, you should be good to go.<\/p>\n<p><a href=\"http:\/\/www.jaimerios.com\/code\/SampleNSStringApp.zip\">Click here for the Objective-C project<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Quick! How do you expand a file path that has a tilde in a program? Luckily, you can use NSString to resolve the path for you. So, if you path looks like &#8220;~\/Library&#8221;, you can use the stringByExpandingTildeInPath method to resolve the tilde to the full path: &#8220;\/Users\/johndoe\/Library\/&#8221;. Here is s snippet of code to &#8230; <a title=\"Using Cocoa to resolve Unix file paths with tildes\" class=\"read-more\" href=\"https:\/\/jaimerios.com\/?p=7\" aria-label=\"Read more about Using Cocoa to resolve Unix file paths with tildes\">Read more<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[],"class_list":["post-7","post","type-post","status-publish","format-standard","hentry","category-coding"],"_links":{"self":[{"href":"https:\/\/jaimerios.com\/index.php?rest_route=\/wp\/v2\/posts\/7","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/jaimerios.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/jaimerios.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/jaimerios.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/jaimerios.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=7"}],"version-history":[{"count":0,"href":"https:\/\/jaimerios.com\/index.php?rest_route=\/wp\/v2\/posts\/7\/revisions"}],"wp:attachment":[{"href":"https:\/\/jaimerios.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=7"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/jaimerios.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=7"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/jaimerios.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=7"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}