0

I have e.g. 5 MyFile objects in my NSArray. Each of these 5 objects has property path.

MyFile *myFile ...;

NSString path = myMyFile.path;

So using KVC I can get the properties form all my 5 objects in the array:

NSArray *folders = [[PNFolder MR_findAllWithPredicate:predicate] valueForKey:@"path"];

so code above will return paths instead of MyFile objects and this is ok for me.

But, how can I using the lastPathComponent here as well to make my array return me just folder name instead of full path. I mean using KVC. or do I need to write cycle?

Wain
  • 118,658
  • 15
  • 128
  • 151
Matrosov Oleksandr
  • 25,505
  • 44
  • 151
  • 277

2 Answers2

1

What you are using is KVC, not KVO (coding, not observing), though in the case of NSArray it's an explicitly stated method (valueForKey:). It calls the method on the destination object(s) and returns the contents. So, you can use it with lastPathComponent.

Indeed, you should be able to use pure KVC via valueForKeyPath: with path.lastPathComponent.

Wain
  • 118,658
  • 15
  • 128
  • 151
1

use valueForKeyPath with the array

NSArray *folderNames = [[PNFolder MR_findAllWithPredicate:predicate] valueForKeyPath:@"path.lastPathComponent"];
Daij-Djan
  • 49,552
  • 17
  • 113
  • 135