nsdictionary

Replacing key/value in NSDictionary

99封情书 提交于 2019-12-08 16:02:58
问题 If I have a dictionary with the following key/value "foo"/"bar" and declared [dictionary setObject:@"baz" forKey:@"foo"]; would this replace the current key value pair with "foo"/"baz" and delete "foo"/"bar"? 回答1: The behave of an NSMutableDictionary (as any common hash table) is that if it does not exists it creates a new key/value pair, if it already exits it will replace the existing value with the new one. 回答2: The documentation here; http://developer.apple.com/library/mac/#documentation

Filtering NSMutableArray of NSDictionary with NSPredicate

梦想与她 提交于 2019-12-08 11:43:02
问题 I'm having an NSObject entity for storing some data like name, id from server NSObject file looks like below, @interface MyEntity : NSObject @property(nonatomic,strong)NSString *userId; @property(nonatomic,strong)NSString *userName; - (id)initWithJSON:(NSDictionary *)dataDict; @end - (id)initWithJSON:(NSDictionary *)dataDict { if (self = [super init]) { self.userId = [dataDict objectForKeyNotNull:@"userId"] ; self.userName = [dataDict objectForKeyNotNull:@"userName"] ; } return self; } I'm

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

Check the attribute of items in a directory in Objective-C

夙愿已清 提交于 2019-12-08 09:41:59
问题 I have made this little code to check how many subdirectories are in a given directory. It checks only the first level, is there anyway I can make it simplier? I have added comments, maybe easier to understand my intention. Thank you! #import < Foundation/Foundation.h > int main (int argc, const char * argv[]){ NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init]; // insert code here... NSFileManager *filemgr; NSMutableArray *listOfFiles; NSDictionary *listOfFolders; NSDictionary

UIBezierPath in NSDictionary - is it possible?

≡放荡痞女 提交于 2019-12-08 09:35:29
问题 I am trying to save a UIBezierPath and some other values in an NSDictionary. I write in the dictionary like this: NSMutableArray *paths = [[NSMutableArray alloc]init]; touchesBegan: - (void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { CGPoint touchPoint = [[touches anyObject] locationInView:self.drawImage]; path = [[UIBezierPath bezierPath] retain]; path.lineCapStyle = kCGLineCapRound; path.lineWidth = brushSize; [path moveToPoint:touchPoint]; [self updateDrawingBoard]; }

Observe value changes of NSDictionary inside NSArray

别等时光非礼了梦想. 提交于 2019-12-08 07:22:40
问题 here's my NSArray carType ( { isSelected = 0; kFieldName = "All types"; kObjectValue = 0; kObjectValueText = All; }, { isSelected = 0; kFieldName = "4 seats"; kObjectValue = 4; kObjectValueText = "4 seats"; }, { isSelected = 1; kFieldName = "7 seats"; kObjectValue = 7; kObjectValueText = "7 seats"; } ) how can I observe the change of isSelected field ? I used KVO in my code but it doesn't work. carType is a NSArray property of context - (void)viewDidLoad { [super viewDidLoad]; [context

NSArray of NSDictionaries - merge dictionaries with same key value pair

一笑奈何 提交于 2019-12-08 06:09:39
问题 I have a NSArray of NSDictionary objects: [ { id = 1; fromDate = 2014-04-03; toDate = 2014-04-05; date = 0000-00-00; title = title 1 }, { id = 1; fromDate = 0000-00-00; toDate = 0000-00-00; date = 2014-04-03 title = title 1 }, { id = 1; fromDate = 0000-00-00; toDate = 0000-00-00; date = 2014-04-04; title = title 1 }, { id = 2; fromDate = 0000-00-00; toDate = 0000-00-00; date = 2014-05-10; title = title 2 }, { id = 2; fromDate = 0000-00-00; toDate = 0000-00-00; date = 2014-05-11; title = title

False order when reading Dictionary from PList

∥☆過路亽.° 提交于 2019-12-08 06:01:34
问题 I have a plist from which i am trying to access its animations in sequence (as defined in the PList) but when I store it in NSDictionary and then try to play animation one by one it is not playing them in sequence. e.g, int index = 0; [self playAnimation:[animTypes objectAtIndex:index++]]; [self playAnimation:[animTypes objectAtIndex:index++]]; This is the code of my Plist: <plist version="1.0"> <dict> <key>Boy</key> <dict> <key>Enter</key> <dict> <key>disabled</key> <false/> <key>halfCycle<

how to store nsdictionary inside keychainwrapper

倖福魔咒の 提交于 2019-12-08 05:32:10
问题 I am using apple provided keychainwrapper sample code to store NSDictionary data which i get in my application authorization. I am receiving errSecParam (-50) as error code from SecItemAdd API. Below is the code for keychainwrapper.m #import "KeychainItemWrapper.h" #import "SynthesizeSingleton.h" #import <Security/Security.h> @interface KeychainItemWrapper (PrivateMethods) /* The decision behind the following two methods (secItemFormatToDictionary and dictionaryToSecItemFormat) was to

Saving an NSDictionary of NSArrays of custom objects

故事扮演 提交于 2019-12-08 04:13:18
问题 I have a dictionary (it's mutable if that makes a difference) which contains nsarrays, which in turn contain (subclass of NSObject)s I have implemented initWithCoder and encodeWithCoder like this: -(id)initWithCoder:(NSCoder *)aDecoder { self = [super init]; self.Title = [aDecoder decodeObjectForKey:@"Title"]; self.SiteAPIURL = [aDecoder decodeObjectForKey:@"SiteAPIURL"]; self.ID = [aDecoder decodeObjectForKey:@"ID"]; return self; } -(void) encodeWithCoder:(NSCoder *)aCoder { [aCoder