I'm building an iOS app for iOS 10+. The app builds fine in Debug configuration, but in Release fails to compile swift source code that references WidgetCenter
.
It outputs the error Cannot find WidgetCenter in scope
even though I'm importing WidgetKit
and optionally embedding the framework.
import Foundation
import WidgetKit
class MyWidgetCenter: NSObject {
@available(iOS 14, *)
func reloadTimelines(_ kind: String) {
// this line causes error: cannot find 'WidgetCenter' in scope
WidgetCenter.shared.reloadTimelines(ofKind: kind)
}
@available(iOS 14, *)
func reloadAllTimelines() {
// this line causes error: cannot find 'WidgetCenter' in scope
WidgetCenter.shared.reloadAllTimelines()
}
}
Edit:
It builds fine for the simulator and my connected device (iPhone XR) in Release configuration when I set the Build Active Architecture Only
flag. It's only when it's building for multiple architectures that it fails to compile. Are there architecture restrictions for WidgetKit
that I'm not accounting for?
I believe WidgetKit is supposed to support the armv7
architecture, however it fails to compile usage of WidgetCenter
for armv7
.
My workaround is to wrap the WidgetCenter
statements, to only support the architectures I need outside of armv7
class MyWidgetCenter: NSObject {
@available(iOS 14, *)
func reloadTimelines(_ kind: String) {
#if arch(arm64) || arch(i386) || arch(x86_64)
WidgetCenter.shared.reloadTimelines(ofKind: kind)
#endif
}
@available(iOS 14, *)
func reloadAllTimelines() {
#if arch(arm64) || arch(i386) || arch(x86_64)
WidgetCenter.shared.reloadAllTimelines()
#endif
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With