How to create a new ITLibMediaItem object?

123 Views Asked by At

I'm trying build an app that will work with iTunes. So, I imported the framework into my project and created a small class, just for learning purposes as follows:

-(NSMutableArray *)processMediaItems:(NSArray *)mediaItems {
    NSMutableArray *titles = [NSMutableArray new];

    if (mediaItems) {
        for (ITLibMediaItem *item in mediaItems) {
            [titles addObject:[item.title]];
        }
    }
    return titles;
}

Then I decided to create a unit test for it, and did the following:

- (void)testExample {    
    ITLibMediaItem *mediaItem = [[ITLibMediaItem alloc] init];
    //mediaItem.title = @"I Still Haven't Found What I'm Looking For";

    NSMutableArray *mediaItems = [NSMutableArray new];
    [mediaItems addObject:mediaItem];

    MyClass *mc = [MyClass new];
    NSMutableArray *titles = [mc processMediaItems:mediaItems];
}

The problem is that the property title is readonly.

So my question is, how do I create a new ITLibMediaItem object with a title? I tried to read the API (ITLibMediaItem) but didn't found a initialization that could help...

1

There are 1 best solutions below

0
On

I find it. Properties in ITLibMediaItem are filled using setValuesForKeysWithDictionary:

NSMutableDictionary *properties = [NSMutableDictionary dictionary];
[properties setObject:@"I Still Haven't Found What I'm Looking For" forKey:@"title"];

ITLibMediaItem *mediaItem = [[ITLibMediaItem alloc] init];
[mediaItem setValuesForKeysWithDictionary:properties];

NSMutableArray *mediaItems = [NSMutableArray new];
[mediaItems addObject:mediaItem];