Background
I have a SwiftUI app that uses OSLog and the new Logger framework. In my SwiftUI views, I would like to use something like Self._logChanges() to help debug issues.
After some trial and error, I can see the messages appear in the System console log for the app I am debugging using the com.apple.SwiftUI subsystem.
Problem
I'd like to see those same messages directly in Xcode's console window so I can filter them as needed. How do I do that?
Thanks! -Patrick
Explore the various UI frameworks available for building app interfaces. Discuss the use cases for different frameworks, share best practices, and get help with specific framework-related questions.
Selecting any option will automatically load the page
Post
Replies
Boosts
Views
Created
Using a button that is placed in the bottom ornament to set focus on a text field will not display the keyboard properly while a button embedded in the view will behave as expected.
To demonstrate the issue, simply run the attached project on Vision Pro with visionOS 1.1 and tap the Toggle 2 button in the bottom ornament. You’ll see that the field does have focus but the keyboard is now visible.
Run the same test with Toggle 1 and the field will get focus and the keyboard will show as expected.
import SwiftUI
import RealityKit
import RealityKitContent
struct ContentView: View {
@State private var text = ""
@State private var showKeyboard = false
@FocusState private var focusedField: FocusField?
private enum FocusField: Hashable {
case username
case password
}
var body: some View {
VStack {
TextField("Test", text: $text)
.focused($focusedField, equals: .username)
Text("Entered Text: \(text)")
.padding()
Button("Toggle 1") { // This button will work and show the keyboard
if focusedField != nil {
focusedField = nil
} else {
focusedField = .username
}
}
Spacer()
}
.padding()
.toolbar {
ToolbarItem(placement: .bottomOrnament) {
Button("Toggle 2") { // This button will set focus properly but not show the keyboard
if focusedField != nil {
focusedField = nil
} else {
focusedField = .username
}
}
}
}
}
}
Is there a way to work around this?
FB13641609
Our app was just rejected by Apple because they say the subscription management sheet never loads. It just spins indefinitely.
We're using StoreKit's manageSubscriptionsSheet view modifier to present the sheet, and it's always worked for us when testing in SandBox.
Has anyone else had this problem?
Given that it's Apple's own code that got us rejected, what's our path forward?
Is there any way to get dock size?
I got Dock Window using CGWindowListCopyWindowInfo.
But I found its frame covers my entire screen.
Same promble as Notification Center.
Any way to get their size?
We have developed an iOS app using three fonts: PingFangSC Regular, PingFangSC Medium, and DINAlternate-Bold. Do all three fonts require commercial authorization to be used in the app?
Hi,
I have few questions regarding the widgets.
I would like to know whether widget and app extensions are same ? This link(https://developer.apple.com/app-extensions/) says widget is type of app extension but I am not quite sure as few link in web says they are different. so need to confirm here :)
Can a widget share same bundle id as the main app ? so basically can we use the same provisioning profile as the main app?
If we use the same bundle id and provisioning profile, will there be any issue during the app store submission process.?
I Implement a 'SubscriptionStoreView' using 'groupID' into a project (iOS is targeting 17.2 and macOS is targeting 14.1).Build/run the application locally (both production and development environments will work fine), however once the application is live on the AppStore in AppStoreConnect, SubscriptionStoreView no longer shows products and only shows 'Subscription Unavailable' and 'The subscription is unavailable in the current storefront.' - this message is shown live in production for both iOS and macOS targets. There is no log messages shown in the Console that indicate anything going wrong with StoreKit 2, but I haven't made any changes to my code and noticed this first start appearing about 5 days ago.
I expect the subscription store to be visible to all users and for my products to display. My application is live on both the iOS and macOS AppStores, it passed App Review and I have users who have previously been able to subscribe and use my application, I have not pushed any new changes, so something has changed in StoreKit2 which is causing unexpected behaviour and for this error message to display. As 'SubscriptionStoreView' is a view provided by Apple, I'm really not sure on the pathway forward other than going back to StoreKit1 which I really don't want to do.
Is there any further error information that can be provided on what might be causing this and how I can fix it? (I have created a feedback ticket FB13658521)
Hi! We added Spanish to the String Catalog. Turned out there are a lot of changes we should make to already localized text. How can we temporarily turn off / disable this language to fix all issues and then turn on Spanish support again?
Thank you!
Hi there,
I have a TabView in page style. Inside that TabView I have a number of views, each view is populated with a model object from an array. The array is iterated to provide the chart data.
Here is the code:
TabView(selection: $displayedChartIndex) {
ForEach((0..<data.count), id: \.self) { index in
ZStack {
AccuracyLineView(graphData: tabSelectorModel.lineChartModels[index])
.padding(5)
}
.tag((index))
}
}
.tabViewStyle(.page)
.indexViewStyle(.page(backgroundDisplayMode: .always))
I am seeing odd behaviour, as I swipe left and right, occasionally the chart area shows the chart from another page in the TabView. I know the correct view is being shown as there are text elements.
See the screenshot below. The screen on the right is running iOS 17.2 and this works correctly. The screen on the left is running iOS 17.4 and the date at the top is correct which tells me that the data object is correct. However the graph is showing a chart from a different page. When I click on the chart on the left (I have interaction enabled) then it immediately draws the correct chart. If I disable the interaction then I still get the behaviour albeit the chart never corrects itself because there is no interaction!
I can reproduce this in the 17.4 simulator and it is happening in my live app on iOS17.4. This has only started happening since iOS 17.4 dropped and works perfectly in iOS 17.2 simulator and I didn't notice it in the live app when I was running 17.3.
Is this a bug and/or is there a workaround?
For info this is the chart view code, it is not doing anything clever:
struct AccuracyLineView: View {
@State private var selectedIndex: Int?
let graphData: LineChartModel
func calcHourMarkers (maxTime: Int) -> [Int] {
let secondsInDay = 86400 // 60 * 60 * 24
var marks: [Int] = []
var counter = 0
while counter <= maxTime {
if (counter > 0) {
marks.append(counter)
}
counter += secondsInDay
}
return marks
}
var selectedGraphMark: GraphMark? {
var returnMark: GraphMark? = nil
var prevPoint = graphData.points.first
for point in graphData.points {
if let prevPoint {
if let selectedIndex, let lastPoint = graphData.points.last, ((point.interval + prevPoint.interval) / 2 > selectedIndex || point == lastPoint) {
if point == graphData.points.last {
if selectedIndex > (point.interval + prevPoint.interval) / 2 {
returnMark = point
} else {
returnMark = prevPoint
}
} else {
returnMark = prevPoint
break
}
}
}
prevPoint = point
}
return returnMark
}
var body: some View {
let lineColour:Color = Color(AppTheme.globalAccentColour)
VStack {
HStack {
Image(systemName: "clock")
Text(graphData.getStartDate() + " - " + graphData.getEndDate()) // 19-29 Sept
.font(.caption)
.fontWeight(.light)
Spacer()
}
Spacer()
Chart {
// Lines
ForEach(graphData.points) { item in
LineMark(
x: .value("Interval", item.interval),
y: .value("Offset", item.timeOffset),
series: .value("A", "A")
)
.interpolationMethod(.catmullRom)
.foregroundStyle(lineColour)
.symbol {
Circle()
.stroke(Color(Color(UIColor.secondarySystemGroupedBackground)), lineWidth: 4)
.fill(AppTheme.globalAccentColour)
.frame(width: 10)
}
}
ForEach(graphData.trend) { item in
LineMark (
x: .value("Interval", item.interval),
y: .value("Offset", item.timeOffset)
)
.foregroundStyle(Color(UIColor.systemGray2))
}
if let selectedGraphMark {
RuleMark(x: .value("Offset", selectedGraphMark.interval))
.foregroundStyle(Color(UIColor.systemGray4))
}
}
.chartXSelection(value: $selectedIndex)
.chartXScale(domain: [0, graphData.getMaxTime()])
}
}
}
The scroll position is not updated when orientation changes in a ScrollView with .scrollTargetBehavior(.viewAligned) and .scrollPosition().
import SwiftUI
struct ContentView: View {
let colors: [Color] = [.red, .yellow, .cyan, .blue, .teal, .brown, .orange, .indigo]
@State private var selected: Int? = 0
var body: some View {
ScrollView(.horizontal) {
HStack(spacing: 0) {
ForEach(0..<colors.count, id: \.self) { index in
Rectangle()
.fill(colors[index])
.containerRelativeFrame(.horizontal)
.overlay {
Text(colors[index].description)
}
}
}
.scrollTargetLayout()
}
.scrollPosition(id: $selected)
.scrollTargetBehavior(.viewAligned)
}
}
#Preview {
ContentView()
}
@main
struct ViewAlignedScrollBugApp: App {
var body: some Scene {
WindowGroup {
ContentView()
}
}
}
Tested on Xcode 15.3 (15E204a), iOS 17.3.1 iPhone, iOS 17.4 Simulator.
Bug report FB13685677 filed with Apple.
I'm trying to do something so seemingly basic, yet I can't get it to work and I'm flummoxed.
In a basic, vanilla SwiftUI app for tvOS, embed a single Text element with a very long string (hundreds of lines) in it:
struct ContentView: View {
var body: some View {
ScrollView(.vertical) {
Text(veryLargeString)
.focusable()
}
}
}
Then fire up the app on tvOS, and it will not scroll. No matter what I do. Pressing arrow keys, swiping fast with my thumb, and nothing. It will not move. Ironically, in the Xcode SwiftUI Preview window—it does scroll, so that's always a fun tease.
What I do know is that the focus engine is throwing a few errors, so it's leading me to believe the issue is with how I have the focusable element attached. I'm using a combination of -UIFocusLoggingEnabled YES as well as listening for UIFocusSystem.movementDidFailNotification.
Unfortunately since this is SwiftUI, the notification failure and debugging logs aren't really all that actionable. Help appreciated!
I have a fairly robust MacOS application that has an NSScrollView that contains a canvas with various subviews (including web views and text views that contain scroll views), and a couple of peer views that track items in the scroll view (eg: screen space controls).
Some of these views interrupt two finger scrolling. Every scroll view, and one of the peer views (essentially a stack view with buttons in it).
I have written an additional bare bones application which does roughly the same thing, and my bare bones application works perfectly: Start two-finger dragging, scroll any of these other things under the cursor, I can continue to drag (and start dragging in any of those, and they drag without interfering with the parent scroll view).
I have tried everything to recreate the interruption, including drag gestures attached to these various ancillary views, and I cannot figure out why dragging some of these views under the cursor interrupts two finger drag in our application, but not in my testbed.
Does anyone have suggestions for how to debug this? I can see that there is a gesture recognizer in the NSScrollView hierarchy, but I don't see it in any of my gesture recognizer handling. I have breakpoints on every variation of hit testing and mouse motion, and none of them are getting hit in unexpected ways.
I'm at my wit's end. Thanks.
I see viewIsAppearing is available on iOS 13 and above, but when I use it, found that the function not be called below iOS 16
https://developer.apple.com/documentation/uikit/uiviewcontroller/4195485-viewisappearing
environment: Macos 14.4.1, Xcode 15.3
import UIKit
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
let sub = SubViewController()
addChild(sub)
view.addSubview(sub.view)
}
@available(iOS 13.0, *)
override func viewIsAppearing(_ animated: Bool) {
super.viewIsAppearing(animated)
print("ViewController viewIsAppearing")
}
}
class SubViewController: UIViewController {
@available(iOS 13.0, *)
override func viewIsAppearing(_ animated: Bool) {
super.viewIsAppearing(animated)
print("SubViewController viewIsAppearing")
}
}
In iOS 15 devcice console log:
ViewController viewIsAppearing
iOS 16, 17:
ViewController viewIsAppearing
SubViewController viewIsAppearing
Hi! I'm running into a warning from a SwiftUI.DynamicProperty on a 6.0 development build (swift-6.0-DEVELOPMENT-SNAPSHOT-2024-03-26-a).
I am attempting to build a type (conforming to DynamicProperty) that should also be MainActor. This type with also need a custom update function. Here is a simple custom wrapper (handwaving over the orthogonal missing pieces) that shows the warning:
import SwiftUI
@MainActor struct MainProperty: DynamicProperty {
// Main actor-isolated instance method 'update()' cannot be used to satisfy nonisolated protocol requirement; this is an error in the Swift 6 language mode
@MainActor func update() {
}
}
Is there anything I can do about that warning? Does the warning correctly imply that this will be a legit compiler error when 6.0 ships?
I can find (at least) two examples of types adopting DynamicProperty from Apple that are also MainActor: FetchRequest and SectionedFetchRequest. What is confusing is that both FetchRequest^1 and SectionedFetchRequest^2 explicitly declare their update method to be MainActor. Is there anything missing from my Wrapper declaration that can get me what I'm looking for? Any more advice about that? Thanks!
A simple view has misaligned localized content after being converted to an image using ImageRenderer.
This is still problematic on real phone and TestFlight
I'm not sure what the problem is, I'm assuming it's an ImageRenderer bug.
I tried to use UIGraphicsImageRenderer, but the UIGraphicsImageRenderer captures the image in an inaccurate position, and it will be offset resulting in a white border. And I don't know why in some cases it encounters circular references that result in blank images.
"(1) days" is also not converted to "1 day" properly.
Hi, I have pretty much finished my app's layout but realized I needed to scale it for different devices. I have read online that hardcoding values (esp in frames) is a big no-no, and GeometryReader should be heavily utilized. Also was recommended ViewThatFits. The problem is, I want the app to look the exact same across all devices. What is the best way to get started?
Also, when testing, do I only have to test on an iPad and iPhone or are the dimensions significantly different amongst each class of devices?
I have a simple example to demonstrate...
struct MyView: View {
var body: some View {
Text("WOW")
}
}
struct MyOtherView: View {
var body: some View {
NavigationStack {
Text("WOW")
}
}
}
On VisionOS, MyOtherView has a glass background effect that cannot be disabled. glassBackgroundEffect(displayMode: .never) .background(.clear), .foregroundColor(.clear), none of them work.
I then resorted to the SwiftUIIntrospect package to try set .clear on various child objects of the NavigationStack but nothing is working.
I am in control of my own glass containers. I have a couple with space between them, but with the NavigationStack it sets a background behind both of them ruining the effect.
This is what MyOtherView renders as:
I'm looking for it to be completely transparent except the text. Like the below layout.
For now I will have to roll my own navigation.
I am trying add Sign in with Apple but when I attempt to capability in my app nothing happens in the list
does apple not able to provide this feature yet in Vision OS or is there any bug or may be ami missing something which does not seems?
In SwiftUI, a link is identified as both a button and link, this is during when running with VoiceOver.
I know you can remove the button trait using .accessibilityRemoveTraits.
However, I am sure there is a reason to it.
Can somebody explain if it is genuinely a bug.
Adding environment value openURL or dismiss to a View in a NavigationStack, without even using it, causes an infinite refresh loop.
What doesn't work:
a)
struct ViewA: View {
@State private var path = NavigationPath()
var body: some View {
NavigationStack(path: $path) {
ViewB()
}
}
}
struct ViewB: View {
@Environment(\.openURL) var openURL
var body: some View {
NavigationLink("Next", value: 1)
.navigationDestination(for: Int.self, destination: itemView)
}
func itemView(_ item: Int) -> some View {
Text("Item \(item)")
}
}
Prints ViewB: _openURL changed. infinitely.
b) Passing the path to ViewB and appending the value with a Button
What works:
a)
.navigationDestination(for: Int.self) {
Text("Item \($0)")
}
Prints
ViewB: @self, @identity, _openURL changed.
ViewB: @self, _openURL changed.
ViewB: _openURL changed. (3 times)
b) Handling the destination on ViewA, which is not ideal for my use case.
Prints
ViewB: @self, @identity, _openURL changed.
ViewB: _openURL changed. (5 times)
While the workaround would work, it is still unclear how the environment value can cause the freeze (and eventual crash). Also that passing a function as parameter fails, while providing the destination in place does not. The code is stripped down to the minimal reproducible version. Any thoughts?