I have a watch face with a background process. In the View class, I have several class-level constants for loading custom fonts and strings (to use in the foreground). I also have a couple of color variables. The type checker doesn't like any of these because they are "not available in all function scopes" (i.e., background). But because they're at the class level, I cannot bypass type checking with (:typecheck(disableBackgroundCheck) like I could with a function.
Is there any way I can use class-level constants and variables like this in an app with a background process and avoid type checking issues?
class MyWatchFaceView extends Ui.WatchFace {
var foregroundColor as Gfx.ColorType = Gfx.COLOR_WHITE;
var backgroundColor as Gfx.ColorType = Gfx.COLOR_BLACK;
const fontSmall = Ui.loadResource(Rez.Fonts.small);
const fontLarge = Ui.loadResource(Rez.Fonts.large);
const weekdays = [
Ui.loadResource(Rez.Strings.Day0),
Ui.loadResource(Rez.Strings.Day1),
Ui.loadResource(Rez.Strings.Day2),
Ui.loadResource(Rez.Strings.Day3),
Ui.loadResource(Rez.Strings.Day4),
Ui.loadResource(Rez.Strings.Day5),
Ui.loadResource(Rez.Strings.Day6)
];
const months = [
Ui.loadResource(Rez.Strings.Month00),
Ui.loadResource(Rez.Strings.Month01),
Ui.loadResource(Rez.Strings.Month02),
Ui.loadResource(Rez.Strings.Month03),
Ui.loadResource(Rez.Strings.Month04),
Ui.loadResource(Rez.Strings.Month05),
Ui.loadResource(Rez.Strings.Month06),
Ui.loadResource(Rez.Strings.Month07),
Ui.loadResource(Rez.Strings.Month08),
Ui.loadResource(Rez.Strings.Month09),
Ui.loadResource(Rez.Strings.Month10),
Ui.loadResource(Rez.Strings.Month11)
];
(:typecheck(disableBackgroundCheck))
function initialize() {
WatchFace.initialize();
}
...
}
For a separate but related question, in the App file, I have a global variable for a custom class for app settings (e.g., "gSettings"). If I try to initialize it at the global level by creating a new class instance, I get an illegal error in the debug console. So for now I'm living with the "untyped" warning.
Is it possible to have a global variable assigned to a custom class and avoid type checking issues?