Question

Currently I am getting CGPathRef for the path variable below.

In another project I am able to get NSString for the path variable while in this project I am able to get CGPathRef.

[[[NSURL URLWithString:fileName]path] lastPathComponents];

How do I specify it to get NSString instead of CGPathRef for the particular variable?

Was it helpful?

Solution

From The NSString reference, you can use :

NSString* theFileName = [[string lastPathComponent] stringByDeletingPathExtension]

The lastPathComponent call will return "thefile.ext", and the stringByDeletingPathExtension will remove the .ext from the end.

src: Objective-C: Extract filename from path string

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