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?

Était-ce utile?

La 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

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top