• 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: Comparing a CFStringRef with a string literal?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Comparing a CFStringRef with a string literal?


  • Subject: Re: Comparing a CFStringRef with a string literal?
  • From: Bryan Henry <email@hidden>
  • Date: Sat, 31 Jan 2009 18:50:29 -0500

NSString *efStr = [EFPW stringValue];

if ([efStr isEqualToString:@"my password") {
	NSLog(@"sjdskjf");
}

- OR -

CFStringRef efStr = (CFStringRef)[EFPW stringValue];

if (CFStringCompare(efStr, CFSTR("my password"), 0) == kCFCompareEqualTo) {
NSLog(@"sjdskjf");
}


I'm not sure why you'd want to use CFStringRef in the first place, but there are numerous things wrong with what you're doing.

1) You can't compare the contents of objects using == - that just compares the pointers, not the objects themselves. For strings, you'd want to use either -isEqualToString: or CFStringCompare().

2) Why are you trying to use CFStringRef when -stringValue (I'm assuming everything else is correct and EFPW is an NSNumber*) returns an NSString*?

3) The first argument of NSLog() must be a NSString* - you're trying to pass it a "const char*" (a compile-time constant c-string).

I recommend that you by a book or two about the basics of Objective-C and Cocoa before getting to much further. There's also tons upon tons of tutorials available just by searching Google, and you can also using the mailing list archives at http://cocoabuilder.com to help you with questions. You should also forward any other Cocoa questions you have to the Cocoa-Dev list, as this list is for issues with Xcode.

- Bryan

On Jan 31, 2009, at 4:35 PM, Arnaud Nicolet wrote:

Hi,

I have this piece of code which does not work:

CFStringRef efstr=([EFPW stringValue]);

if (efstr=="my password"){
	NSLog("sjdskjf");
}

I also tried with strcmp and with a single "=". Even when both values are the same, the equal test fails. What I am doing wrong?
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Xcode-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
@mac.com


This email sent to email@hidden

_______________________________________________ Do not post admin requests to the list. They will be ignored. Xcode-users mailing list (email@hidden) Help/Unsubscribe/Update your Subscription: This email sent to email@hidden
References: 
 >Comparing a CFStringRef with a string literal? (From: Arnaud Nicolet <email@hidden>)

  • Prev by Date: Re: Comparing a CFStringRef with a string literal?
  • Next by Date: Re: Comparing a CFStringRef with a string literal?
  • Previous by thread: Re: Comparing a CFStringRef with a string literal?
  • Next by thread: XCode and ccache
  • Index(es):
    • Date
    • Thread