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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T17:15:17+00:00 2026-05-27T17:15:17+00:00

I am writing an extension to NSURL that will give it a convenience method

  • 0

I am writing an extension to NSURL that will give it a convenience method URLFromString:withArguments: that builds an URL with some parameters included. The first argument to this method is a string like @"http://www.example.com/foo" and the second is an NSDictionary like {key1 => val1, key2 => val2}, where all of the keys and values are NSStrings. The convenience method will return an NSURL with an URL like, for this example

http://www.example.com/foo?key1=val1&key2=val2

First off, I guess I should ask whether there already exists something like this in Foundation! If not, though, my question is about properly encoding the keys and values. Much has been written on this issue (1, 2, 3). The issues with these three approaches to the problem are, respectively,

  1. Inelegant. (Although it probably works. I haven’t tried it yet.)

  2. Doesn’t properly escape everything.

    The source recommends using - stringByAddingPercentEscapesUsingEncoding on an NSString to escape everything. The problem is that this method doesn’t actually escape everything it should, ampersands and slashes being two obvious examples. I don’t know when this method could be useful, given these omissions, but it certainly isn’t useful for my application.

  3. Apparently not kosher with ARC.

    I don’t know all that much about ARC yet, but the solution presented on this site uses some CoreFoundation types at which ARC balks. Xcode offers to insert __bridge before a couple of type casts, and the code seems to work then, but I can’t tell whether or not I’m leaking memory or generally doing the Right Thing. And in general it seems to me like I shouldn’t have to go so low-level.

So again, my question is: is there any way to do the percent encoding required for HTTP requests that is built in to NSURL or NSString or the like? And if not, what’s the safest way?

  • 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-27T17:15:18+00:00Added an answer on May 27, 2026 at 5:15 pm

    Use (3). ARC doesn’t handle CF types directly, just as garbage-collection does not, the bridge casts are just to instruct ARC to take responsibility for the objects from CF (as NSMakeCollectible does for GC). Put in the right bridge casts and you won’t be leaking any memory, see section 3.2.4 in the ARC docs

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

Sidebar

Related Questions

I'm writing an extension that will allow me to add the magic words: CURRENTUSER
I'm writing an extension method that takes a string of digits (ie. 4083239382) and
I'm writing an extension for Firefox, and I need to log some data to
I'm writing a Firefox extension that needs to know what the username of the
I am writing a python extension that seems to be leaking memory. I am
I'm writing a Firefox extension that's to be used in house. Basically, I need
I'm writing a Python extension that runs through a Py_UNICODE array, finds specific (ASCII,
I am writing a firefox extension that interacts with a JSON server interface. I
I am writing a Chrome Extension that inserts a DIV on top of an
Is there a good way to do this? I'm writing an extension that interacts

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.