I have a 2019 16 inch MacBook Pro running Catalina 10.15.5 with a strange problem. Just launching the Simulator can hard freeze the entire machine. The Simulator launches, the device shows a spinner that just keeps going and within a couple of seconds the machine beach-balls and the entire UI freezes with no possibility of option-command-escape to kill the Simulator.
I've looked in the logs afterward and I don't see any good clues. This problem is much more likely to occur with a simulated iPhone device (much more rare with a simulated iPad) and it doesn't happen every time I launch a simulated iPhone, just somewhere between 1/3 and 1/2 of the time.
Does anyone have any debugging or diagnostic ideas?
Thanks!
Post
Replies
Boosts
Views
Activity
Hi all - I am curious as to whether it is a good idea to make a separate Apple ID for distributing apps, etc. I am working on apps as a side gig and I'm trying to decide how to approach this. Are there any "gotchas" if you set up a second Apple ID just for your paid developer account? I assume you can set up your personal ID as a "developer" in App Store Connect for testing. How do you do two-factor for the "business" ID? (Do you need a separate device for that?) Do you use the same phone number for both accounts (I'm only planning on having one phone, haha)? Are there actually any meaningful advantages to having a separate Apple ID for this purpose?
Thanks for any thoughts on this!
Hello - I posted this question on StackOverflow and it didn't get any traction, so I thought I'd repost it here.
https://stackoverflow.com/questions/65370523/how-to-run-ui-tests-for-swiftui-app-lifecycle-apps-with-different-environments
I'm trying to figure out how to run UI tests for a SwiftUI app that is using the "SwiftUI App lifecycle" with preview data - in particular some data for CoreData, but it might be more general.
With the SwiftUI App lifecycle, we know have "main" entry points like:
@main
struct MyApp: App {
	let persistenceController = PersistenceController.shared
	
	var body: some Scene {
		WindowGroup {
			ContentView()
				.environment(\.managedObjectContext, persistenceController.container.viewContext)
		}
	}
}
wherePersistenceController is a struct that is managing the CoreData stuff (with this example created by Apple's template if you just make a new App and select "use CoreData"). I have written an extension with a bunch of preview data that can easily be loaded in PreviewProviders just by setting a different managedObjectContext with .environment() on the view code, etc. for use while developing the UI code.
Is there a way to make this preview data available inside a UI test? We usually have UI test code that looks sort of like:
class MyUITests: XCTestCase {
	
	var app: XCUIApplication!
	
	override func setUpWithError() throws {
		app = XCUIApplication()
		app.launch()
		continueAfterFailure = false
	}
	
	func testTabBarButtonsAndNavTitles() throws {
		let tabBar = app.tabBars["Tab Bar"]
		let loadAndGoTabBarButton = tabBar.buttons["Load and go"]
		loadAndGoTabBarButton.tap()
		XCTAssert(app.navigationBars["Load a thing and do it"].exists)
	}
Is there a way I can tell the XCUIApplication() to use a different managedObjectContext value in the environment call when it starts?
If not - it seems like the only way to test some of the SwiftUI elements would be to have the UI test function first "tap around" and enter a bunch of preview data, but this is really cumbersome. It would be better if the app could start up for testing with some saved data.
Apologies for not providing a fully runnable piece of code to illustrate this, but it would require a lot of infrastructure and boilerplate, etc. Thanks for any thoughts on this!
How does the Xcode Beta "work?" If I download and install, does it replace my Xcode 11? Does it replace the Simulator? Is it possible to "go back?" What happens when the final version is released through the App Store?
Thanks!
I asked this question on StackOverflow - https://stackoverflow.com/questions/63104172/swiftui-navigationview-with-presentationmode-creates-bug-in-multilevel-navigatio also, but my interactions there have lead me to think this might be a SwiftUI bug, so I thought I'd ask here too.
I have an iOS 13.5 SwiftUI (macOS 10.15.6) app that requires the user to navigate two levels deep in a NavigationView hierarchy to play a game. The game is timed. I'd like to use custom back buttons in both levels, but if I do, the timer in the second level breaks in a strange way. If I give up on custom back buttons in the first level and use the system back button everything works. Here is a minimum app that replicates the problem:
class SimpleTimerManager: ObservableObject {
	@Published var elapsedSeconds: Double = 0.0
	private(set) var timer = Timer()
	
	func start() {
		print("timer started")
		timer = Timer.scheduledTimer(withTimeInterval: 0.01, repeats: true) {_ in
			if (Int(self.elapsedSeconds * 100) % 100 == 0) { print ("\(self.elapsedSeconds)") }
			self.elapsedSeconds += 0.01
		}
	}
	
	func stop() {
		timer.invalidate()
		elapsedSeconds = 0.0
		print("timer stopped")
	}
}
struct ContentView: View {
	var body: some View {
		NavigationView {
			NavigationLink(destination: CountDownIntervalPassThroughView()) {
				Text("Start the timer!")
			}
		}
		.navigationViewStyle(StackNavigationViewStyle())
	}
}
struct CountDownIntervalPassThroughView: View {
	@Environment(\.presentationMode) var mode: Binding<PresentationMode>
	var body: some View {
		VStack {
			NavigationLink(destination: CountDownIntervalView()) {
				Text("One more click...")
			}
			Button(action: {
				self.mode.wrappedValue.dismiss()
				print("Going back from CountDownIntervalPassThroughView")
			}) {
				Text("Go back!")
			}
		}
		.navigationBarBackButtonHidden(true)
	}
}
struct CountDownIntervalView: View {
	@ObservedObject var timerManager = SimpleTimerManager()
	@Environment(\.presentationMode) var mode: Binding<PresentationMode>
	var interval: Double { 10.0 - self.timerManager.elapsedSeconds }
		
	var body: some View {
		VStack {
			Text("Time remaining: \(String(format: "%.2f", interval))")
				.onReceive(timerManager.$elapsedSeconds) { _ in
					print("\(self.interval)")
					if self.interval <= 0 {
						print("timer auto stop")
						self.timerManager.stop()
						self.mode.wrappedValue.dismiss()
					}
			}
			Button(action: {
				print("timer manual stop")
				self.timerManager.stop()
				self.mode.wrappedValue.dismiss()
			}) {
				Text("Quit early!")
			}
		}
		.onAppear(perform: {
			self.timerManager.start()
		})
		.navigationBarBackButtonHidden(true)
	}
}
Poking at this some more, I see two strange behaviors. If I don't use a pass through, everything works for manual clicking. But if I let the timer expire and create a pop back, when I try to restart it, the view immediately pops, but the timer keeps running. If I do use a pass through, the timer starts when I navigate two levels down, but the view doesn't update. I wonder if this is a bug in how SwiftUI is handling the onAppear and mode.dismiss methods.
Hello,Running: 10.15.4 with Xcode 11.5 on MacBook Pro (16-inch, 2019)Even extremely simple "Hello world" SwiftUI apps occasionally freeze the entire machine while generating canvas previews with SwiftUI. Searching around on the internet has lead me to disable "Paralellize Builds" in the Scheme and this helps, but does not eliminate the problem. Also, similar full system freezes have occured when running the app without the appropriate simulator device already up and running, but this is less reproducible.Has anyone seen similar problems? I basically can't use previews with SwiftUI with this problem.Thanks for any thoughts.