我一直在使用以下帖子作为如何显示UIAlertController与特定无关的from代码的指导UIViewController。现在,我要对该代码进行单元测试:
func showAlert(alert: UIAlertController, animated: Bool, completion: (()->Void)?)
{
let alertWindow = UIWindow(frame: UIScreen.mainScreen().bounds)
// Keep a strong refence to the window.
// We manually set this to nil when the alert is dismissed
self.alertWindow = alertWindow
alertWindow.rootViewController = UIViewController()
if let currentTopWindow = UIApplication.sharedApplication().windows.last {
alertWindow.windowLevel = currentTopWindow.windowLevel + 1
}
else {
// This case only happens during unit testing
Logger.trace(ICELogLevel.Error, category: .Utility, message: "The application doesn't have a window being displayed!") …Run Code Online (Sandbox Code Playgroud) 我的应用程序中有一个视图控制器,用于调试目的以显示应用程序的一些内部结构(仅适用于本地 xcode 版本,应用程序商店版本没有此控制器)。
在此控制器中,我有一个标签,我想反映内部组件的状态(具体来说,我希望它显示该组件是启用还是禁用)。
我的问题:
.attributedText#1:将UILabel 的属性设置为与之前相同的值是否昂贵,或者我应该缓存旧值并仅在属性更改时设置该属性?
.text#2:(非归属)财产怎么样?
我目前正在使用以下代码:
// Schedule timer to update the control panel. (This is debug-only, so not worth
// the complexity of making this event-based)
Timer.scheduledTimer(withTimeInterval: 0.5,
repeats: true) { [weak self] timer in
DispatchQueue.main.async {
// Stop timer if we've been dealloced or are no longer being presented
guard let strongSelf = self,
strongSelf.isBeingPresented else
{
timer.invalidate()
return
}
// "Something Enabled / Disabled" label
let somethingIsEnabled = strongSelf.someDepenency.isEnabled
let somethingEnabledString = …Run Code Online (Sandbox Code Playgroud)