Reputation: 553
I need to store some persistent data in my application that should be specific to the URL i am requesting data from. For example, if i make a request to http://www.example.com/a, i need to store a plist in my documents folders that is unique to that URL. So if another request is made to the same URL, i can go edit that same plist in my documents folder.
Temporarily I am generating it this way but i need a better solution:
NSString *filename = stringForURL;
filename = [filename stringByReplacingOccurrencesOfString:@"/" withString:@"__"];
filename = [filename stringByReplacingOccurrencesOfString:@"?" withString:@""];
filename = [filename stringByAppendingPathExtension:@"plist"];
And then i write my dictionary with that filename.
Edit: Ok I don't think i explained myself clearly. I basically want to generate a unique filename for a given URL. Any same URL should generate the same filename, and 2 different URLs should generate a different filename.
Upvotes: 1
Views: 412
Reputation: 222
If i understand your problem you want to get the same URL back after you have changed it. If so use the same code on when looking for the string.
Create an array of all the urls you have changed and saved.
NSString *theURLyouAreLookingFor= "myURL" ;
theURLyouAreLookingFor = [filename stringByReplacingOccurrencesOfString:@"/" withString:@"__"];
theURLyouAreLookingFor = [filename stringByReplacingOccurrencesOfString:@"?" withString:@""];
And the use isEqualTo:
with the theURLyouAreLookingFor
and look it up in the array of saved URLs.
Not the best way of explaining this, but hope it helps.
Upvotes: 0