鉴于功能" printTime"打印3个语句(H / M / S)每秒使用NSTimer中断调用此函数的确切语法是什么?
答案 0 :(得分:2)
试试这个:
String url = "https://play.google.com/store/apps";
final Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
startActivity(intent);
您需要将import Foundation
import XCPlayground
class Wrapper: NSObject {
static let formatter: NSDateFormatter = {
let formatter = NSDateFormatter()
formatter.dateFormat = "HH:mm:ss"
return formatter
}()
class func printTime() {
print(formatter.stringFromDate(NSDate()))
}
}
let timer = NSTimer.scheduledTimerWithTimeInterval(1, target: Wrapper.self, selector: #selector(Wrapper.printTime), userInfo: nil, repeats: true)
XCPlaygroundPage.currentPage.needsIndefiniteExecution = true
函数包装在对象中以发送到printTime
。当你改变游乐场的代码时,循环将结束。