objective c - How to work with plist in several threads -
i have simple multithread application 2 tabs. each tab table view number of items, information them saved in plist file structure this:
<key>items</key> <array> <dict> <key>name</key> <string>bosch kgn36x45</string> <key>price</key> <string>18890</string> <key>quantity</key> <real>33</real> </dict>
i need work file in several threads, example in 1 thread can remove item code:
- (void)removeitematrow:(int)row { [items removeobjectatindex:row]; nsmutabledictionary *plistdict = [nsdictionary dictionarywithobject:items forkey:@"items"]; [self saveappfile:plistdict]; }
and can open item in other view controller edit:
- (void) updateviews { nsdictionary *item = [[[datacontroller sharedinstance] getitems] objectatindex:itemrow]; nslog(@"%@", item); self.namelabel.text = [item objectforkey:@"name"]; self.pricelabel.text = [nsstring stringwithformat:@"%@ руб.", [item objectforkey:@"price"]]; self.quantitylabel.text = [nsstring stringwithformat:@"%@ шт.", [item objectforkey:@"quantity"]]; }
so when in first thread item deleted - when edited in second thread - saved item on other one, on other row after changes deleting, have several problems multithreading work plist. how make operations file save?
if don't want threads being executed on top of each other, should try , have integer value can both access, , changing depending on wether or not plist can edited. called semaphore. agree partially jeremy there little benefit multithreading in case:
if agree , want use them, ask , can provide more detailed explanation/implementation help.
alternatively, if absolutely must multithread reason , don't want use semaphores, i'd recommend jeremy had say, find algorithm make unique identifier , keep track of rather using row number decide item which.
Comments
Post a Comment