Write in the main directory of the Bundle. It is allowed?

I was sure that writing to the main Bundle is not possible on iOS ... for example, an operation like:

NSString *path = [[NSBundle mainBundle] pathForResource:@"Data" ofType:@"plist"]; .....something [xmlData writeToFile:path atomically:YES]; 

Why is the first example in the Apple documentation using this exact code?

+4
source share
2 answers

An example for OS X, which is not as strict with permissions as iOS.

I would be surprised if you are able to do this for much longer (if you can at all) in the app bundle for the Mac App Store.

It might be worth pointing out an error in the documentation.

+3
source

This is not a link to the main package. This is the path to the resources folder and plist inside this folder.

Hence the function name pathForResource...

Everything in the main set is cryptographically signed when compiling the application. However, the resource folder does not exist. You are free to write on and off of this.

for @jrturton

 // we need to get the plist data... NSString *plistPath = [[NSBundle mainBundle] pathForResource:@"Symptoms" ofType:@"plist"]; NSMutableArray *dataArray = [[NSMutableArray alloc] initWithContentsOfFile:plistPath]; // add a new entry NSDictionary *addQuestion = [[NSDictionary alloc] initWithObjectsAndKeys:@"Blank.png",@"Icon", [NSString stringWithFormat:@"%i",r],@"ID", [titleTextField text],@"Title", [questionTextField text],@"Text", qnType,@"Type", @"1",@"Custom", [NSArray arrayWithObjects:@"Yes",@"No",nil],@"Values", [unitsTextField text],@"Units", nil]; [dataArray addObject:addQuestion]; [addQuestion release]; // rewrite the plist [dataArray writeToFile:plistPath atomically:YES]; 
+2
source

Source: https://habr.com/ru/post/1214816/


All Articles