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 711801
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T04:46:35+00:00 2026-05-14T04:46:35+00:00

I’ve been modifying some code to work between Mac OS X and iPhone OS.

  • 0

I’ve been modifying some code to work between Mac OS X and iPhone OS.

I came across some code that was using NSURL‘s URLByAppendingPathComponent: (added in 10.6), which as some may know, isn’t available in the iPhone SDK.

My solution to make this code work between OS’s is to use

NSString *urlString = [myURL absoluteString];
urlString = [urlString stringByAppendingPathComponent:@"helloworld"];
myURL = [NSURL urlWithString:urlString];

The problem with this is that NSString‘s stringByAppendingPathComponent: seems to remove one of the /’s from the http:// part of the URL.

Is this intended behaviour or a bug?


Edit

Ok, So I was a bit too quick in asking the question above. I re-read the documentation and it does say:

Note that this method only works with file paths (not, for example, string representations of URLs)

However, it doesn’t give any pointers in the right direction for what to do if you need to append a path component to a URL on the iPhone…

I could always just do it manually, adding a /if necessary and the extra string, but I was looking to keep it as close to the original Mac OS X code as possible…

  • 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-14T04:46:35+00:00Added an answer on May 14, 2026 at 4:46 am

    I would implement a myURLByAppendingPathComponent: method on NSURL that does the same thing. The reason to give it a different name is so it doesn’t override the Apple-provided method when Apple gets around to porting the 10.6 API to the iPhone (so the “my” is just an example — the point is that it’s unlikely somebody else would write a method with that name).

    It seems to me you just want to mess with the path rather than the whole URL. Here’s an untested example:

    - (NSURL *)myURLByAppendingPathComponent:(NSString *)component {
        NSString *newPath = [[self path] stringByAppendingPathComponent:component];
        return [[[NSURL alloc] initWithScheme: [self scheme] 
                                         host: [self host] 
                                         path: newPath]
                                         autorelease];
    }
    

    It would only work correctly with URLs that have file-like paths, but I’m pretty sure the Apple method works the same way. At any rate, hopefully it helps you in the right direction.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 441k
  • Answers 441k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Updated Answer declare @NumRecords int SELECT @NumRecords = COUNT(*) FROM… May 15, 2026 at 5:32 pm
  • Editorial Team
    Editorial Team added an answer Personally, I use a stored procedure to do this, but… May 15, 2026 at 5:32 pm
  • Editorial Team
    Editorial Team added an answer Implement and register a org.testng.ITestListener and react on the callback… May 15, 2026 at 5:32 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.