Hi Apple MapKit team,
I am a new iOS developer and recently learned SwiftUI. This WWDC is my first one.
I noticed that although Apple is moving towards SwiftUI, the new features released for MapKit is still largely UIKit based. I am not very familiar with UIKit. I wondered that if MapKit team is going to mainly develop in MapKit space instead of the SwiftUI space.
Cheers,
Post
Replies
Boosts
Views
Activity
I am trying to add a confirm button to the top-right of a text editor screen by using the SwiftUI toolbar.
I realised that the text in the button cannot be centered as long as the ToolbarItem placement is configured to set the item to the top-right of the screen.
Is this a bug?
Here is a sample code:
import SwiftUI
struct TestView: View {
var body: some View {
NavigationView {
ZStack {
Color(.black)
.ignoresSafeArea()
Text("Hello World")
.foregroundColor(.white)
.toolbarRole(.editor)
.toolbar {
ToolbarItem(placement: .confirmationAction) {
Button(action: {print("confirm.")}) {
Text("confirm")
}
.background(.yellow)
.foregroundColor(.white)
.cornerRadius(20.0)
}
}
}
}
}
}
struct TestView_Previews: PreviewProvider {
static var previews: some View {
TestView()
}
}
code-block
I am developing an iOS app which uses swift-gRPC services.
Following the official xcode documentation, I imported the swift-gRPC package from its github repository.
When creating tests for the gRPC code in view model, I realised the moment I write @testable import ViewModel in a blank XCTest file, and build the unit test target, I get an error Missing required module "CNIOAtomics".
I checked the missing module is from the swift-gRPC package.
I also checked the Unit Tests are correctly pointing to the main app target.
It is very strange that this dependency problem does not happen in my main app target and all the code builds correctly.
Is this a bug? How do I fix it?
I am switchingt to the new WWDC 2023 SwiftUI map with user location and a few map annotations.
I find if I use .mapStyle(.imagery(elevation: .flat)) as the map style, the map will be loaded with a reasonably zoomed area.
However, if I use .mapStyle(.imagery(elevation: .realistic)) on the same map, the simulator will give me a view of the entire planet. I have to manually zoom in everytime to find the user location and annotations, which is not very convenient. This is the only map style configuration that does this.
I am not very sure if this is a feature or a inconsistency bug. If this is a feature, I cannot see the purpose of it.
I am trying to use the new scroll position API with the tabs. Following is my test code:
import SwiftUI
struct ContentView: View {
@State private var selectedTab = 0
@State private var position = ScrollPosition(edge: .top)
@State private var shouldScrollToBottom = false
var body: some View {
ScrollView {
VStack {
Picker("Tabs", selection: $selectedTab) {
Text("Collection 1").tag(0)
Text("Collection 2").tag(1)
Text("Collection 3").tag(2)
}
.pickerStyle(SegmentedPickerStyle())
.padding()
contentForSelectedTab()
}
}
.scrollPosition($position)
.onChange(of: selectedTab) { oldTab, newTab in
position.scrollTo(edge: .bottom)
}
}
@ViewBuilder
private func contentForSelectedTab() -> some View {
if selectedTab == 0 {
listItems
} else {
Text("unknown list")
}
}
var listItems: some View {
LazyVStack(spacing: 0) {
ForEach(1...100, id: \.self) { item in
VStack(spacing: 0) {
Text("Item \(item)")
.padding()
.frame(maxWidth: .infinity, alignment: .leading)
Divider()
}
}
}
}
}
#Preview {
ContentView()
}
As you can see, I want to achieve an effect that every time users switch to a different tab, the scroll view automatically scrolls to the bottom of the list of the tab.
However, this does not work very well somehow.
I also tried to introduce some delay on calling the position.scrollTo(edge: .bottom) but no luck.
If I use onAppear on the listItems and place the scrollTo function there, I can see it works only the first time. Any tab switching later will not scroll to the bottom.
What confused me is that if I add a print function in the onChange and onAppear, I can see the prints at the desired timing.
So my only explanation to this is that the scrollTo function cannot correctly recognise the sizes of scroll view when its content has changed.
Looks like a bug to me.
SwiftUI has no way to remove the bottom border line at the moment.
In the past, developers can use the UIKit to work around it. See stackoverflow 1 and stackoverflow 2.
Following sample code works if we use the old navigation view and title.
import SwiftUI
struct TestView: View {
init(){
let appearance = UINavigationBarAppearance()
appearance.shadowColor = .clear
UINavigationBar.appearance().standardAppearance = appearance
UINavigationBar.appearance().scrollEdgeAppearance = appearance
}
var body: some View {
NavigationView{
ScrollView{
ForEach(0 ..< 20){ num in
Text("Num - \(num)")
.padding()
}
}
.navigationTitle("Learn")
}
}
}
struct TestView_Previews: PreviewProvider {
static var previews: some View {
TestView()
}
}
However, as soon as we begin to use toolbar related modifiers, the trick will no longer work. I guess it is because the old navigation view uses UIKit behind the scene but toolbar does not.
import SwiftUI
struct ToolbarBorderTest: View {
init(){
let appearance = UINavigationBarAppearance()
appearance.shadowColor = .clear
UINavigationBar.appearance().standardAppearance = appearance
UINavigationBar.appearance().scrollEdgeAppearance = appearance
}
var body: some View {
NavigationView{
ScrollView{
ForEach(0 ..< 20){ num in
Text("Num - \(num)")
.padding()
}
}
.toolbar {
ToolbarItem(placement: .principal) {
Text("Toolbar title (Inline)")
.foregroundColor(.blue)
.font(.headline)
}
}
.toolbarTitleDisplayMode(.inline)
.toolbarBackground(Color.white, for: .navigationBar)
.toolbarColorScheme(.light, for: .navigationBar)
}
}
}
#Preview {
ToolbarBorderTest()
}
Is this something that SwiftUI will support in the future?
With the latest Xcode 16 RC version, the Live Preview on iPhone device problem has been fixed.
However, it still fails on the iPhone 16 pro preview emulator even for the simplest hello world view.
Apparently in Xcode 16, introducing any 3rdParty package impacts the preview build, even if the package is not referenced in the view.
I feel this is an incorrect behaviour.
Following are the steps to reproduce the problem:
Create a new iOS project in the latest Xcode 16 beta
Select ContentView in the project and verify the live preview is working and fast
Go the project’s Package Dependencies tab, add gRPC-Swift (https://github.com/grpc/grpc-swift.git) as a 3rdParty library of this project.
Go the main project target, select General tab.
Under Frameworks, Libraries, and Embedded Content section, add “GRPC”
Go back to ContentView and verify its live preview rendering now takes very long time and eventually failed.
Select Live Preview Diagnostic, verify error message: Failed to launch app ”PreviewBug.app” in reasonable time…
I have also created a feedback to Apple: FB15110765