Merge branch 'master' of https://code.abettergeek.com/ABG/LunaMac.wiki

master
Claire 1 year ago
parent
commit
7a945c73f7
  1. 27
      Swift-Windows.md

27
Swift-Windows.md

@ -215,6 +215,33 @@ To connect this action to your button, you can either edit the XML, or use the m
Alternatively, you can `Ctrl`-and-drag from the button's **Button Cell** to the **First Responder** you'll find under **Placeholders**, and select your function `clickClick:` from the list that appears.
### D. Displaying the build version number
In LunaMac version 1.4.3, I updated the About window to dynamically display the current build number, which is set in `Info.plist`. To make this slightly easier, and because Xcode offers no way to assign unique, meaningful names to window elements, we're first going to set the `Tag` property of the "Using LunaMac" text label to `100`.
I've seen advice against using tags to identify form elements, but it's consistent and predictable, so I'm sticking with it. Note that the `Tag` property must be an **integer**, so you'll have to keep track of your tag numbers if you decide to use this method in your own projects.
To programmatically access this label and set its value, we're going to update our `viewDidAppear()` function in `ViewController.swift`.
We can retrieve the build version from the global `Bundle` object, using `Bundle.main.appBuild`.
```swift
override func viewDidAppear() {
...
if (title.contains("Changelog")) {
...
}
else if (title.contains("About")) {
// set label with version number
if (label.tag == 100) {
label.stringValue = ("Using LunaMac " + Bundle.main.appBuild)
}
}
}
```
Launch your application and open the About window, and you'll see the current version number displayed.
Now we need to make a changelog dialog, and the code to load it and its contents.
## III. The Changelog window

Loading…
Cancel
Save