Post

Replies

Boosts

Views

Activity

Reply to Playgrounds App on iPad not updating UI on @State change
I’m seeing the same issue on my iPad Pro 11” FB9121354: Swift Playgrounds on iPad does not update UI for @State variables The code works on Mac, not on iPad Playgrounds. import SwiftUI import PlaygroundSupport struct ContentView: View {     @State var isSelected: Bool = true     @State var useRedText = false     var body: some View {         VStack {             Text("SwiftUI on iPad")                 .font(.headline)                 .padding(20)                 .background(Color.red)                 .cornerRadius(10)             Text("Paul Rocks!")                 .font(.largeTitle)                 .padding(20)                 .background(isSelected ? Color.orange : Color.blue) //color())                 .cornerRadius(30)                 .onTapGesture {                      print("Paul Rocks")                     isSelected.toggle()                 }                          Button("Hello World") {                     // flip the Boolean between true and false                     self.useRedText.toggle()                       }                 .foregroundColor(useRedText ? .red : .blue)         }     }          func color() -> Color {         isSelected ? Color.orange : Color.blue     } } PlaygroundPage.current.setLiveView(ContentView())
May ’21
Reply to Swift Playgrounds 4 on Ipad
Yes, it's a lot more friendly to write Swift code on the new Swift Playgrounds 4 app. Errors are more straightforward and fixes are provided, which help beginners. The biggest challenge is that your screen space is limited, but it does force you to be more focused because you can only do one thing at a time (read documentation/stack overflow in Safari or write code in Swift Playgrounds). Using an external display will mirror the Swift Playground, which you can lower the font size to fit more code on screen. The new Swift app package is a quick way to prototype SwiftUI on narrow screen size, and also check how it adapts to larger screens. It makes it more fun to fast prototype a UI, and then you can tap it to see how it's working right on the device. Previously with Swift Playgrounds 3, I found myself running into corner cases trying to get my SwiftUI designs to work because there's no "app canvas", so you need to use a fixedSize() to fix some quirks. I had a lot more frustration prototyping UI on the old Swift Playgrounds 3, so the new version is 100% better for fast prototyping. Previous error messages were not verbose, or clear, so the new Swift Playgrounds 4 feels a lot better. You can import those Swift App Playgrounds on Xcode 13.2.1, but can't use them with the Mac Swift Playgrounds 4 (which may get fixed in an update?).
Dec ’21
Reply to Auto Layout Constraint Conflict in SwiftUI When Tapping TextField
I'm seeing a similar issue for a simple UI. I created feedback: FB14337260 "SwiftUI shows broken constraints error when tapping on TextField and SecureField in Xcode 16 and 15" Sample code struct LogInView: View { @Bindable var userValidator: UserValidator var body: some View { VStack(spacing: 16) { TextField(text: $userValidator.name) { Text("Name") } .autocorrectionDisabled() .textInputAutocapitalization(.words) TextField(text: $userValidator.email) { Text("Email") } .autocorrectionDisabled() .keyboardType(.emailAddress) SecureField(text: $userValidator.password) { Text("Password") } Button("Create Account") { print("ViewMode: userName: \(userValidator.name), email: \(userValidator.email), password: \(userValidator.password)") } .disabled(userValidator.isSubmitButtonDisabled) } } } Broken constraints: Unable to simultaneously satisfy constraints. Probably at least one of the constraints in the following list is one you don't want. Try this: (1) look at each constraint and try to figure out which you don't expect; (2) find the code that added the unwanted constraint or constraints and fix it. ( "<NSLayoutConstraint:0x60000217c000 'accessoryView.bottom' _UIRemoteKeyboardPlaceholderView:0x11c313250.bottom == _UIKBCompatInputView:0x10180eaf0.top (active)>", "<NSLayoutConstraint:0x600002139860 'assistantHeight' SystemInputAssistantView.height == 45 (active, names: SystemInputAssistantView:0x102528ba0 )>", "<NSLayoutConstraint:0x600002131630 'assistantView.bottom' SystemInputAssistantView.bottom == _UIKBCompatInputView:0x10180eaf0.top (active, names: SystemInputAssistantView:0x102528ba0 )>", "<NSLayoutConstraint:0x600002161720 'assistantView.top' V:[_UIRemoteKeyboardPlaceholderView:0x11c313250]-(0)-[SystemInputAssistantView] (active, names: SystemInputAssistantView:0x102528ba0 )>" ) Will attempt to recover by breaking constraint <NSLayoutConstraint:0x600002139860 'assistantHeight' SystemInputAssistantView.height == 45 (active, names: SystemInputAssistantView:0x102528ba0 )>
Jul ’24
Reply to SwiftData Fatal error: failed to find a currently active container
I'm refactoring my old iPhone app that uses Storyboards and AppDelegate to use SwiftData. When I launch the app, I hit the issue because my ModelContainer in my "quick sanity check integration" was being created after static variables containing "default recipes". I had to use the custom storyboard initializer to work around this issue, until I revamp the launch screen from a UIViewController backed by a storyboard to a SwiftUI view and the new app structure. This uses the instantiateViewController(identifier:creator:) variant of the Storyboard class so that I can inject the dependencies for SwiftData. https://developer.apple.com/documentation/uikit/uistoryboard/3213989-instantiateviewcontroller On start I have this logic in application(didFinishLaunchingWithOptions: let dataContainer = DataContainer(enableCloudKit: false, isStoredInMemoryOnly: false) let userSettings = UserSettings() let recipeHelper = RecipeHelper(userSettings: userSettings) let storyboard = UIStoryboard(name: "Main", bundle: nil) let measureVC = storyboard.instantiateViewController(identifier: "MeasureViewController") { coder in return MeasureViewController(coder: coder, userSettings: userSettings, recipeHelper: recipeHelper, dataContainer: dataContainer) } The offending code was a SwiftData static variable. static let harioV60_size1 = CoffeeRecipe( dateCreated: .now, dateModified: .now, dateBrewed: nil, title: "Hario V60", brewMethod: .harioV60_Size1, defaultRecipe: true, waterToCoffeeRatio: 16.2, coffeeWeight: 21, waterWeight: 340, bloomRatio: 2, bloomTime: 30, pourTime: 2.5 * 60, drainTime: 3 * 60 )
Aug ’24