Here are a couple of actual examples from the Apple developer forums:
func sliderDidChangeValue(_ newSliderValue: Float, parentCell: CustomCell) {
let parentCellIndexPath = tblExpandable.indexPath(for: parentCell)
getIndicesOfVisibleRows()
let indexOfChangedRow = visibleRowsPerSection[(parentCellIndexPath?.section)!][(parentCellIndexPath?.row)!]
let newStep = roundf(newSliderValue / 0.1)
let stepped = String.localizedStringWithFormat("%.1f %@", newStep * 0.1 , "")
((cellDescriptors[(parentCellIndexPath?.section)!])[(indexOfChangedRow)]).updateValue(stepped, forKey: "secondaryTitle")
((cellDescriptors[(parentCellIndexPath?.section)!])[(indexOfChangedRow)-1]).updateValue(stepped, forKey: "primaryTitle")
tblExpandable.reloadSections(IndexSet(integer: ((parentCellIndexPath?.section)!)), with: UITableViewRowAnimation.fade)
}
This user seems to have learned to resolve optionality issues stepwise, following the initial fixit to insert a ?
, then a second fixit to insert a !
. It doesn't crash, and it's perfectly well-formed both syntactically and semantically.
@objc func scrapePDF() {
let documentURL = self.documentDisplayWebView!.url!
let document = PDFDocument(url: documentURL)
let numberOfPages = document!.pageCount
DispatchQueue.global().async {
for pageNumber in 1...numberOfPages {
print(document?.page(at: pageNumber)!.string!)
}
}
}
This user knew about using !
on document
at the first reference, but apparently followed fixits the second time. Also, the user added !
to the documentURL
declaration, but never thought of doing the exact same thing on the next line.
New users don't learn anything from this. They just conclude that Swift is a stupid language.
I've seen much worse, much more convoluted, examples than these.