An iPhone Simulator "Wrapper" for SwiftUI Apps on macOS

Overview

SwiftUIPhone

Version License Platform Platform

Run a SwiftUI app (or any SwiftUI view) in an iPhone Simulator "wrapper", directly on macOS!

To be clear, this is not an iPhone Simulator (nor any sort of emulation thereof). Rather, for those of us who took care to write our iOS apps without leaning on any platform-specific libraries (e.g. UIKit), you can think of this as your reward: a way to build that app for macOS and run it at light speed (compared to an actual iPhone Simulator, that is) directly on any Mac, no Xcode or dev tools required.

Compatibility

SwiftUIPhone is compatible with applications targeting macOS 11+.

Installation

Swift Package Manager

SwiftUIPhone is available as a Swift Package. To use it in your project, add it to your project's Swift Packages:

https://github.com/JUSTINMKAUFMAN/SwiftUIPhone.git

Usage

SwiftUIPhone can be used as follows:

import SwiftUI
import SwiftUIPhone

@main
struct SwiftUIPhoneDemoApp: App {
    @SwiftUI.Environment(\.colorScheme) var colorScheme
    let appName: String = "SwiftUIPhone Demo"
    
    @SceneBuilder var body: some Scene {
        WindowGroup {
            VStack(alignment: .center) {
                Button("Launch SwiftUIPhone") { launch() }
            }.padding()
        }
    }
    
    func launch() {
        let window = NSWindow(
            contentRect: NSRect(x: 0.0, y: 0.0, width: 400.0, height: 809.0),
            styleMask: [.titled, .closable, .miniaturizable],
            backing: .buffered,
            defer: false
        )
        
        let view = SwiftUIPhone(
            rootView: AnyView(
                VStack(alignment: .center) {
                    Text("This is the root view of my app")
                }
                .background(colorScheme == .dark ? Color.black : Color.white)
            )
        )
        
        window.titlebarAppearsTransparent = false
        window.hasShadow = false
        window.isOpaque = false
        window.backgroundColor = NSColor.clear
        window.center()
        window.setFrameAutosaveName("\(appName).MainWindow")
        window.title = appName
        window.isReleasedWhenClosed = false
        window.contentView = NSHostingView(rootView: view)
        window.makeKeyAndOrderFront(nil)
    }
}

Author

Justin Kaufman, [email protected]

License

SwiftUIPhone is available under the MIT license. See the LICENSE file for more info.

You might also like...
iPhone App for identifying resistors.
iPhone App for identifying resistors.

IDResistors Download on the App Store! IDResistors is a simple app for identifing the values smd and through hole resistors. It's developed using Swif

iOS Trakt Client - Keep track of your favorite TV shows and movies on your iPhone. (Under development)

CouchTracker Keep track of your favorite movies and tv shows on your iPhone Setup for development You will need Xcode 11.2.1 Swift 5.1.2 Run the follo

Xkcd iPhone app

This is the repo behind http://bit.ly/xkcdapp, an iOS xkcd reader. The code started as a learning project back on iOS 2.0 and has been through a lot s

Reading List is an iOS app for iPhone and iPad which helps users track and catalog the books they read
Reading List is an iOS app for iPhone and iPad which helps users track and catalog the books they read

Reading List Reading List is an iOS app for iPhone and iPad which helps users track and catalog the books they read. Reading List v2 As of version 2.0

OctoPod is a free open source iPhone/iPad app for OctoPrint
OctoPod is a free open source iPhone/iPad app for OctoPrint

OctoPod OctoPod is a free open source iPhone/iPad app for OctoPrint. Build Instructions Download Xcode You will need to install Swift 5.0 and Xcode 11

Swift iPhone and iPad Client for Polls API, using Hyperdrive API client
Swift iPhone and iPad Client for Polls API, using Hyperdrive API client

Polls Client This is a Swift iPhone and iPad client for the Polls API - a simple application allowing users to view polls and vote in them. Polls is a

