nsmutabledictionary

Swift 3: cannot write data to plist file

只谈情不闲聊 提交于 2019-12-10 11:54:51
问题 I am trying to use a file called Data.plist to store some simple unstructured data, and I placed this file at the root folder of my app. To make it simple to read/write to this file, I created the following DataManager struct. It can read Data.plist file with no problem, but it cannot write data to the file. I am not sure where the problem is, could anyone spot where might be wrong? struct DataManager { static var shared = DataManager() var dataFilePath: String? { return Bundle.main.path

CFPropertyListCreateDeepCopy fails to process array / dictionary containing NSNull

↘锁芯ラ 提交于 2019-12-10 05:23:05
问题 For some reason this sample code works: NSArray *immutable = @[ @"a", @"b", @"c" ]; NSMutableArray *mutable = (__bridge id)CFPropertyListCreateDeepCopy(kCFAllocatorDefault, (__bridge CFArrayRef)immutable, kCFPropertyListMutableContainers); and this code produces nil as a result of the conversion: NSArray *immutable = @[ @"a", [NSNull null], @"c" ]; NSMutableArray *mutable = (__bridge id)CFPropertyListCreateDeepCopy(kCFAllocatorDefault, (__bridge CFArrayRef)immutable,

NSMutableDictionary: mutating method sent to immutable object

倖福魔咒の 提交于 2019-12-09 02:26:51
问题 The following code is returning an exception with the following error message "mutating method sent to immutable object" when attempting to removeObjectForKey NSMutableDictionary * storedIpDictionary = (NSMutableDictionary*)[[NSUserDefaults standardUserDefaults] dictionaryForKey:@"dictDeviceIp"]; NSString *key = self.currentDeviceNameText.text; NSString *ipAddressTemp = [storedIpDictionary objectForKey:key]; [storedIpDictionary removeObjectForKey:key]; <----Crashes here storedIpDictionary[key

Is there NSMutableDictionary literal syntax to remove an element?

半腔热情 提交于 2019-12-08 21:18:01
问题 There is a literal syntax to add object and change object in an NSMutableDictionary, is there a literal syntax to remove object? 回答1: Yes, but... :-) This is not supported by default, however the new syntax for setting dictionary elements uses the method setObject:forKeyedSubscript: rather than setObject:forKey: . So you can write a category which replaces the former and either sets or removes the element: @implementation NSMutableDictionary (RemoveWithNil) - (void) setObject:(id)obj

Sum duplicate on NSMutableArray

痴心易碎 提交于 2019-12-08 18:35:43
I have a NSMutableArray with objects of type NSMutableDictionary , the NSMutableDictionary contains 2 keys -Airlines (string) -Rating (integer) I have an NSMutableArray with all the objects and what i need is to Sum the rating of all the airline companies repeated objects, an example: Airline Rating A 2 B 3 B 4 C 5 The end result array will be the A = 2, C = 5 and the Sum of B´s that is equal to 7. My code so far: for (int i = 0; i < arrayMealRating.count; ++i) { NSMutableDictionary *item = [arrayMealRating objectAtIndex:i]; NSLog(@"item=%@",item); for (int j = i+1; j < arrayMealRating.count;

How can we limit the capacity of an NSMutableDictionary?

拥有回忆 提交于 2019-12-08 10:28:52
问题 Is there any way to create a mutable dictionary with a capacity limit rather than an initial capacity? Say you want to create a dictionary that will only ever have, at most, 100 entries. The capacity argument for the dictionary is an initial capacity that will be simply increased if you add more elements than you want so it's not suitable. 回答1: Subclass it and override addObject to check count before adding? No built-in way. Here is a basic example... not tested, missing init etc, but this is

Swizzled method for NSMutableDictionary is not getting called

怎甘沉沦 提交于 2019-12-08 09:56:39
问题 I'm trying to swizzle NSMutableDictionary. What am I doing wrong here? I'm trying to override setObject:forKey: for NSMutableDictionary. #import "NSMutableDictionary+NilHandled.h" #import <objc/runtime.h> @implementation NSMutableDictionary (NilHandled) + (void)load{ static dispatch_once_t onceToken; dispatch_once(&onceToken, ^{ Class class = [self class]; SEL originalSelector = @selector(setObject:forKey:); SEL swizzledSelector = @selector(swizzledSetObject:forKey:); Method originalMethod =

how to sort the time in a NSMutableArray in ios

廉价感情. 提交于 2019-12-07 20:12:52
问题 i'm having a set of Dictionaries in a NSMutableArray. now i want to sort ascending & Descending order by time here is my Array value. ( { StartTime = "09:00 AM"; TravelsName = "ABC Travels"; }, { StartTime = "07:30 AM"; TravelsName = "XYZ Travels "; }, { StartTime = "06:45 PM"; TravelsName = "GSP Travels"; }, { StartTime = "05:00 PM"; TravelsName = "Madura Travels"; }, { StartTime = "12:45 AM"; TravelsName = "MJT Travels"; }, { StartTime = "12:45 PM"; TravelsName = "OPR Travels"; }, {

@property retain OR copy

北城以北 提交于 2019-12-07 17:58:40
问题 First I read this article I think I should use "copy" in my programe. Problem is using NSMutableDictionary copy it will terminate. ***** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: '-[__NSCFDictionary removeAllObjects]: mutating method sent to immutable object'** I have no idea about "mutating method sent to immutable object". I didn't set NSDictionary to NSMutabledictionary pointer. Here is my code .h file @interface Button : NSObject { @private

Case Insensitive Search in NSMutableDictionary

老子叫甜甜 提交于 2019-12-07 05:34:44
问题 HI, I have a NSMutableDicitionary contains both lowercase and uppercase keys. So currently i don't know how to find the key in the dictionary irrespective key using objective c. 回答1: Categories to the rescue. Ok, so it's an old post... @interface NSDictionary (caseINsensitive) -(id) objectForCaseInsensitiveKey:(id)aKey; @end @interface NSMutableDictionary (caseINsensitive) -(void) setObject:(id) obj forCaseInsensitiveKey:(id)aKey ; @end @implementation NSDictionary (caseINsensitive) -(id)