NSToolbar (Mac API) UIWindowScene.titlebar.toolbar — access
func scene(_ scene: UIScene,
willConnectTo session: UISceneSession,
options connectionOptions: UIScene.ConnectionOptions) {
// setup the window
#if targetEnvironment(UIKitForMac)
if let windowScene = scene as? UIWindowScene {
if let titlebar = windowScene.titlebar {
let toolbar = NSToolbar(identifier: "myIdentifier")
// configure the toolbar, add items to it
titlebar.toolbar = toolbar
}
}
#endif
}
}
Quite different from iOS, where toolbar is usually at the bottom.
UISplitViewController (old API in new look)
new primaryBackgroundStyle
property (can be .none
or .sidebar
)
When it is .sidebar
, the embedded table view changes it's appearance as well (styles .grouped
and .insetGrouped
)
In UISplitViewController subclass:
override func viewDidLoad() {
super.viewDidLoad()
#if targetEnvironment(UIKitForMac)
primaryBackgroundStyle = .sidebar
#else
preferredDisplayMode = .allVisible
#endif
The sidebar even has a translucensy. It is REALLY a sidebar: we can change icon size in Systen Preferences!
Class NSTouchBar
(Mac API exposed to UIKit)
Access via
UIResponder.touchbar
UIViewController.childViewControllerForTouchBar
UIViewController.setNeedsTouchBarUpdate
If you have a Settings.bundle
in iOS app, you automatically get a Preferences Window, that is opened with ⌘,
keys. It is also present in the Main Menu.
- UIContextMenuInteraction
macOS icons can be larger and have transparency (have custom shape thanks to transparency)
Implement corresponding callbacks and you can drag to reorder rows without going into Edit mode
new UIHoverGestureRecognizer is used to know when the mouse is positioned over a view (buttons ans other controls can be slightly highlighted on mouse over — hovered)
iOS: NSData write with encryption
data.write(to: file, options: .completeFileProtection
It compiles on macOS but without protection ) We can rely in FileVault ot use new CryptoKit
let key = SymmetricKey(size: .bits256)
let sealed = try AES.GCM.seal(data, using: key)
// write file to disk
// write key to the keychain
- UIKeyCommand
- UICommand
- UIMenu
- UIMenuBuilder
We can use as is, basic one. We can customize it in Interface Builder and we can customize it in code for text fields
In AppDelegate:
override func buildCommands(with builder: UICommandBuilder) {
guard builder.system == .main else { return }
// we don't need `Format` menu in Main menu,
// so let's remove it
builder.remove(menu: .format)
// let's add
let addNoteCommand = UIKeyCommand(title: "New Note…",
action: #selector(...),
input: "f",
modifierFlags: [.command, .alternate])
let menu = UIMenu<UICommand>.create(title: "",
image: nil,
identifier(UIMenuIdentifier(""),
options: .displayInline),
children: [addNoteCommand])
builder.insertChild(menu, atStartOfMenu: .file)
It works both on Mac and iPad with keypad