There is such a keyword in swift: try? and try! , what are their application scenarios?
try?:
1. Application scenario: When a function or method throws an exception, the exception can be converted to an optional type, return a nil, the program does not crash, if the program is normal, it will return a correct optional type;
Eg: letanyobject = try? Nsjsonserialization.jsonobjectwithdata (Jsondata, Options:. Mutablecontainers)
2. Format: let+ attribute + try? + Functions or methods;
3. Note: The returned is an optional type, note that when mixed with other methods, there are multiple package options for the type of unpacking problem.
try!:
1. Meaning: Wrong wrong transmission chain, try! broke the wrong propagation chain, but if there is a real error in the run-time error, resulting in a program crash.
2. Format: let+ properties + try! + Functions or methods;
3. Note: If an error occurs, a run-time error occurs, causing the program to crash.
Swift in Try