Skip to content

Commit

Permalink
Updated for Xcode 8
Browse files Browse the repository at this point in the history
Most of these changes came from
stepanhruda#30 with
further additions. Unfortunately those were all done in a working copy
without applying to git, so this commit doesn't reflect proper
attribution to the author(s).
  • Loading branch information
dpogue committed Oct 26, 2017
1 parent 160e753 commit f4ab061
Show file tree
Hide file tree
Showing 18 changed files with 734 additions and 132 deletions.
9 changes: 4 additions & 5 deletions Formula/ios-simulator-app-installer.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
class IosSimulatorAppInstaller < Formula
homepage "https://github.com/stepanhruda/ios-simulator-app-installer"
url "https://github.com/stepanhruda/ios-simulator-app-installer.git",
:revision => "def460846f6065e8d0bbdf8ad9bd5cd01ca25e0c"
version "0.2.1"
homepage "https://github.com/tcurdt/ios-simulator-app-installer"
url "https://github.com/tcurdt/ios-simulator-app-installer.git", :tag => "0.3.0"
version "0.3.0"

depends_on :xcode => "7"
depends_on :xcode => "8"
depends_on :macos => :yosemite

def install
Expand Down
10 changes: 5 additions & 5 deletions app-package-launcher/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import Cocoa
@NSApplicationMain
class AppDelegate: NSObject, NSApplicationDelegate {

func applicationDidFinishLaunching(notification: NSNotification) {
func applicationDidFinishLaunching(_ notification: Notification) {
do {
let packagedApp = try PackagedApp(bundleName: "Packaged")

Expand Down Expand Up @@ -37,7 +37,7 @@ class AppDelegate: NSObject, NSApplicationDelegate {

var simulatorSelectionController: SimulatorSelectionWindowController?

func letUserSelectSimulatorFrom(simulators: [Simulator], completion: Simulator -> Void) {
func letUserSelectSimulatorFrom(_ simulators: [Simulator], completion: @escaping (Simulator) -> Void) {
simulatorSelectionController = SimulatorSelectionWindowController.controller(simulators) {
[unowned self] selectedSimulator in
completion(selectedSimulator)
Expand All @@ -46,12 +46,12 @@ class AppDelegate: NSObject, NSApplicationDelegate {
simulatorSelectionController?.showWindow(nil)
}

func terminateWithError(error: NSError) {
func terminateWithError(_ error: NSError) {
NSAlert(error: error).runModal()
NSApplication.sharedApplication().terminate(nil)
NSApplication.shared().terminate(nil)
}

func noSuitableDeviceFoundForStringError(targetDevice: String) -> NSError {
func noSuitableDeviceFoundForStringError(_ targetDevice: String) -> NSError {
return NSError(
domain: "com.stepanhruda.ios-simulator-app-installer",
code: 2,
Expand Down
18 changes: 9 additions & 9 deletions app-package-launcher/Installer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,26 @@ import Foundation

class Installer {

static func installAndRunApp(packagedApp: PackagedApp, simulator: Simulator) {
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0)) {
static func installAndRunApp(_ packagedApp: PackagedApp, simulator: Simulator) {
DispatchQueue.global().async {
shutDownCurrentSimulatorSessions()

system("xcrun instruments -w \"\(simulator.identifierString)\"")
_ = Shell.run(command: "xcrun instruments -w \"\(simulator.identifierString)\"")

if Parameters.shouldUninstallFirst() {
system("xcrun simctl uninstall booted \(packagedApp.bundleIdentifier)")
_ = Shell.run(command: "xcrun simctl uninstall booted \(packagedApp.bundleIdentifier)")
}

system("xcrun simctl install booted \"\(packagedApp.bundlePath)\"")
system("xcrun simctl launch booted \(packagedApp.bundleIdentifier)")
_ = Shell.run(command: "xcrun simctl install booted \"\(packagedApp.bundlePath)\"")
_ = Shell.run(command: "xcrun simctl launch booted \(packagedApp.bundleIdentifier)")

NSApplication.sharedApplication().terminate(nil)
NSApplication.shared().terminate(nil)
}
}

static func shutDownCurrentSimulatorSessions() {
system("killall \"iOS Simulator\"")
system("xcrun simctl shutdown booted")
_ = Shell.run(command: "killall \"Simulator\"")
_ = Shell.run(command: "xcrun simctl shutdown booted")
}

}
32 changes: 16 additions & 16 deletions app-package-launcher/PackagedApp.swift
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import Foundation

enum PackagedAppError: ErrorType {
case BundleNotFound
case InfoPlistNotFound
case BundleIdentifierNotFound
enum PackagedAppError: Error {
case bundleNotFound
case infoPlistNotFound
case bundleIdentifierNotFound

var asNSError: NSError {
let description: String
switch self {
case .BundleNotFound: description = "App bundle couldn't be found, this installer was packaged incorrectly."
case .InfoPlistNotFound: description = "Info.plist not found in packaged app, this installer was packaged incorrectly."
case .BundleIdentifierNotFound: description = "Bundle identifier not found in packaged app's Info.plist, this installer was packaged incorrectly."
case .bundleNotFound: description = "App bundle couldn't be found, this installer was packaged incorrectly."
case .infoPlistNotFound: description = "Info.plist not found in packaged app, this installer was packaged incorrectly."
case .bundleIdentifierNotFound: description = "Bundle identifier not found in packaged app's Info.plist, this installer was packaged incorrectly."
}

return NSError(
Expand All @@ -26,24 +26,24 @@ struct PackagedApp {
let bundleIdentifier: String

init(bundleName: String) throws {
guard let bundlePath = PackagedApp.pathForFileNamed(bundleName) else { throw PackagedAppError.BundleNotFound }
guard let infoPlist = PackagedApp.infoPlistInBundleWithPath(bundlePath) else { throw PackagedAppError.InfoPlistNotFound }
guard let bundleIdentifier = PackagedApp.bundleIdentifierFromInfoPlist(infoPlist) else { throw PackagedAppError.BundleIdentifierNotFound }
guard let bundlePath = PackagedApp.pathForFileNamed(bundleName) else { throw PackagedAppError.bundleNotFound }
guard let infoPlist = PackagedApp.infoPlistInBundleWithPath(bundlePath) else { throw PackagedAppError.infoPlistNotFound }
guard let bundleIdentifier = PackagedApp.bundleIdentifierFromInfoPlist(infoPlist) else { throw PackagedAppError.bundleIdentifierNotFound }

self.bundlePath = bundlePath
self.bundleName = bundleName
self.bundleIdentifier = bundleIdentifier
}

static func pathForFileNamed(filename: String) -> String? {
return NSBundle.mainBundle().pathForResource(filename, ofType: "app")
static func pathForFileNamed(_ filename: String) -> String? {
return Bundle.main.path(forResource: filename, ofType: "app")
}

static func infoPlistInBundleWithPath(bundlePath: String) -> NSDictionary? {
return NSDictionary(contentsOfFile: bundlePath.stringByAppendingString("/Info.plist"))
static func infoPlistInBundleWithPath(_ bundlePath: String) -> NSDictionary? {
return NSDictionary(contentsOfFile: bundlePath + "/Info.plist")
}

static func bundleIdentifierFromInfoPlist(infoPlist: NSDictionary) -> String? {
return infoPlist.objectForKey(kCFBundleIdentifierKey) as? String
static func bundleIdentifierFromInfoPlist(_ infoPlist: NSDictionary) -> String? {
return infoPlist.object(forKey: kCFBundleIdentifierKey) as? String
}
}
Loading

0 comments on commit f4ab061

Please sign in to comment.