New with Swift 3, you can use Foundation value types to get compile time checks to eliminate many of the errors that couldn't be discovered until runtime when using reference-based Foundation types. Let's work through an example that demonstrates a runtime check in Swift 2.2.
In Swift 2.2:
if let filePath = NSBundle.mainBundle().pathForResource("testFile", ofType: "txt"){ let fileURL = NSURL.fileURLWithPath(filePath) let keys = [NSURLCreationDateKey, NSURLPathKey, NSURLFileSizeKey,NSURLTagNamesKey] var values = try fileURL.resourceValuesForKeys(keys) if let creationDate = values[NSURLCreationDateKey]{ print("creationDate: \(creationDate)") } values[NSURLTagNamesKey] = ["test", "sample", "playground"] values[NSURLCreationDateKey] = "now" // à creates an error print(values[NSURLTagNamesKey]) print(values[NSURLCreationDateKey]) ...