killerwakka
killerwakka

Reputation: 31

objective C save file with extension and name to dictonary

I have a browse function where I get the url of a file.

Now I want to save the file in the supporting file dictionary so that if the file is move anywhere else it can still access it

I have a code which saves it to the supporting files:

NSURL *mainUrl;
mainUrl=[[NSBundle mainBundle] bundleURL];
NSFileManager *Fm;
[Fm copyItemAtURL:url toURL:mainUrl error:nil];

but I don't know what the name and the extension because the browse function allows png,jpg,jepg files

and I would need the name to access it

so my question would be how I can I save the file there with a name and extension of my choose

my name would look like that:

NSString *string;
NSInteger number;
number=0;
string=[NSString stringWithFormat:@"%@%li",@"img",(long)number];

and the extension would be jpg

can somebody help me?

Upvotes: 0

Views: 229

Answers (2)

Itachi
Itachi

Reputation: 6070

You could get the file name and the extension using the specified full path and the following functions.

/* NSString Class References*/

lastPathComponent Returns the last path component of the receiver.

  • (NSString *)lastPathComponent

pathExtension Interprets the receiver as a path and returns the receiver’s extension, if any.

  • (NSString *)pathExtension

Upvotes: 0

user23743
user23743

Reputation:

You can use NSString's -stringByAppendingPathExtension: method:

[@"foo" stringByAppendingPathExtension: @"jpg"];

results in @"foo.jpg".

Upvotes: 1

Related Questions