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!
Post
Replies
Boosts
Views
Activity
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?
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?
Hi,Does anyone know how to add images inline in a post. Sometimes I have a question and it is best explained with accompanying text and an image or screenshot. Do Apple Developer Forums even support images... if so, @AppleDeveloperForums... please add this feature.. Thanks!