I do not understand how this may be used in a code. In particular I do not understand { get }.
Declarations in the framework's manuals like these are useless if no more info is given.
And there are a lot of these shortcuts. Manuals should not play peekaboo
Thanks for any hint where to find some more explicit info.
gefa
The fix is pretty simple, just as you do with any other optional:
var r_RowSelection : [IndexPath] = []
var r_RowSelectionDictionary: [String : IndexSet] = [:] // Or r_RowSelectionDictionary = Dictionary < String, IndexSet >()
if codeSystemTableView.indexPathsForSelectedRows == nil {
// May be you have to set r_RowSelectionDictionary = [:]
return // from the func you are in ; maybe you have to return something
}
// Now on, selection is not nil, and the following is safe
r_RowSelection = codeSystemTableView.indexPathsForSelectedRows!
let selectedRows = r_RowSelection.map() { $0.row}
let selectedRowsSet = IndexSet(selectedRows)
r_RowSelectionDictionary = [r_TemplateTerm : selectedRowsSet]
For your other points:
In addition I have some questions:
• I couldn't find in the manuals the function map(). I want to know something more about this function and the statement
'r_RowSelection.map() { $0.row}'
• I don't understand { $0.row} in particular not the part ' $0'
It would be very helpful if you can give me a link where I can read more about these secrets.
map() is a very powerful func on collections (as arrays): it goes through all the elements, transform them as described in the closure,
Here is what it r_RowSelection.map() { $0.row} is doing:
- will create a new array: selectedRows, derived from r_RowSelection
- $0 is the way to reference the current item in the array
- for each item ($0) in r_RowSelection, get its row
- get this item in the new array, selectedRows
There is a less condensed form that is easier to understand:
r_RowSelection.map({ (item: IndexPath) -> Int in
let result = item.row
return result
})
Should have a look at « The Swift Programming Language (Swift 4). » Apple Books. to learn more
Also read this well written tutorial
h ttps://useyourloaf.com/blog/swift-guide-to-map-filter-reduce/
You'll learn about other very important func, as filter and reduce.
If everything works OK after those explanation, don't forget to close the thread. Otherwise, don't hesitate to ask.