Hello dear readers,
I’m having an issue with dictionaries.
I have a this: Key0:Value\nKey1:Value\nKey2:Value\nKey3:Value\n
I would like to create a dictionary with these keys and values.
I have written this code for now:
let deciphered = str.split(separator: "\n").reduce(into: [String: AnyObject]()) {
let str = $1.split(separator: ":")
if let first = str.first, let key = String(first), let value = str.last {
$0[key] = value as AnyObject
}
}```
But I'm having this error:
```**error: initializer for conditional binding must have Optional type, not 'String'**
**if let first = str.first, let key = String(first), let value = str.last {**
^ ~~~~~~~~~~~~~
Can you help me or give me an other way to store it ?