This file contains hidden or 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
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, | |
sizeForItemAt indexPath: IndexPath) -> CGSize { | |
return gridViewModel.cellSize(for: collectionView.bounds, at: indexPath) | |
} |
This file contains hidden or 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
import UIKit | |
class GridViewModel { | |
static var itemMargin: CGFloat = 8.0 | |
var data: [Int] = (1...10).map { $0 } | |
func cellSize(for frame: CGRect, at indexPath: IndexPath) -> CGSize { | |
let height = (frame.height / 5) - 2 * GridViewModel.itemMargin | |
let fullWidth = frame.width | |
let halfWidth = (frame.width / 2) - (GridViewModel.itemMargin / 2) |
This file contains hidden or 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
class GridViewModelTests: XCTestCase { | |
let testFrame = CGRect(x: 0, y: 0, width: 72, height: 130) | |
let expectedFullWidth: CGFloat = 72 // 72 | |
let expectedHalfWidth = (72 / 2) - (GridViewModel.itemMargin / 2) //32 | |
let expectedHeight = (130 / 5) - 2 * GridViewModel.itemMargin //10 | |
// ... tests one through five | |
func testSixItemCellSize() { | |
let expectedCellSizes = [ |
This file contains hidden or 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
func cellSize(for frame: CGRect, at indexPath: IndexPath) -> CGSize { | |
let height = (frame.height / 5) - 2 * GridViewModel.itemMargin | |
let fullWidth = frame.width - 2 * GridViewModel.itemMargin | |
return CGSize(width: fullWidth, height: height) | |
} |
This file contains hidden or 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
class GridViewModelTests: XCTestCase { | |
let testFrame = CGRect(x: 0, y: 0, width: 72, height: 130) | |
let expectedFullWidth: CGFloat = 72 // 72 | |
let expectedHeight = (130 / 5) - 2 * GridViewModel.itemMargin //10 | |
func testOneItemCellSize() { | |
let expectedCellSize = CGSize(width: expectedFullWidth, height: expectedHeight) | |
let viewModel = GridViewModel() | |
viewModel.data = [1] | |
let row = 0 |
This file contains hidden or 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
import UIKit | |
class GridViewModel { | |
static var itemMargin: CGFloat = 8.0 | |
var data: [Int] = (1...10).map { $0 } | |
func cellSize(for frame: CGRect, at indexPath: IndexPath) -> CGSize { | |
return CGSize(width: 0, height: 0) | |
} | |
} |
This file contains hidden or 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
import UIKit | |
class ViewController: UIViewController, UICollectionViewDataSource, UICollectionViewDelegateFlowLayout { | |
@IBOutlet weak var collectionView: UICollectionView! | |
private let gridViewModel = GridViewModel() | |
override func viewDidLoad() { | |
super.viewDidLoad() |
This file contains hidden or 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
$oneString = array("", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine"); | |
$tenString = array("", "ten", "twenty", "thirty", "forty", "fifty", "sixty", "seventy", "eighty", "ninety", "one hundred"); | |
$teenString = array("", "eleven", "twelve", "thirteen", "fourteen", "fifteen", "sixteen", "seventeen", "eighteen", "nineteen"); | |
for ($count = 100; $count > 0; --$count) { | |
$next = $count - 1; | |
$count_text = (!($count>10 && $count<20) ? $tenString[$count/10] . (($count%10 != 0 && $count>9) ? " " : "") . $oneString[$count%10] : $teenString[$count-10]); | |
$next_text = (!($next>10 && $next<20) ? $tenString[$next/10] . (($next%10 != 0 && $next > 9) ? " " : "") . $oneString[$next%10] : $teenString[$next-10]); | |
print (ucFirst($count_text). " bottles of beer on the wall, " . $count_text . " bottles of beer! Take one down, and pass it around; " . $next_text . " bottles of beer on the wall! |