2016-10-04 13 views
1

コアデータエンティティの属性がNullであるかどうかをチェックしたいと思います。私はいくつかのアプローチを試して、SOに関するいくつかの質問を行った。驚くべきことに答えがなかったか、うまくいかなかった。質問hereには、属性値をチェックするすべての可能な方法が記載されていますが、機能する入力はありません。 Null値の属性をチェックしようとすると、アプリケーションがクラッシュします。どんな助けもありがとう。ありがとうございました。だから、CoreDataエンティティの属性がnullであることを確認しますか?

EDIT

NSMutableAttributedString *attrStringNew = [[NSMutableAttributedString alloc] initWithString:[contact valueForKey:@"first_name"]]; 
    [attrString addAttribute:NSFontAttributeName value:[UIFont fontWithName:@"Helvetica Neue" size:10] range:boldedRange]; 
    titleLbl.attributedText = attrStringNew; 

接触は全く最初の名前を持っていない場合、私のアプリがクラッシュします。

+0

ok ..コードを表示してください。他の{ここ ........コード } { //ここでの問題を取り扱って } –

+0

は、このよう ([@ "FIRST_NAME" 接触valueForKey])があればで@Gagan_iOS – TKutal

+2

チェックを追加しました完了しました。回答に追加されました。 –

答えて

2

このよう

if([contact valueForKey:@"first_name"]) 
{ ........code here } 
else 
{ //Handle issue here 
} 

・ホープ、このヘルプでご確認ください。

0

まず、コアデータEntityを以下のように呼び出す必要があります。

NSManagedObjectContext *moc = self.appDelegate.managedObjectContext; 
     NSFetchRequest *theRequest = [NSFetchRequest fetchRequestWithEntityName:@"Your Entity Name"]; 
    NSError *error = nil; 
    NSArray *resultArray = [moc executeFetchRequest:theRequest error:&error]; 

    if (!resultArray) { 
     abort(); 
     //check here where the array is null or not 

    } 
    else 
    { 
     //then in here you can check the objects one by one 
     for (yourEntity *entity in resultArray) 
     { 
      NSString *myobject = entity.first_name; 
      //in here your can check the each object is null or not 
      if([myobject iseEqualToString:@""]) 
      { 
       NSLog(@"the object is null"); 
      } 

     } 
    } 
関連する問題