• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: NSURL question (easy (i think))
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSURL question (easy (i think))


  • Subject: Re: NSURL question (easy (i think))
  • From: Sherm Pendley <email@hidden>
  • Date: Wed, 29 May 2002 19:36:17 -0400

On Wednesday, May 29, 2002, at 06:23 PM, Mamdouh wrote:

NSString *MyUrlString= [MyTextView string];
[[NSWorkspace sharedWorkspace] openURL:[NSURL URLWithString:@"http://www.%@.com",MyUrlString]];

You can probably guess that i4m trying to replace the %@ with the MyUrlString, but i4m making somekind of typo here, or using a wrong method, but i cant find out what...

It looks like you're confusing URL escapes with printf-style format strings. Easy mistake to make, as they both use %'s. The URLWithString method processes URL escapes, but it doesn't do string formatting.

What you want is something more like this:

NSString *MyURLString = [NSString stringWithFormat: @"http://www.%@.com";, [MyTextView string]];
[[NSWorkspace sharedWorkspace] openURL: [NSURL URLWithString: MyURLString]];

Hint: The words "WithFormat" in the method name imply that a method accepts a list of parameters, and will do printf-style formatting. Likewise, the words "WithString" imply that the method wants one ordinary, non-formatted string. Many Cocoa methods follow similar patterns, using "WithFoo" to help indicate the type of parameter to pass.

sherm--


Never put off until tomorrow what you can do today. There might be a law against it by that time.
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.
References: 
 >NSURL question (easy (i think)) (From: Mamdouh <email@hidden>)

  • Prev by Date: Re: Objective C <--> COM comparison
  • Next by Date: Re: Objective C <--> COM comparison
  • Previous by thread: Re: NSURL question (easy (i think))
  • Next by thread: Re: NSURL question (easy (i think))
  • Index(es):
    • Date
    • Thread