Comments (1)
You can assign the dictionary literal directly to the variable of type OrderedDictionary<String, AnyObject>
like this:
let orderedDictionary: OrderedDictionary<String, AnyObject> = ["A": [1], "B": [2]]
However if the dictionary is dynamically constructed, there is no direct way to convert it to the ordered dictionary. In that case I'd suggest to map the dictionary to an array of key-value tuples and use it to initialize the ordered dictionary. Be aware of the non-deterministic ordering of the dynamic data in pure Dictionary
. You better sort those elements according your specific logic before constructing the ordered dictionary.
let dictionary: [String: AnyObject] = ["A": [1], "B": [2]]
let elements = dictionary.map({ ($0, $1) })
let sortedElemetns = elements.sort(...)
let orderedDictionary = OrderedDictionary<String: AnyObject>(elements: sortedElements)
I hope this helps. If you have further questions, feel free to ask.
from ordereddictionary.
Related Issues (20)
- Integrate containment optimizations from maicki's fork
- Add a note to README about no official support for CocoaPods
- Key based access fails with error when Dictionary key is an integer type HOT 6
- Package.swift seems invalid for Swift 4.2.1 HOT 2
- Fix warnings for Swift 5.0
- OrderedDictionary does not serialize to JSON using JSONSerialization or JSONEncoder HOT 1
- how to use cocoapods? HOT 1
- how to convert [String:[[String:AnyObject]]] to OrderedDictionary type? HOT 1
- V3.0.0 CFBundleShortVersionString missing HOT 3
- Move LinuxMain.swift to /Tests
- SwiftUI ForEach? HOT 6
- Cannot insert duplicate key HOT 2
- `filter` should return a new OrderedDictionary, not an array of Key-Value pairs HOT 2
- Direct access to keys array instead of the lazy variant only
- Precondition Failed: Inconsistency error occurred in OrderedDictionary HOT 2
- Apple m1 support
- Inspect memory leaks in implementation on v4.0 branch
- Xcode 13 Build Issues HOT 2
- Convert to a proper SPM package and remove Xcode project
- The Server SSL certificate failed to verify HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from ordereddictionary.