Post

Replies

Boosts

Views

Activity

syntax of the reduce method in Swift
Hi,Working on a simple problem where I want to sum all the elements in an int array. All the numbers in the array are positive. I came accross the reduce method online and I noticed the following syntax:let items = [2, 4, 5, 7] let sum = items.reduce(0, +) // result is 18I understand that the first argument is the initial result (in my case 0). I'm having a hard time understand the nextPartialResult closure which is the second argument. I also don't understand the "+" syntax, I'm guessing that shorthand for summing all the elements in the array. I don't want to just use that code without understanding what it means...Any help would be appreciated!Thanks!
2
1
2.2k
Feb ’20
Swift Dictionary order does not match JSON file
I'm working on parsing a JSON file into a dictionary: // JSON Payload File { "orderPlaced": "done", "prep": "pending", "shipped" : "pending" }Here is my code to make a dictionary from that file: if let path = Bundle.main.path(forResource: "JSONPayload", ofType: "json") { do { // Data from JSON file path let data = try Data(contentsOf: URL(fileURLWithPath: path), options: []) // JSON dicrtionary being made let json = try JSONSerialization.jsonObject(with: data) as! [String: Any] print(json) } catch let jsonErr { print("err", jsonErr) }Expected output: ["orderPlaced": done, "prep": pending, "shipped": pending]The actual output is: ["shipped": pending, "orderPlaced": done, "prep": pending]Is there a way I can re-order my dictionary or have it ordered from the start. I'm assuming the latter request might not be doable since dictionaires from my understanding are un-ordered. Maybe the only thing I can do is re-order after the dictionary is made, but how would i do that? Do I have to modify my JSON file and the Swift code or just one or ther other?
10
0
8.5k
Aug ’18
Is Apple CloudKit Compliant with HIPPA?
Hi, So I have been recently work on some research for a Health Care application where HIPPA compliance is a requirement. I had done research into FireBase and that seemed good, but as of May 2018 it is not HIPPA compliant. I was looking around and Apple CloudKit seems like a good option, however I could not find any information from Apple's developer pages about CloudKit on whether it was HIPPA compliant or not?
3
1
2.4k
Jul ’18