现在我正在开发一个时间表应用程序,允许用户打卡记录工作时间。但是我遇到了一些问题,不知道如何实现这个功能。
我的模型中有:
struct TimeLog {
var punchInTime: CFAbsoluteTime
var punchOutTime: CFAbsoluteTime
var timeWorked: Double
init (pInTime: CFAbsoluteTime, pOutTime: CFAbsoluteTime) {
self.punchInTime = pInTime
self.punchOutTime = pOutTime
self.timeWorked = pOutTime - pInTime
}
}
在我的视图控制器中:
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
@IBAction func punchInButtonPressed(sender: AnyObject) {
// not sure what actions are needed here to start the "aTimeLog" variable
}
@IBAction func punchOutButtonPressed(sender: AnyObject) {
// not sure what actions are needed here to complete the "aTimeLog" variable
}
我正在尝试完成这个变量:
var aTimeLog = TimeLog(pInTime: //get the punch in time here, pOutTime: //get the punch out time here)
一旦变量"aTimeLog"完成(即按下punchOutButton),我希望显示所有"timeWorked"变量的日志记录。
提前道歉,您可能能够看出我正在学习编程和Swift。