I have the following code:
struct Product {
var image: URL!
var title: String!
var price: Price!
var rating: Float!
var url: URL!
}
struct Price {
var value: Double!
var currency: String! // should be enum
}
I later initialize a Product
with:
product = Product(
image: URL(string: "...")!,
title: "...",
price: Price(
value: 5.99,
currency: "CAD"
),
rating: 4.5,
url: URL(string: "...")!
)
During runtime, product.price
is of type Price?
I find this weird since it's implicitly unwrapped.
I've tried giving Price
an init()
method, with the same results. I've also tried using var price: Price! = Price(value: 0, currency: "CAD")
in the Product
definition, with the same results. (I add a memberwise initializer to Price
.)
What's going on here?