I have a simple class to interval run some code when call it start ;
// Test.swift
public class Test {
var timer Timer?
public func start(){
//
print("2“) // print
timer = Timer.scheduledTimer(5,true,{
// code here
print("3") // not print
}
// RunLoop.current.add(timer,forMode:.commonMode) // uncomment this line also not work
}
}
// Class2.swift
class Class2: ParentClass{
private let test = Test()
@objc public func check(flag:String){
if flag == "Y" {
print("1")
test.start()
}
}
}
But the timer seems not work --- not print "3"
But I try to create a timer at some other class, it work, just at Test class not run ....
Anyone know why ?