Question

I have an entity Tag (in core data) that have some attributes and a to-many relationship named "aliases".

My ArrayController is "bind" in Xcode to:

Parameters->Managed Object Context = File's Owner.managedObjectContext

It work OK for all Attributes, the others columns present the correct values.

In one column I try to "display" this to-many relationship. If I do it naively and bind the Value of my NSTableColumn to my ArrayController.arrangedObjects.aliases (like all other attributes) I get this on the screen:

Relationship fault for (), name aliases, isOptional 1, isTransient 0, entity Tag, renamingIdentifier aliases, validation predicates ( ), warnings ( ), versionHashModifier (null), destination entity TagAlias, inverseRelationship tag, minCount 0, maxCount 0 on 0x10053db10

It seems to be some kind of CoreData proxy for the relationship...

I then build a subclass of NSValueTransformer:

@interface tagAliasesToStringTransformer : NSValueTransformer

+ (Class)transformedValueClass;
+ (BOOL)allowsReverseTransformation;
- (id)transformedValue:(id)value;

@end

and tried to use it as a Value Transformer in the binding. But I'm lost in my implementation:

@implementation tagAliasesToStringTransformer

+ (Class)transformedValueClass {
    return [NSString class];
}

+ (BOOL)allowsReverseTransformation {
    return NO;
}

- (id)transformedValue:(id)value {

    if (value == nil) return nil;

    ...
}

@end

In the method transformedValue:, value is of class '_NSFaultingMutableSet' and I don't know how to get a Set/Array of the aliases or anything useful.

The goal is to build a NSString of the concatenation of each alias. Something like:

aTag : alias1 alias2 alias3 ...

Was it helpful?

Solution

I found the solution:

_NSFaultingMutableSet is actually a kind of NSSet, so by doing something like this:

- (id)transformedValue:(id)value {
    if (value == nil) return nil;

    NSArray *tags = [value allObjects];
    for (Tag *tag in tags) {
        ...
    }
}

you get access to all the entity.

Don't know why it's obvious now and not one week ago... getting out of newbie zone ?

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top