Created
May 30, 2011 12:12
-
-
Save nevyn/998818 to your computer and use it in GitHub Desktop.
Count of tracks in playlists in a playlist folder
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#import <Foundation/Foundation.h> | |
@interface PlaylistFolder : NSObject | |
@property (retain) NSArray *playlists; | |
-(id)trackCount; | |
@end | |
@interface Playlist : NSObject | |
@property (retain) NSArray *tracks; | |
@end | |
@interface Track : NSObject | |
@end | |
int main (int argc, const char * argv[]) { | |
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init]; | |
PlaylistFolder *folder = [PlaylistFolder new]; | |
Playlist *pl1 = [Playlist new], *pl2 = [Playlist new], *pl3 = [Playlist new]; | |
pl1.tracks = [NSArray arrayWithObjects:[Track new], nil]; | |
pl2.tracks = [NSArray arrayWithObjects:[Track new], [Track new], nil]; | |
pl3.tracks = [NSArray arrayWithObjects:[Track new], [Track new], [Track new], [Track new], nil]; | |
folder.playlists = [NSArray arrayWithObjects:pl1, pl2, pl3, nil]; | |
NSLog(@"Folder %@", [folder trackCount]); | |
[pool drain]; | |
return 0; | |
} | |
@implementation Playlist | |
@synthesize tracks; | |
@end | |
@implementation Track | |
@end | |
@implementation PlaylistFolder | |
@synthesize playlists; | |
-(id)trackCount; | |
{ | |
/////// This is the part I can't figure out | |
return [self valueForKeyPath:@"[email protected].@count"]; | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
It's
[email protected].@count
.AFAIK,
@unionOfArrays
will evaluate the entire remaining key-path, then union. So the original code tried to union three counts, rather than count a union. (Does that make sense?)The new code counts each array in
playlists.tracks
and sums the array of counts.(This is me randomly reading other programmers' Twitter feeds...)