-2

I don't know where to turn to figure this out so I'm turning to you guys, the BEST! I'm new to objective c.

I get the deprecated warning with the following line of code. Any ideas on how to make this compatible with iOS 6?

const char *pUrl = [tStr cString];

Thanks so much!

  • You can still use it if it's deprecated but why don't you change that to NSString variable? – juniperi Jul 06 '13 at 08:53
  • 2
    `tStr.UTF8String` does the job. **Read the documentation.** –  Jul 06 '13 at 08:54
  • Thanks so much! the ".UTF8String;" works perfect. and yes, I'm reading the docs but teaching myself by writing something. This one I was stumped on where to look so I ask and then I will go and look up this UTF8String thing. Works for me. Objective C is just a hobby for me but I'm been programming since the 80s, just part time though. I truly love it. You guys are the best! Thanks for your help! – user2393110 Jul 06 '13 at 09:00
  • You didn't think to check the `NSString` documentation for information on `NSString` ?? – borrrden Jul 06 '13 at 09:01
  • To be honest, NO... why? I did not know this was a NSString. cString and NSString could be different. I know I could look and I did. I googled a bunch of stuff but it does not always make sense to me either. I'm NOT a coder, but i respect it and very much enjoy it. I'm a network engineer and now days a business guy. But I still love to build fun stuff. I'm sorry for not knowing but now i do... and i won't ask the same question twice. You guys are also amazing, i ask something, which I try NOT to do, and you reply... in minutes. WOW! Then when i search for things, you come up! :) – user2393110 Jul 06 '13 at 09:07
  • Thank you very much. You guys truly help people like me. – user2393110 Jul 06 '13 at 09:08
  • 2
    Well let me put it this way. In your above sample `tStr` is an `NSString`. You can verify that by looking for where it is declared. If you see a notice about a deprecated method, the first place it makes sense to look is the class that the method is called on. This rule applies to any programming language. Next time you run into a problem like this, follow the procedure I just described and it will answer your question more often than not. – borrrden Jul 06 '13 at 10:38

1 Answers1

3

As per the relevant documentation, this has been deprecated since iOS 2.

(Deprecated in iOS 2.0. Use cStringUsingEncoding: or UTF8String instead.)

As such, you need to either use the cStringUsingEncoding or UTF8String approaches instead.

John Parker
  • 54,048
  • 11
  • 129
  • 129