A
A
arturios5712016-10-18 13:06:14
Swift
arturios571, 2016-10-18 13:06:14

How to reach the classa element subscribed to the sub protocol?

Please tell me how to do it right so that I can reach out to expired) Newbie don't kick Sin, thanks)!
5f4ca5035dbd47b79715a7845f6d4810.png

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
arturios571, 2016-10-18
@arturios571

var fridge = [Storable]() // empty array of type Storable fridge
for prod in basket {
if let storableProduct = prod as? Storable where storableProduct.expired == false {
fridge.append(storableProduct)
}
Might be useful to someone

A
Anton Zhilin, 2016-10-18
@Anton3

In Swift 3, the syntax for multiple conditions in a single if let has changed:

if let storableProduct = prod as? Storable, storableProduct.expired == false {
    fridge.append(storableProduct)
}

At the same time, where is still used in for, while, switch.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question