I have this test class:
class OrderParserTests: XCTestCase {
var previewJson : String!
override func setUp(){
let path = Bundle(for: type(of: self)).path(forResource: "orderDocumentPreviewResponse", ofType: "json") ?? ""
self.previewJson = try! String(contentsOfFile: path)
}
func testStandardOrder(){
...
}
}
previewJson
is of type String, but I don't need an initializer to set it and it starts with a default value of nil even though it's a non optional field (I think).
Am I misunderstanding what ! does to fields?
What is the difference between
var previewJson: String?
and
var previewJson: String!