Skip to content

Instantly share code, notes, and snippets.

//
// HelloWorldApp.swift
// HelloWorld
//
// Created by Zheng on 6/22/20.
//
import SwiftUI
@main
struct ContentView: View {
var body: some View {
Text("Hello world!").padding()
}
}
class SceneDelegate: UIResponder, UIWindowSceneDelegate {
...
lots more code
...
func sceneDidBecomeActive(_ scene: UIScene) {
// Called when the scene has moved from an inactive state to an active state.
// Use this method to restart any tasks that were paused (or not yet started) when the scene was inactive.
print("scene is now active!")
}
func sceneWillResignActive(_ scene: UIScene) {
@main
struct HelloWorldApp: App {
@Environment(\.scenePhase) private var scenePhase
var body: some Scene {
WindowGroup {
ContentView()
}
.onChange(of: scenePhase) { (newScenePhase) in
switch newScenePhase {
case .active:
//
// HelloWorldApp.swift
// HelloWorld
//
// Created by Zheng on 6/22/20.
//
import SwiftUI
@main
import SwiftUI
struct ContentView: View {
@Binding var cameFromUrl: URL
var body: some View {
Text("Hello World! Came from url: \(cameFromUrl)")
}
}
import SwiftUI
struct ContentView: View {
@Binding var cameFromUrl: URL
@State var orientation = UIDevice.current.orientation
let orientationChanged = NotificationCenter.default.publisher(for: UIDevice.orientationDidChangeNotification)
.makeConnectable()
.autoconnect()
var body: some View {
struct ContentView: View {
var body: some View {
let symbol = Image(systemName: "books.vertical")
return Text("Here is a symbol \(symbol) embedded in a string!")
}
}
import SwiftUI
class AppDelegate: NSObject, UIApplicationDelegate {
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey : Any]? = nil) -> Bool {
if let shortcutItem = launchOptions?[UIApplication.LaunchOptionsKey.shortcutItem] as? UIApplicationShortcutItem {
if shortcutItem.type == "com.example.ExampleApp.exampleAction" {
print("Action Pressed!")
}
}
return true
import SwiftUI
class AppDelegate: NSObject, UIApplicationDelegate {
@Published var shortcutItemType: String?
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey : Any]? = nil) -> Bool {
if let shortcutItem = launchOptions?[.shortcutItem] as? UIApplicationShortcutItem {
if shortcutItem.type == "com.example.ExampleApp.exampleAction" {
shortcutItemType = shortcutItem.type
}
}
return true