Aquarium Life is an iPhone app for management of Home Aquariums
Aquarium Life is an iPhone app for management of Home Aquariums

Aquarium life Aquarium Life is an iPhone app for management of Home Aquariums. The app was launched on Apple App Store in 2021 but removed after my me

SafeTimer es una app para iPhone y Apple Watch que te ayuda a controlar el tiempo que has usado una mascarilla.

SafeTimer es una app para iPhone y Apple Watch que te ayuda a controlar el tiempo que has usado una mascarilla.

Comments
  • Add generic initializer to `SwiftUIPhone`

    Add generic initializer to `SwiftUIPhone`

    I modified the initializer to allow a generic view argument, which automatically wraps the content with AnyView inside the initializer, slightly simplifying initializing a new SwiftUIView. Since supplying a view conforming to AnyView is still an acceptable argument, this is not a source-breaking change. I also added a second initializer that initializes the view to the default argument you supplied with the original initializer.

    Thank you, really enjoy what you've done here!

    opened by christopherweems 0
Releases(1.0.2)
Owner
Justin Kaufman
Principal Engineer @ 98point6
Justin Kaufman
Simulate any device and settings on one simulator or device.

SwiftUI-Simulator Enables the following settings without settings or restarting the simulator or real device. Any device screen Light/Dark mode Locale

Yusuke Hosonuma 70 Dec 19, 2022
A SwiftUI dynamic property wrapper for fetching media from your photo library. (iOS, tvOS, macOS)

Media Also available as a part of my SwiftUI+ Collection – just add it to Xcode 13+ A package for simplifying the user of the camera and the user's ph

SwiftUI+ 20 Nov 16, 2022
A simple star rating library for SwiftUI apps on macOS and iOS

DLDRating A simple star rating library for SwiftUI apps on macOS and iOS. Features Installation Usage Styling Credits DLDRating was made by Dionne Lie

null 1 Mar 6, 2022
Client library for making in-app purchases on iOS and macOS Automattic apps

MobilePayKit Client library for making in-app purchases on iOS and macOS Automattic apps Introduction MobilePayKit is a client library for making in-a

Automattic 8 Oct 20, 2022
macOS application written in SwiftUI that downloads installer pkgs for the Install macOS Big Sur application.

Download Full Installer This is a Swift UI implementation of my fetch-installer-pkg script. It will list the full macOS Big Sur (and later) installer

Armin Briegel 654 Dec 31, 2022
A SwiftUI wrapper around the `Add to Siri` button used to donate INIntents to the system.

AddToSiri A SwiftUI wrapper around the Add to Siri button used to donate INIntents to the system. Originally created by Reddit user u/dippnerd (Github

Florian Schweizer 5 Nov 23, 2022
A new property wrapper for SwiftUI ObservableObject.

SharedObject ?? @SharedObject is an alternative to @StateObject, @ObservedObject, @EnvironmentObject to handle ObservableObject. If you need to have m

Lorenzo Fiamingo 51 Dec 8, 2022
A simple health assistant app built in Swift5 for iPhone 📱

Health-Habit-Assistant A simple habit forming app build for iPhone in Swift 5 (iOS 11+) (This Project is designed to be used in China 4C Computer Comp

Masayuki Inamori 381 Dec 27, 2022
iCome Out is an open source project of an unofficial Pornub app for iPhone and iPad

iCome Out is an open source project of an unofficial Pornub app for iPhone and iPad, written in Swift with some cool features Getting Started Prerequi

Anon 3 Dec 1, 2022
iCloud Drive is Apple's essential connection between all your devices, Mac, iPhone, iPad, even your Windows PC.

iCloud Drive is Apple's essential connection between all your devices, Mac, iPhone, iPad, even your Windows PC.While the cost of storage seems expensive in comparison to other online storage services, its advantage is that it works natively across all your devices.

MindInventory 12 Jul 29, 2022