Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 255693
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T21:57:07+00:00 2026-05-11T21:57:07+00:00

Playing with URLs, more specifically building them incrementally from other, discovered URLs. In doing

  • 0

Playing with URLs, more specifically building them incrementally from other, discovered URLs. In doing so, I’d like to stay using NSURL objects instead of manipulating NSStrings, just to gain the added sanity checks and url-specific methods from the URL class.

Unfortunately, it seems that there is no way to get the following to join together how I wish:

NSURL *base = [NSURL URLWithString:@"http://my.url/path"];
NSString *suffix = @"sub/path";

I want to append them to get:

http://my.url/path/sub/path

But the best I can seem to get is:

NSURL *final = [NSURL URLWithString:suffix relativeToURL:base];

Which trims off the path on the base, resulting in:

http://my.url/sub/path

There’s a CoreFoundation function that does it:

CFURLRef CFURLCreateCopyAppendingPathComponent (
   CFAllocatorRef allocator,
   CFURLRef url,
   CFStringRef pathComponent,
   Boolean isDirectory
);

Which seems to work fine, but bouncing back/forth from ObjC to C is jarring and annoying… I’d rather just manipulate strings… Am I missing something? Other than being way too picky of course. 🙂

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-11T21:57:08+00:00Added an answer on May 11, 2026 at 9:57 pm

    This is Objective C – if NSURL does not do what you need, add an extension category.

    @interface NSURL ( Extensions )
    - (NSURL*) urlByAppendingPathComponent: (NSString*) component;
    @end
    
    @implementation NSURL ( Extensions )
    - (NSURL*) urlByAppendingPathComponent: (NSString*) component;
    {
        CFURLRef newURL = CFURLCreateCopyAppendingPathComponent( kCFAllocatorDefault, (CFURLRef)[self absoluteURL], (CFStringRef)component, [component hasSuffix:@"/"] );
        return [NSMakeCollectable(newURL) autorelease];
    }
    @end
    

    and then:

    *base = [NSURL URLWithString:@"http://my.url/path"];
    *suffix = @"sub/path";
    NSURL *final = [base urlByAppendingPathComponent:suffix];
    NSLog( @"%@", final );
    // displays http://my.url/path/sub/path
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm playing a bit with Javascript these days... I was shrinking some URLs using
Playing with the ssh and public_key application in Erlang, I've discovered a nice feature
While playing around with regexps in Scala I wrote something like this: scala> val
been playing around with ResolveClientUrl(~/Confirmation.aspx) and other methods.. I am tryin go get the
I've recently been playing with nodejs and would like to build my first project
I'm playing with YouTube API. Using the following URL: https://gdata.youtube.com/feeds/api/users/RayWilliamJohnson/uploads , how do I
I have a ruby script that downloads URLs from an RSS server and then
I'm building a website which requires continuous music playing even between switching pages. I
I've been playing with Amazon S3 presigned URLs all night attempting to PUT a
Anyone know for sure if playing local mp3 file using HTML5 is possible or

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.