import UIKit
class ViewController: UIViewController {
var timeArray = [Any]()
let formatter = DateFormatter()
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
timeSlots(startTime: "11:44 AM", endTime: "6:00 PM", timeInterval: 30)
}
func timeSlots(startTime:String , endTime:String , timeInterval:Int){
formatter.dateFormat = "hh:mm a"
let startingTime = formatter.date(from: startTime)
var endingTime = formatter.date(from: endTime)
if endingTime! <= startingTime! {
return
}
formatter.dateFormat = "mm"
var min = formatter.string(from: startingTime!)
formatter.dateFormat = "hh"
var hour = formatter.string(from: startingTime!)
if Int(min)! <= 30 {
min = "30"
} else {
min = "00"
hour = String(Int(hour)! + 1)
}
formatter.dateFormat = "HH:mm"
var tempStartTime = formatter.date(from: "\(hour):\(min)")
let endTimeString = formatter.string(from: endingTime!)
endingTime = formatter.date(from: endTimeString)
formatter.dateFormat = "hh:mm a"
timeArray.append(formatter.string(from: tempStartTime!).localizedUppercase)
while tempStartTime! < endingTime! {
guard let timeSlot = Calendar.current.date(byAdding: .minute , value: timeInterval, to: tempStartTime!) else {return}
//print("timeSlot: \(formatter.string(from: timeSlot))")
tempStartTime = timeSlot
timeArray.append(formatter.string(from: timeSlot).localizedUppercase)
}
print(timeArray)
}
在ObjectPropertyBase
:
newValue == oldValue
问题: /**
* {@inheritDoc}
*/
@Override
public void set(T newValue) {
if (isBound()) {
throw new java.lang.RuntimeException((getBean() != null && getName() != null ?
getBean().getClass().getSimpleName() + "." + getName() + " : ": "") + "A bound value cannot be set.");
}
if (value != newValue) {
value = newValue;
markInvalid();
}
}
和markInvalid()
为value
,因此我无法正确覆盖private
。
问题:如何获取不进行set(newValue)
检查的类型?
此问题与this question有关。
答案 0 :(得分:0)
如何获取不执行(value!= newValue)检查的类型?
扩展SimpleObjectProperty
(或ObjectPropertyBase
)并覆盖其set
方法并跳过检查。虽然您无法自己致电markInvalid
,但该方法无法做很多事情:
class InvalidatingObjectProperty<T> extends SimpleObjectProperty<T> {
@Override
public void set(T newValue) {
if (isBound()) {
throw new java.lang.RuntimeException(
(getBean() != null && getName() != null ? getBean().getClass().getSimpleName() + "." + getName() + " : " : "")
+ "A bound value cannot be set.");
}
invalidated();
fireValueChangedEvent();
}
}
我们缺少的是将valid
设置为false
。但是,唯一重要的地方是toString
方法,您也可以覆盖它。