重複の可能性:
Objective-Cの2つの文字列を比較します
私は2つのNSString間の同等性を比較しようとします...
1つ目は共有ユーザーのデフォルトに保存され、2つ目はNSTextFieldを介してユーザーが入力します...
ここに私のコードの少しがあります(Xcode 4.5.2 Mac OS 10.7)..。
1番目のAppDelegate.h:
@interface AppDelegate : NSObject <NSApplicationDelegate>{
NSUserDefaults *administratifPref;
...
IBOutlet NSTextField *champProtection;
...
}
...
- (IBAction)poursuivre:(id) sender;
...
@end
そしてここにAppDelegate.m:
- (IBAction)poursuivre:(id)sender {
if([champProtection stringValue] == [champProtection stringValue]){
...
...
}
}
私の質問は:条件「if」が検証されないのはなぜですか?!
問題は発生せず、クラッシュも発生しません...
私は2つのNSLogを追加しました:
- (IBAction)poursuivre:(id)sender {
NSLog([champProtection stringValue]);
NSLog([administratifPref valueForKey:@"motdepasse"]);
if([champProtection stringValue] == [champProtection stringValue]){
...
...
}
}
戻り値は同じです:(
私が見つけた唯一の解決策はやっています:
- (IBAction)poursuivre:(id)sender {
BOOL result = [[champProtection stringValue] isEqualToString:[administratifPref valueForKey:@"motdepasse"]];
if(result == YES) {
...
...
}
}
だから...誰かが私にこれらの2つのコーディング方法の違いを説明できますか?それはすっごく違うようです?(しかし、ココアはとてもシンプルだと言う人を信頼している私のような初心者にとっても、それは本当に同じように思えます^^)