I have an iOS 13 app that I’m hoping to release soon that is written entirely in SwiftUI. If I was starting from scratch today, I’d obviously use the new multi platform template which looks awesome.... But since I’m not starting from scratch, what are the recommendations/best practices for existing apps? Is there a path for migrating existing apps to take advantage of the new app structure (below) when moving to iOS 14? @main struct HelloWorld: App { var body: some Scene { WindowGroup { Text(“Hello, world!”).padding() } } }
Search results for
[tags:wwdc20-10163]
43 results found
Selecting any option will automatically load the page
Post
Replies
Boosts
Views
Activity
Using XCode 12 Beta, setting the background on the new SwiftUI TextEditor() view doesn't seem to be working. Is this by design? TextEditor(text: $text) .background(Color.red) .foregroundColor(Color.black)
I would love my SwiftUI views to support the new modifiers in iOS 14 (e.g. .navigationTitle), but still run on iOS 13 (e.g. using deprecated .navigationBarTitle). What is the best way to add conditional #if available code for view modifiers? The only way I can find to do it is by extracting every subview, and putting #if available blocks around every view declaration — this seems very tedious, as I am redefining each view twice. E.g. struct SettingsView: View { var body: some View { NavigationView { if #available(iOS 14.0, *) { SettingsContentView() .navigationTitle(Settings) } else { SettingsContentView() .navigationBarTitle(Settings) } } } } Is there a better way to just add conditional code only around the modifiers? Thanks in advance.
Hi - are you able to set first responder now in SwiftUI 2? Thanks! Nick
There is a lot of great updates this year to SwiftUI (especially the new App / Scene protocols enabling full app development in 100% SwiftUI 😍) but there is one area I had really hoped would get some much needed improvements, and that is better Gesture support for multi-touch. At the moment there is no way to implement the very common interaction of pinch-zooming a photo/view while also panning it at the same time. MagnificationGesture supports pinching, but it’s Value is just a single float, while DragGesture supports panning but doesn’t have the needed fidelity it its Value to give you information about multiple fingers. Trying to combine these gestures in a SimultaneousGesture doesn’t seem to work either as one or the other fails (one requires two fingers and the other a single finger). Implementing with the available API results in a poor UX as first a user must pinch the photo to their preferred size (with a locked center anchor), then switch to a single finger to pan the image to the desired point of i
Here's an example of a NavigationView that uses the new 3-column layout: struct ContentView: View { var body: some View { NavigationView { PrimaryColumn() SupplementaryColumn() SecondaryColumn() t } } } When the app starts on the iPad in the landscape mode, the supplementary and secondary columns are visible and the primary column can be opened with the Back button. I'd like for the primary column to be visible immediately, because when the app starts the secondary column doesn't have any content. I could include some placeholder text, but the user would still have to take an extra step to expand the primary column, which is annoying. With UIKit, I could use UISplitViewController with tripleColumn style, and expand the primary column manually by setting its display mode to twoBesideSecondary, for example. Is this possible to achieve in SwiftUI?
Has anyone been able to get the new TextEditor view to work in SwiftUI form? I've tried different things and it seems like the row isn't aware of the size of the TextEditor as you type and it grows. I'd be more than happy to file a radar with example code if needed.
I use lazyVStack lazyGrid and ScrollView to build a Symbol Picker. But you know, there are more than 1300 symbols in Symbol Library. So I use LazyVStack and LazyVGrid. Here is my code: ScrollView { LazyVStack { VStack(alignment: .leading) { CategoryNameIndicator() LazyVGrid(columns: columns) { ForEach(symbolGroup.symbolsName, id: .self) { symbol in SymbolPickerCell(symbol: symbol, canBeSelected: true, selectedSymbol: $symbolLibrary.selectedSymbol) .padding(15) .padding(.bottom, 5) } } .compositingGroup() // -> I don't know if this will improve the performance. But I used. } } } My problem is: When I scroll very fast. CPU usage will goes to 100% and the performance is reeeally bad. Scrolling Animation is caton. Do you have any suggestions?
In the AppKit lifecycle it was possible to open new windows by calling showWindow(_ sender: Any?) on an NSWindowController instance, whether it was initialized via a storyboard or via code alone. I see that on macOS in the new SwiftUI Lifecycle you can create a new window by default using ⌘N, but it's a new copy of the existing window. Can we declare a completely unique scene and open it in a new window? I saw that it was possible to declare custom scenes - https://developer.apple.com/documentation/swiftui/scene, but how do we invoke them if they aren't the default scene at startup? Thanks!
If a user uses the Document App template in Xcode to create a SwiftUI app, macOS starts them off with a new document. This is good. I can work with that to present onboarding UI within a new document. However, with that same app running on iOS, the user is instead greeted by the stock document view controller to create or pick a document. This is not helpful in that I don't have a way to present onboarding information. I did notice that if you add a WindowGroup to the Scene, the app will display that window group. But then I don't know how to get the user to the picker UI of the DocumentGroup. Has anyone figured out how to do things like present onboarding on top of this DocumentGroup-based app?
Is it possible to use CoreData with the newly announces SwiftUI App Protocol for 100% SwiftUI apps. If I need to create an app with persistant storage, is there a way to achieve this with the new protocol? I like the idea of having my app fully compatable across all systems. Thanks.
Currently using Attributed String in Foundation we could have several text stylings in a long string by using something like this: attributedSentence.setAttributes(redTextAttributes, range: NSRange(location: 0, length: 3)) How do we achieve this in SwiftUI? Yes we can concat string like this Text(Hi there).foregroundColor(.red) + Text(how are you?).foregroundColor(.blue) But this static approach is not possible if we apply localisation in our app. Each language have different grammar which leads to different word structure. How could we have a consistent Hi there in red color regardless of it's language?
The keyboard shortcut does not work on the iPadOS 14 simulator using following the code. @main struct DemoApp: App { var body: some Scene { WindowGroup { Text(Demo Keyboard Shotcuts) } .commands { CommandGroup(before: .sidebar) { Button(Test Keyboard, action: { print(keyboard shortcut - command + k) }) .keyboardShortcut([) } } } } Would you please help us to know what's the problem? From the WWDC session What's new in SwiftUI, the keyboard shortcut should work on iPad. Thank you.
If target is set to iOS13 - following error appears 'main()' is only available in iOS 14.0 or newer @available(iOS 14.0, *) @main struct MainApp: App { var body: some Scene { WindowGroup { Text(Hello, world!).padding() } } } What are the options and best practises to start using new SwiftUI concepts, views and features while maintaining backward compatibility with iOS13 ?
Hi, All the Lists I was developed in my app that was using Sections appears totally broken after update my project to Xcode 12 and macOS Big Sur for macOS apps. struct ContentView: View { var body: some View { List { Section(header: Text(Important tasks)) { Text(Helloworld1) Text(Helloworld2) } Section(header: Text(Other tasks)) { Text(Helloworld3) Text(Helloworld4) } } } } This code works fine on iOS projects, but not in macOS projects. In macOS the section contents doesn't appear neither the preview nor app execution. Could be a bug or I'm missing something building sectioned lists? Thanks in advance.