MadMaxAPP
MadMaxAPP

Reputation: 1075

how to filter part of a path in iOS?

we have an app released, which wasn't held for developer release. Our customer released the app instead of waiting for us changing the backend for the new version. This now leads to wrong information at a local CoreData Storage, where the problem begins.

There seems to be a field holding a local path to a file on Documents directory like:

/var/mobile/Applications/9EE88C79-F060-4EE....C0A/Documents/core23/thumb.png

The folder where the App lives in on local device changes during the update of an app (looks like!?). Now we need to filter this field to change the path before /Documents/to the actual path where the app is installed on local device.

Does somebody have a handy solution for that? Any help is appreciated.

MadMaxApp

Upvotes: 0

Views: 127

Answers (2)

auibrian
auibrian

Reputation: 261

-[NSString pathComponents] returns an array of all path components. Call that on your errant path string and build it back up from the resulting array.

-[NSString componentsSeparatedByString:(NSString*)] would also work just as well if passed @"/" for the separator string.

Upvotes: 2

runmad
runmad

Reputation: 14886

You can't hard code that path. To get the documents directory path use the following code:

-(NSString *)documentsDirectoryPath {
      NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
      NSString *documentsDirectoryPath = [paths objectAtIndex:0];
      return documentsDirectoryPath;
}

Upvotes: 0

Related Questions