سؤال

أحاول إجراء جلب على البيانات الأساسية بعد إدراج كيان ، وأحصل على نتائج 0. لدي كيان شخص. وقمت ببناء طلب جلب في واجهة المستخدم الرسومية Datamodule مع المسند:

الاسم == "personname"

قبل البحث عن الاسم الذي أدخله وحفظه أولاً. وأنا أعلم أن هذا يعمل لأنني أعرض الأسماء في طاولة ويتم حفظ coredata بعد إغلاق التطبيق وفتحه مرة أخرى.

هنا هو الكود الذي قمت بترميزه لجلب. الرجاء مساعدتي في فهم لماذا أحصل على نتائج 0

-(Person *)findPersonByName:(NSString *)name{
    NSLog(@"looking for person with name: %@",name);
    NSDictionary *subs = [NSDictionary dictionaryWithObject:name forKey:@"PERSONNAME"];
    NSAssert(self.managedObjectModel, @"anything wrong with managedObjectModel");//no
    NSFetchRequest *fetch = [self.managedObjectModel fetchRequestFromTemplateWithName:@"getPersonByName" substitutionVariables:subs];
    NSAssert(fetch, @"anything wrong with fetch?");//no
    NSLog(@"fetch: %@",fetch);
    NSError *error;
    NSArray *result = [self.managedObjectContext executeFetchRequest:fetch error:&error];
    NSLog(@"fetch request getQuestionsByParent: %u found (sub variables:%@, results:%@)", [result count], subs, result);
    if (result == nil){
        // Deal with error...
    }
    else if([result count]>0){
        for (Person *person in result) {
            NSLog(@"search result: %@",person.name);
        }
    }
    return nil;
}

الرجاء المساعدة في حل المشكلة. شكرًا

هل كانت مفيدة؟

المحلول

في قالب الخاص بك:

name == "PERSONNAME"

يجب ان يكون:

name == $PERSONNAME
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top