This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // A way to open main app from share extension. Verified on iOS 15-26 and macOS 15 | |
| private func openApp() { | |
| // For this to work the app needs to have an url scheme: https://developer.apple.com/documentation/xcode/defining-a-custom-url-scheme-for-your-app | |
| // Potential alternative is also to use universal links: https://developer.apple.com/documentation/xcode/allowing-apps-and-websites-to-link-to-your-content | |
| let url = URL(string: "myApp://")! | |
| #if os(iOS) | |
| if #available(iOS 18.0, *), openURL(url) { | |
| return | |
| } | |
| OpenURLAction.system(url) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import SwiftUI | |
| struct ContentView: View { | |
| var body: some View { | |
| NavigationStack { | |
| TabView { | |
| List { | |
| Text("Content") | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import SwiftUI | |
| struct ContentView: View { | |
| var body: some View { | |
| VStack { | |
| ChildView() | |
| ChildView() | |
| } | |
| .padding() | |
| .overlayPreferenceValue(ViewPreferenceKey.self) { $0 } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import SwiftUI | |
| struct ContentView: View { | |
| @State private var showSheet1 = false | |
| @State private var showSheet2 = false | |
| @State private var showSheet3 = false | |
| var body: some View { | |
| VStack { | |
| Button("State object created directly") { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import SwiftUI | |
| struct ContentView: View { | |
| @State private var id = UUID() | |
| @State private var isOn = false | |
| var body: some View { | |
| VStack { | |
| // Changing this toggle will cause child views to update colors | |
| Toggle("Toggle", isOn: $isOn) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import SwiftUI | |
| final class SwiftUIView<Content: View>: UIView { | |
| private var heightConstraint: NSLayoutConstraint? | |
| init(content: Content, onSizeChanged: @escaping (CGSize) -> Void) { | |
| super.init(frame: .zero) | |
| let sizeReadingContent = content.readSize { [weak self] newSize in |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import SwiftUI | |
| public class TapPanGestureRecognizer: UIGestureRecognizer { | |
| private var waitingForSecondTap: Task<Void, Never>? | |
| public private(set) var initialLocation: CGPoint = .zero { | |
| didSet { | |
| currentLocation = initialLocation | |
| } | |
| } |