45 lines
1.6 KiB
Swift
45 lines
1.6 KiB
Swift
//
|
|
// CollectionViewMonth.swift
|
|
// Graphic Analysis 2
|
|
//
|
|
// Created by Kilian Hofmann on 16.06.17.
|
|
// Copyright © 2017 Kilian Hofmann. All rights reserved.
|
|
//
|
|
|
|
import Cocoa
|
|
|
|
class CollectionViewMonth: NSObject {
|
|
var days: [[FileWrapper?]] = []
|
|
var month: Int? = nil
|
|
|
|
override init() {
|
|
super.init()
|
|
}
|
|
|
|
init(days: [[FileWrapper?]]) {
|
|
super.init()
|
|
self.days = days
|
|
}
|
|
}
|
|
|
|
extension CollectionViewMonth: NSCollectionViewDataSource {
|
|
func collectionView(_ collectionView: NSCollectionView, numberOfItemsInSection section: Int) -> Int {
|
|
return 31
|
|
}
|
|
|
|
func collectionView(_ itemForRepresentedObjectAtcollectionView: NSCollectionView, itemForRepresentedObjectAt indexPath: IndexPath) -> NSCollectionViewItem {
|
|
let item = itemForRepresentedObjectAtcollectionView.makeItem(withIdentifier: "CollectionViewItemMonth", for: indexPath)
|
|
guard let item2 = item as? CollectionViewItemMonth else { return item }
|
|
item2.loss.stringValue = ""
|
|
item2.day.textColor = NSColor.controlShadowColor
|
|
item2.day.stringValue = "\(indexPath.item + 1)"
|
|
guard month != nil else { return item2 }
|
|
guard let day = days[month!][indexPath.item] else { return item2 }
|
|
item2.day.textColor = NSColor.black
|
|
guard let log = day.fileWrappers?["KDLog.txt"] else { return item2 }
|
|
guard let loss = (String(data: log.regularFileContents!, encoding: .utf8)?.components(separatedBy: "\n").count) else { return item2 }
|
|
item2.loss.stringValue = "\(loss)"
|
|
return item2
|
|
}
|
|
}
|