nsdictionary

changing a key name in NSDictionary

烂漫一生 提交于 2019-12-06 03:38:37
问题 I have a method which returns me a nsdictionary with certain keys and values. i need to change the key names from the dictionary to a new key name but the values need to be same for that key,but i am stuck here.need help 回答1: This method will only work with a mutable dictionary. It doesn't check what should be done if the new key already exists. You can get a mutable dictionary of a immutable by calling mutableCopy on it. - (void)exchangeKey:(NSString *)aKey withKey:(NSString *)aNewKey

how do I serialise NSDictionary from a Class - Swift implementation

与世无争的帅哥 提交于 2019-12-06 01:47:15
问题 in Objective-C, I am using following codes to serialise a custom class to a dictionary which working fine. In order to being familiar to Swift, porting Objective-C codes to Swift. However I couldn’t achieve this one, how do I make this with Swift? this is how I achieve with Objective-C .h #import <Foundation/Foundation.h> #import <objc/runtime.h> @interface NSObject (aClass_NSDictionary) - (NSDictionary *)NSDictionaryFromClass; @end .m @implementation NSObject (aClass_NSDictionary) -

Ios NSDictionary array - grouping values and keys

天涯浪子 提交于 2019-12-06 01:39:40
I have the following result of NSDictionary of Array Bath = { Keynsham = ( "nsham companies" ); }; Bath = { "Midsomer Norton" = ( "Keynsham companies" ); }; Bath = { "Norton Radstock" = ( "Keynsham taxi companies" ); }; Birmingham = { "Acock's Green" = ( "Acock's Green taxi companies" ); }; Birmingham = { "Alcester Lane's End" = ( "Alcester Lane's End taxi companies" ); }; How can i combine the values and keys so that I end up with only one category as shown below; Bath = { "Norton Radstock" = ( "Keynsham taxi companies" ); "Midsomer Norton" = ( "Keynsham companies" ); Keynsham = ( "nsham

How do I convert url.query to a dictionary in Swift?

江枫思渺然 提交于 2019-12-06 00:43:51
问题 I have a URL coming in to the AppDelegate method: func application(_ application: UIApplication, open url: URL, sourceApplication: String?, annotation: Any) -> Bool { } The URL looks like www.wesite.com/shareplace.html?placeid=123 . How can it be converted to a dictionary for easy access? I found some code on some website, but it's showing an error in Xcode 9: extension URL { var queryDictionary: [String: AnyObject]? { return URLComponents(url: self, resolvingAgainstBaseURL: false)?

NSFileManager & NSFilePosixPermissions

≡放荡痞女 提交于 2019-12-06 00:34:13
问题 I want to use the octal permissions (used for chmod) for NSFilePosixPermissions. Here is what I did now: NSFileManager *manager = [NSFileManager defaultManager]; NSDictionary *attributes; [attributes setValue:[NSString stringWithFormat:@"%d", 0777] forKey:@"NSFilePosixPermissions"]; // chmod permissions 777 [manager setAttributes:attributes ofItemAtPath:@"/Users/lucky/Desktop/script" error:nil]; I get no error, but when I check the result with "ls -o" the permission are't -rwxrwxrwx. What's

Object keys with NSMutableDictionary (Objective-C)

隐身守侯 提交于 2019-12-05 23:45:08
问题 I want to store a bunch of key value pairs, with the key being my own object (ObjectA) that inherits from NSObject, and the value being an int. I am trying to use an NSMutableDictionary. I understand that you can only store object types in the dictionary, so I have the following: id value = [NSNumber numberWithInt:my_number]; [[self dictionary] setObject:value forKey:myObjectA]; Now that gives me an error, saying -[ObjectA copyWithZone:]: unrecognized selector sent to instance which is fine,

Keys in NSDictionary can be duplicated?

邮差的信 提交于 2019-12-05 21:38:19
问题 From what I have read, keys in dictionaries are unique. Consider this code: NSMutableDictionary *mydic = [NSMutableDictionary dictionary]; [mydic setObject:@"value1" forKey:@"key1"]; [mydic setObject:@"value1" forKey:@"key1"]; [mydic setObject:@"value1" forKey:@"key1"]; Why can I run this without any error? What should I do to avoid duplicate keys? 回答1: Yes keys are unique. Calling -setObject:forKey: with an existing key overrides the old value — it sets values, not adds values. You can check

Why do some dictionary keys have quotes and others don't when printing from debugger?

时光怂恿深爱的人放手 提交于 2019-12-05 18:33:46
So I am currently sending back from my server a JSON object. If I do a print of the responseObject in XCode, I get the following: Printing description of responseObject: { order = 3; "picture_bucket_name" = test; "picture_creation_date" = "2013-01-06T21:49:54.546Z"; "picture_identifier" = 61; "picture_url_with_bucket" = "test/pictures/sop/steps/test_default_320_320.png"; "sub_order" = 0; } Why is the Order key not in " "? This is the only key with a Number that I have to convert from NSString to NSNumber using a NumberFormatter. Why is that? Normally a single word without any spaces and other

NSDictionary with NSDates as keys

心已入冬 提交于 2019-12-05 18:32:30
Is it possible to have an NSdictionary where the keys are NSDates and also have it writeable/archiveable to disk? Jens Ayton Not using property lists, as only string keys are allowed there. You should be able to write it using NSKeyedArchiver , but that has the disadvantage of being a more opaque format. Alternatively, you could of course make a copy of the dictionary where you convert the dates to strings. Yes, this should work just fine - and NSDate elements are also suitable for plist encoding. Might depend on the value you put in as values, though. If you experience problems, please update

How do I make my AFNetworking “responseObject” that I receive a NSDictionary I can parse?

拥有回忆 提交于 2019-12-05 18:16:22
I have this call with AFNetworking 1.0 that returns a responseObject with the data from the API that I want: [[AFDiffbotClient sharedClient] postPath:@"http://diffbot.com/api/batch" parameters:parameters success:^(AFHTTPRequestOperation *operation, id responseObject) { However, I have no idea how to process responseObject . If I check [responseObject class] I get NSData . If I NSLog(@"%@", responseObject) I get a bunch of numbers (memory addresses I assume): <5b0a7b22 68656164 65727322 3a5b7b22 6e616d65 223a6e75 6c6c2c22 76616c75 65223a22 48545450 2f312e31 20323030 204f4b22 7d2c7b22 6e616d65