1

NSMutableOrderedSet を初期化する方法を教えてもらえますか?

私は次のことを試しました

NSMutableOrderedSet *answerSet = [NSMutableOrderedSet orderedSet];

しかし、ログはただ(lldb)です

オブジェクトの回答を挿入します

#import "Answer.h"
#import "Survey.h"


@implementation Answer

@dynamic count;
@dynamic text;
@dynamic survey;

@end

編集1:

  #import <Foundation/Foundation.h>
    #import <CoreData/CoreData.h>

    @interface Survey : NSManagedObject

    @property (nonatomic, retain) NSDate * dateCreated;
    @property (nonatomic, retain) NSString * id;
    @property (nonatomic, retain) NSString * note;
    @property (nonatomic, retain) NSString * question;
    @property (nonatomic, retain) NSMutableOrderedSet *answers;
    @end

    @interface Survey (CoreDataGeneratedAccessors)

    - (void)addAnswersObject:(NSManagedObject *)value;
    - (void)removeAnswersObject:(NSManagedObject *)value;
    - (void)addAnswers:(NSMutableOrderedSet *)values;
    - (void)removeAnswers:(NSMutableOrderedSet *)values;

    @end


    #import <Foundation/Foundation.h>
    #import <CoreData/CoreData.h>

    @class Survey;

    @interface Answer : NSManagedObject

    @property (nonatomic, retain) NSNumber * count;
    @property (nonatomic, retain) NSString * text;
    @property (nonatomic, retain) Survey *survey;

    @end


        NSMutableOrderedSet *answerSet = [[NSMutableOrderedSet alloc] initWithCapacity:4];

        Answer *ans1 = [NSEntityDescription insertNewObjectForEntityForName:@"Answer"inManagedObjectContext:managedObjectContext];
        ans1.text = trimedAns1;
        ans1.count = 0;
        ans1.survey = survey;

        Answer *ans2 = [NSEntityDescription insertNewObjectForEntityForName:@"Answer"inManagedObjectContext:self.managedObjectContext];
        ans2.text = trimedAns2;
        ans2.count = 0;
        ans2.survey = survey;

        [answerSet addObject:ans1];
        [answerSet addObject:ans2];

       [survey setAnswers:answerSet];

        NSError *error = nil;

        if (![managedObjectContext save:&error]) {

            NSLog(@"Can't Save! %@ %@", error, [error userInfo]);

        } else {

            NSLog(@"Saved question : %@", self.question.text);

        }

そして今、コアデータに保存するときに以下の例外が発生しました:

   2013-06-27 22:58:33.955 Simple Survey[718:11903] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Unacceptable type of value for to-many relationship: property = "answers"; desired type = NSSet; given type = __NSOrderedSetM; value = {(
        <Answer: 0x8168070> (entity: Answer; id: 0x81c8880 <x-coredata:///Answer/t0F1038D5-DD97-4066-AB7D-E92386A9010B3> ; data: {
        count = nil;
        survey = "0x81be560 <x-coredata:///Survey/t0F1038D5-DD97-4066-AB7D-E92386A9010B2>";
        text = 6;
    }),
        <Answer: 0x74ec7f0> (entity: Answer; id: 0x74eed40 <x-coredata:///Answer/t0F1038D5-DD97-4066-AB7D-E92386A9010B4> ; data: {
        count = nil;
        survey = "0x81be560 <x-coredata:///Survey/t0F1038D5-DD97-4066-AB7D-E92386A9010B2>";
        text = 7;
    })
    )}.'
4

1 に答える 1