### Simple Animation View Example Source: https://developer.apple.com/documentation/technologyoverviews/animations A custom NSView that displays an image and animates its position when clicked. It uses NSAnimationContext for smooth transitions. ```swift class SimpleAnimationView: NSView { var name: String = "globe" var imageView : NSImageView? = nil override init(frame: CGRect) { super.init(frame: frame) configureSubviews() } required init?(coder: NSCoder) { super.init(coder: coder) configureSubviews() } func configureSubviews() { let image = NSImage(systemSymbolName: name, accessibilityDescription: nil) imageView = NSImageView(image: image!) self.addSubview(imageView!) imageView!.leadingAnchor.constraint(equalTo: self.leadingAnchor).isActive = true imageView!.trailingAnchor.constraint(equalTo: self.trailingAnchor).isActive = true imageView!.topAnchor.constraint(equalTo: self.topAnchor).isActive = true imageView!.bottomAnchor.constraint(equalTo: self.bottomAnchor).isActive = true let gesture = NSClickGestureRecognizer(target: self, action: #selector(animateImage)) self.addGestureRecognizer(gesture) } @objc func animateImage() { NSAnimationContext.runAnimationGroup { context in context.duration = 0.3 context.timingFunction = CAMediaTimingFunction(name: .easeOut) self.animator().frame.origin.y += 40 } completionHandler: { NSAnimationContext.runAnimationGroup { context in context.duration = 0.3 context.timingFunction = CAMediaTimingFunction(name: .easeIn) self.animator().frame.origin.y -= 40 } } } } ``` -------------------------------- ### Swift Type Declaration and Implementation Source: https://developer.apple.com/documentation/technologyoverviews/development-process Demonstrates the basic syntax for declaring a structure, initializing its properties, and defining methods in Swift. This is a fundamental example for understanding Swift's type system. ```swift // Type declaration and implementation. struct PersonRecord { let name: String var age: Int = 0 // Initialize a new instance of the type. init(_ name: String) { self.name = name } // Declare a function to update the age. func updateAge(_ newAge: Int) { guard let newAge > 0 else { return } age = newAge } } ``` -------------------------------- ### Define a SwiftUI View with Environment and State Source: https://developer.apple.com/documentation/technologyoverviews/swiftui Example of a view structure utilizing @Environment and @State property wrappers to manage data and navigation state. ```swift struct CategoryView: View { @Environment(PlayerModel.self) private var player @Environment(\.modelContext) private var context @State private var navigationPath: [NavigationNode] @State private var videos: [Video] = [] private let category: Category private let namespace: Namespace.ID var body: some View { // Wrap the content in a vertically scrolling view. NavigationStack(path: $navigationPath) { ScrollView(showsIndicators: false) { VStack(alignment: .leading) { Text(category.name) .font(.title.bold()) Text(category.description) .font(.body) ... } } ... } } } ``` -------------------------------- ### Accept Xcode license agreement Source: https://developer.apple.com/documentation/technologyoverviews/building-your-macos-game-remotely-from-your-pc Execute this command in the Mac's Terminal and follow the prompts to accept the Xcode license agreement. This is required before using Xcode for builds. ```bash sudo xcodebuild -license ``` -------------------------------- ### Handle Button and Slider Interactions in SwiftUI Source: https://developer.apple.com/documentation/technologyoverviews/swiftui Use inline closures to specify actions for controls like Buttons and Sliders. The Slider example shows how to bind its value and handle editing changes. ```swift Button("Button") { // Action } ``` ```swift Slider( value: $speed, in: 0...100, onEditingChanged: { editing in isEditing = editing } ) ``` -------------------------------- ### Define a SwiftUI App Entry Point Source: https://developer.apple.com/documentation/technologyoverviews/swiftui The App structure acts as the main entry point for a SwiftUI application, where global data is initialized and scenes are declared. ```swift import SwiftUI @main struct MyApp: App { var body: some Scene { WindowGroup { ContentView() } } } ``` ```swift import SwiftUI @main struct MyDocApp: App { var body: some Scene { DocumentGroup(newDocument: MyDocAppDocument()) { file in ContentView(document: file.$document) } } } ``` -------------------------------- ### Verify macOS and Xcode versions Source: https://developer.apple.com/documentation/technologyoverviews/building-your-macos-game-remotely-from-your-pc Run this command in the Mac's Terminal to check the macOS product version and Xcode version. Ensure your Mac meets the minimum requirements. ```bash % sw_vers -productVersion && xcodebuild -version ``` -------------------------------- ### Configure CMakePresets for lldb-dap Source: https://developer.apple.com/documentation/technologyoverviews/building-your-macos-game-remotely-from-your-pc Defines the build preset for macOS debugging, including the Ninja generator and remote settings for Visual Studio. ```json { "version": 3, "configurePresets": [ { "name": "macos-debug", "displayName": "macOS-Clang-Debug", "generator": "Ninja", "binaryDir": "${sourceDir}/out/build/${presetName}", "installDir": "${sourceDir}/out/install/${presetName}", "cacheVariables": { "CMAKE_BUILD_TYPE": "Debug" }, "condition": { "type": "equals", "lhs": "${hostSystemName}", "rhs": "Darwin" }, "vendor": { "microsoft.com/VisualStudioRemoteSettings/CMake/1.0": { "sourceDir": "$env{HOME}/.vs/$ms{projectDirName}" } } } ] } ``` -------------------------------- ### Read Data from a File Using FileHandle Source: https://developer.apple.com/documentation/technologyoverviews/files-and-directories Open a file for reading using `FileHandle` and read its entire contents into a `Data` object. This method is suitable for reading existing files. ```swift let filePathURL = ... // A path to an existing file. do { // Open a file handle and read data from it. let fileHandle = try FileHandle(forReadingFrom: filePathURL) let fileContents = try fileHandle.readToEnd() print("File read successfully.") } catch { print("File not read.") } ``` -------------------------------- ### Adopt New Button Styles with Liquid Glass Source: https://developer.apple.com/documentation/technologyoverviews/adopting-liquid-glass Use these button style APIs to adopt the Liquid Glass look and feel with minimal code, instead of creating custom effects. ```swift glass ``` ```swift glassProminent ``` ```swift glass(_:) ``` ```swift glass() ``` ```swift prominentGlass() ``` ```swift clearGlass() ``` ```swift prominentClearGlass() ``` ```swift NSButton.BezelStyle.glass ``` -------------------------------- ### macOS Bundle Structure Source: https://developer.apple.com/documentation/technologyoverviews/files-and-directories This illustrates the hierarchical structure of a macOS application bundle, typically seen in the Finder as a single file but containing distinct directories for code and resources. ```text MyApp.app Contents MacOS MyApp PkgInfo Resources Assets.car en.lproj de.lproj ... ``` -------------------------------- ### Localize String with Unicode and Comments Source: https://developer.apple.com/documentation/technologyoverviews/text-display Use a String initializer that takes a localized value to add strings to your string catalogs. Include a comment to provide context for translators. ```swift myLabel.string = String(localized: "There are \(peopleInChat) people in this chat.", comment: "Label indicating number of chat participants.") ``` -------------------------------- ### Configuring Confirmation Dialog Source: https://developer.apple.com/documentation/technologyoverviews/adopting-liquid-glass Configure a confirmation dialog with options for presenting, title visibility, and source. This is useful for action sheets originating from specific controls. ```swift confirmationDialog(_:isPresented:titleVisibility:presenting:actions:) ``` -------------------------------- ### Create a Fixed Spacer in Toolbars Source: https://developer.apple.com/documentation/technologyoverviews/adopting-liquid-glass Use these APIs to create a fixed spacer for separating toolbar items that share a background. ```swift fixed ToolbarSpacer fixedSpace(_:) space ``` -------------------------------- ### Using UISplitViewController for Fluid Resizing Source: https://developer.apple.com/documentation/technologyoverviews/adopting-liquid-glass Implement UISplitViewController to support continuous window resizing by automatically reflowing content. This system API ensures fluid transitions for resizing. ```objective-c UISplitViewController ``` -------------------------------- ### Define a minimal CMake project Source: https://developer.apple.com/documentation/technologyoverviews/building-your-macos-game-remotely-from-your-pc Specifies the minimum CMake version, project name, and executable target for a macOS build. ```cmake cmake_minimum_required(VERSION 3.26) project(gptksample) add_executable(gptksample main.m) ``` -------------------------------- ### Declare a SwiftUI View Source: https://developer.apple.com/documentation/technologyoverviews/swiftui Views are lightweight structures where the body property defines the interface content using other views and modifiers. ```swift import SwiftUI struct LibraryItemView: View { var book: Book var body: some View { VStack(alignment: .leading) { Text(book.title) Text("Written by: \(book.author.name)") .font(.caption) } } } ``` -------------------------------- ### iOS/iPadOS/tvOS/visionOS/watchOS Bundle Structure Source: https://developer.apple.com/documentation/technologyoverviews/files-and-directories This shows the flatter organizational structure of bundles on iOS, iPadOS, tvOS, visionOS, and watchOS, designed for simplicity and efficient resource access. ```text MyApp.app Assets.car MyApp PkgInfo en.lproj de.lproj ... ``` -------------------------------- ### Setting Action Sheet Source Item Source: https://developer.apple.com/documentation/technologyoverviews/adopting-liquid-glass Define the source item for an action sheet, indicating where it originates from. This is crucial for achieving the correct inline presentation. ```swift sourceItem ``` -------------------------------- ### Use Semantic Search Tabs in SwiftUI Source: https://developer.apple.com/documentation/technologyoverviews/adopting-liquid-glass Implement semantic search tabs in SwiftUI using the Tab view with the .search role. ```swift Tab(role: .search) { // ... } ``` -------------------------------- ### Presenting a Sheet Modally Source: https://developer.apple.com/documentation/technologyoverviews/adopting-liquid-glass Use beginSheetModal to present a sheet modally for a given window, with a completion handler executed upon dismissal. This method is part of the API for presenting modal views. ```objective-c beginSheetModal(for:completionHandler:) ```