Reputation: 31
I was watching lecture 2 in Stanford's iOS development course and noticed an odd way of declaring an array.
var cards: Array<MemoryGame<String>.Card> {
return model.cards
}
I do not recognize this method of initializing an array and have not been able to find any details about it in Apple's documentation. When I tried to initialize the above array by using an equals sign and a closure, it stated that "Instance member 'model' cannot be used on type 'EmojiMemoryGame'; did you mean to use a value of this type instead?" I understand that this is because of the circular definition of the property cards and an instance of the class. However, I don't understand how the code above circumvents this issue. I also noticed that the code also correctly intialized the array in the sample case I set up below:
var arr1: Array<Int> = [1, 2, 3, 4, 5]
var arr2: Array<Int> {
return arr1
}
Could someone please explain how this method of initializing arrays work or link me to a piece of documentation that explains this?
Upvotes: 0
Views: 54