nsdictionary

NSFileManager & NSFilePosixPermissions

人盡茶涼 提交于 2019-12-04 07:42:47
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 wrong? Thanks for help. gcbrueckmann First, NSFilePosixPermissions is the name of a constant. Its value

Sort NSDictionary

折月煮酒 提交于 2019-12-04 06:45:30
问题 I got NSDictionary with pairs like : Key -> Value: @"home" -> @"blue" @"family" -> @"green" @"work" -> @"red" Updated Internet said no one can sort NSDictionary :c This code helped me with values. sortedArray = [anArray sortedArrayUsingSelector:@selector(localizedCaseInsensitiveCompare:)]; But i lose relation between keys and values. If anybody can write function, which take NSDictionary and make two NSArray, which related and one of those arrays sorted by values of NSDictionary like this:

JSONkit sorting issues

天大地大妈咪最大 提交于 2019-12-04 06:41:41
问题 I am using a REST based web service to get data. No matter what the structure of the JSON document, the NSDictionary gets populated the same way. I want the sorting preserved as the web service returns. Here is my code: -(void) getData { NSURL *url = [NSURL URLWithString:@"http://somewebservice"]; __block ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:url]; [request setCompletionBlock:^{ // Use when fetching text data NSString *responseString = [request responseString]; NSDictionary

Change objects in NSUserDefaults without creating and re-setting copies

家住魔仙堡 提交于 2019-12-04 06:40:47
I've got dictionary stored in NSUserDefaults and I need to add/remove items in this dictionary. It bothers me that to do this I have to create mutable copy of entire dictionary, change one element and replace entire dictionary with new copy. copy = [[defaults objectForKey:@"foo"] mutableCopy]; [copy setObject:… forKey:@"bar"]; [defaults setObject:copy forKey:@"foo"]; and it involves even more copying and re-setting for objects deeper in the hierarchy. Is there a better way? I've tried to use [defaults setValue:… forKeyPath:@"foo.bar"] but that doesn't seem to work (object is not mutable). I

NSNull crashes my initWithDictionary

时光怂恿深爱的人放手 提交于 2019-12-04 06:23:52
问题 I am parsing a JSON file. After getting the NSDictionary, I parse the objects in the dictionary into an array of objects. However, for certain JSON files, I get NULL, which should be fine, but it crashes my app for those place where I am expecting something but getting null: - (id)initWithDictionary:(NSDictionary *)boxDictionary { if ([self init]) { // ... int numberOfBoxes = [[boxDictionary valueForKey:@"box_count"] intValue]; int numberOfItemsInBoxes = [[boxDictionary valueForKey:@"box

how do I serialise NSDictionary from a Class - Swift implementation

会有一股神秘感。 提交于 2019-12-04 06:18:45
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) - (NSDictionary *)NSDictionaryFromClass { Class aClass = [self class]; u_int propertiesCount; objc_property_t

Converting NSDictionary to XML [duplicate]

﹥>﹥吖頭↗ 提交于 2019-12-04 05:49:03
问题 This question already has answers here : Converting NSDictionary to XML (3 answers) Closed 6 years ago . I need to convert a dictionary to XML format for using with SOAP webservice in objective C . Let the dictionary be { password = testpassword; username = testusername; } and the converted result i need is : <password>testpassword</password> <username>testusername</username> i need a specific function to get output like this format for dynamic dictioanry . many libraries are available but i

Accessing keys in NSDictionary using [key] notation?

拥有回忆 提交于 2019-12-04 05:46:57
I have just realised that I can access NSDictionary using both objectForKey: and dict[key]? NSDictionary *coordsDict = @{@"xpos": @5.0, @"ypos": @7.2, @"zpos": @15.7}; NSLog(@"XPOS: %@", coordsDict[@"xpos"]); NSLog(@"XPOS: %@", [coordsDict objectForKey:@"xpos"]); Can anyone tell me if this has been hiding from me all along or if its some fairly recent change to the language? EDIT: The question does not generically refer to the new string literals, but more specifically to accessing NSDictionary with the same string literal syntax you would use for NSArray. I obviously overlooked this and just

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

孤街醉人 提交于 2019-12-04 05:35:20
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)? .queryItems? .reduce([:], combine: { (var result: [String: AnyObject], queryItem) -> [String: AnyObject] in if

How do I parse this Flickr response?

夙愿已清 提交于 2019-12-04 05:09:47
I get this from a sample Flickr response in their api site: jsonFlickrApi({"method":{"_content":"flickr.test.echo"}, "format":{"_content":"json"}, "api_key":{"_content":"8038f7f7d7151ccbf6df2aa10b1b35ae"}, "stat":"ok"}) I can see the dictionary in there, right after the words jsonFlickApi. But how do I get rid of that leading text and put the dictionary into my NSDictionary? Use the NSJSONSerialization class to parse the JSON data. Edit: The jsonFlickrApi(...) indicates that you're using a JSONP endpoint to talk to Flickr. You don't need this; a plain JSON endpoint is fine. According to this