Created
December 18, 2015 03:50
-
-
Save davenportw15/3c28c5b713475d43271a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// LazySquares.swift | |
// SwiftBook | |
// | |
// Created by William Davenport on 12/10/15. | |
// Copyright © 2015 William Davenport. All rights reserved. | |
// | |
import Foundation | |
class SquareContainer { | |
let maximum: Int | |
lazy var squares: [Int] = (1...self.maximum).map { n in | |
print(n) | |
return n * n | |
} | |
init(withMaximum maximum: Int) { | |
self.maximum = maximum | |
} | |
} | |
let squareContainer = SquareContainer(withMaximum: 100) | |
print("squareContainer.squares not yet calculated") | |
print(squareContainer.squares) | |
print("squareContainer.squares now calculated") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment