Tag: dictionary

C++ / Objective-C++ – How can I store a C++ variable in an NSDictionary?

I have a C++ variable of type std::vector<std::bitset<128> > which is defined and populated in a C++ class (which is called from my Objective-C++ class.) I would like to store this object in an NSDictionary – or some equivalent of. I clearly can’t simply add the std::vector<std::bitset<128> > to the NSDictionary because it’s not of […]

Can I change an NSDictionaries key?

I have an NSDictionary object that is populated by NSMutableStrings for its keys and objects. I have been able to change the key by changing the original NSMutableString with the setString: method. They key however remains the same regardless of the contents of the string used to set the key initially. My question is, is […]

Objective-C dictionary inserting a BOOL

OK, I’m a little confused. It’s probably just a triviality. I’ve got a function which looks something like this: – (void)getNumbersForNews:(BOOL)news andMails:(BOOL)mails { NSMutableDictionary *parameters = [[NSMutableDictionary alloc] init]; [parameters setValue:news forKey:@”getNews”]; [parameters setValue:mails forKey:@”getMails”];…} It doesn’t matter whether I use setValue:forKey: or setObject:ForKey:, I’m always getting a warning: “Passing argument 1 of set… makes […]

Directly accessing nested dictionary values in Objective-C

Is there a way to directly access an inner-array of an an outer array in Objective-C? For example, a call to an external data source returns the following object: { bio = “this is the profile.bio data”; “first_name” = John; “last_name” = Doe; location = { name = “Any Town, Any State”; }; metadata = […]

Swift: Contextual type 'AnyObject' cannot be used with dictionary literal

I am having difficulty constructing this dictionary. My code looks like this: var array: [String] = [] let params: [String: AnyObject] = [ “presentation”: [ “array”: array, “current_index”: 0 ] ] The error shows up on the first line “presentation”: [ with Contextual type ‘AnyObject’ cannot be used with dictionary literal. I have tried rewriting […]

How can we create our own plist file in a Xcode project?

I want to create “UrlPaths.plist” file in my Application and also a dictionary with 4 or 5 objects. Please help me create a plist file and dictionary. And also read data from that plist file. I want the plist to add the file to resources folder and i want to add Dictionary at that time […]

Type Any has no subscript members Error in Swift 3.0?

I am following this tutorial here… And the issue I am having is I keep getting the error. “Type Any has no subscript members Error” in this function… func allItems() -> [TodoItem] { let todoDictionary = NSUserDefaults.standardUserDefaults().dictionaryForKey(ITEMS_KEY) ?? [:] let items = Array(todoDictionary.values) return items.map({TodoItem(deadline: $0[“deadline”] as! NSDate, title: $0[“title”] as! String, UUID: $0[“UUID”] as! […]

Swift Optional Dictionary unwrapping error

So here I have a basic setup var preferenceSpecification = [String : String?]() preferenceSpecification[“Key”] = “Some Key” preferenceSpecification[“Some Key”] = nil preferenceSpecification[“DefaultValue”] = “Some DefaultValue” print(preferenceSpecification) var defaultsToRegister = [String : String]() if let key = preferenceSpecification[“Key”], let defaultValueKey = preferenceSpecification[“DefaultValue”] { defaultsToRegister[key] = preferenceSpecification[defaultValueKey]! } But the error points out where it demands that […]

Sort Swift array of dictionaries by value

What is the best and most efficient way sorting an array of [String : String] by value? For example, let dicts = [[“key”: “4”], [“key”: “4”], [“key”: “3”], [“key”:”1″]] then after sorting I want to have dicts = [[“key”: “1”], [“key”: “3”], [“key”: “4”], [“key”:”4″]]

How to convert Realm object to JSON with nested NSDate properties?

I have a nested Realm Object with multiple nested NSDate properties within the nested objects. I am using this answer to transform the nested Realm Object to an NSDictionary, but I do not know how to convert that NSDictionary to actual JSON. When I use NSJSONSerialization.dataWithJSONObject(), I get the error: ‘Invalid type in JSON write […]