I'm creating a simple TipViewStyle based on sample code but it fails to compile. It displays: Type 'MyViewStyle' does not conform to protocol 'TipViewStyle'
When I choose the Fix option, it adds this line:
`type alias Body = type'
What should the type be here?
struct MyTipViewStyle: TipViewStyle {
func makeBody(config: Configuration) -> some View {
VStack {
config.title
config.message?
}
}
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.
Post
Replies
Boosts
Views
Activity
I have a map application that needs to show a line (representing a direct route) that is above everything, including annotations. This is important because the map has lots of annotations (possibly hundreds) and the line is representing a route from point to another. With that many annotations being on top the line / route is basically useless because you can't see it.
I've looked at things like MKOverlayLevel but it only supports .aboveRoads or .aboveLabels. Is there a way to set the z-axis of a map overlay so that it truly is on top of everything else on the map, including annotations? And if not directly in MapKit, what other options might I have?
Worth noting that I'm targeting 16.4 and above, so that's my limitation on this
When I try to install cocoapods I get this error:
[!] Oh no, an error occurred.
Search for existing GitHub issues similar to yours:
https://github.com/CocoaPods/CocoaPods/search?q=dlopen%28%2FLibrary%2FRuby%2FGems%2F2.6.0%2Fgems%2Fffi-1.12.2%2Flib%2Fffi_c.bundle%2C+0x0009%29%3A+tried%3A+%27%2FLibrary%2FRuby%2FGems%2F2.6.0%2Fgems%2Fffi-1.12.2%2Flib%2Fffi_c.bundle%27+%28mach-o+file%2C+but+is+an+incompatible+architecture+%28have+%27x86_64%27%2C+need+%27arm64e%27+or+%27arm64%27%29%29%2C+%27%2FSystem%2FVolumes%2FPreboot%2FCryptexes%2FOS%2FLibrary%2FRuby%2FGems%2F2.6.0%2Fgems%2Fffi-1.12.2%2Flib%2Fffi_c.bundle%27+%28no+such+file%29%2C+%27%2FLibrary%2FRuby%2FGems%2F2.6.0%2Fgems%2Fffi-1.12.2%2Flib%2Fffi_c.bundle%27+%28mach-o+file%2C+but+is+an+incompatible+architecture+%28have+%27x86_64%27%2C+need+%27arm64e%27+or+%27arm64%27%29%29+-+%2FLibrary%2FRuby%2FGems%2F2.6.0%2Fgems%2Fffi-1.12.2%2Flib%2Fffi_c.bundle&type=Issues
If none exists, create a ticket, with the template displayed above, on:
https://github.com/CocoaPods/CocoaPods/issues/new
Be sure to first read the contributing guide for details on how to properly submit a ticket:
https://github.com/CocoaPods/CocoaPods/blob/master/CONTRIBUTING.md
Don't forget to anonymize any private data!
Looking for related issues on cocoapods/cocoapods...
Searching for inspections failed: undefined method `map' for nil:NilClass
robertsantovasco@iMac L1 demo %
I typed "install pod". There's pages of errors above that. Here is my podfile:
platform :ios, '9.0'
target 'L1 demo' do
Comment the next line if you don't want to use dynamic frameworks
use_frameworks!
pod 'RealmSwift'
end
Please help. Thank you.
We are using an imbedded WKWebView in a SwiftUI view. There are links within the pages being viewed - they are company pages - and some link to other pages as well as open named (or unnamed) browser tabs.
In our implementation, when there is a named (or unnamed) link to another browser tab, the view does not do anything.
Any ideas on how to allow tabs to open in some manner and allow the users to access the links?
Hi I think I found an issue with SwiftUI List on iOS 18.0 and 18.1
Using the ContentView from the code block below: if you try to drag and drop the globe image onto the blue rows, things work fine on both iOS 17 and 18 with either List or VStack.
However if you first drag and drop the image onto the Files app and then drag the newly created PNG file back into our app, it won't work on iOS 18 with the blue row inside the List. Also there's no visual feedback when hovering that blue row (unlike the one inside the VStack).
I've tried various view modifiers but no luck so far. Any help is appreciated.
Thank you.
FB15618535
struct ContentView: View {
var body: some View {
VStack {
Image(systemName: "globe")
.resizable()
.scaledToFit()
.frame(height: 100)
.draggable(Image(systemName: "globe"))
List {
Color.gray
.frame(height: 100)
Color.blue
.frame(height: 100)
.dropDestination(for: Image.self) { _, _ in
print("List dropped")
return true
}
}
VStack {
Color.gray
Color.blue
.dropDestination(for: Image.self) { _, _ in
print("VStack dropped")
return true
}
}
}
.padding()
}
}
I have ran into an issue that is illustrated by the code in the following GitHub repository.
https://github.com/dougholland/ColorTest
When a SwiftUI color originates from the ColorPicker it can be persisted correctly and renders the same as the original color. When the color originates from the MapFeature.backgroundColor, it is always rendered with the light appearance version of the color and not the dark appearance version. The readme in the GitHub repo has screenshots that show this.
Any assistance would be greatly appreciated as this is affecting an app that is in development and I'd like to resolve this before the app is released.
If this is caused by a framework bug, any possible workaround would be greatly appreciated also. I suspect it maybe a framework issue, possibly with some code related to the MapFeature.backgroundColor, because the issue does not occur when the color originates from the ColorPicker.
This is a critical bug with Document-Based Apps (SwiftData). If you download the WWDC 2023 sample code for"Building a document-based app using SwiftData" , open it in Xcode 16.1, and run it on an iOS 18+ simulator, you'll encounter a major issue. When you exit a document and reopen it, you'll find that the changes you just made were not saved.
iOS 18 has effectively rendered last year's WWDC 2023 sample code obsolete!
Has anyone managed to successfully save data in a Document-Based App using SwiftData?
ScrollView scrolling works on Mac Catalyst apps with a Trackpad just fine but the same cannot be said for mouses with scroll wheels.
Is there any way to achieve scrolling with scroll wheels?
Following instructions from ChatGPT, I'm trying to rearrange the order of rows in a UITableView.
- (void)tableView:(UITableView *)tableView performDropWithCoordinator:(id<UITableViewDropCoordinator>)coordinator {
NSIndexPath *destinationIndexPath = coordinator.destinationIndexPath ?: [NSIndexPath indexPathForRow:self.items.count inSection:0];
[tableView performBatchUpdates:^{
for (UITableViewDropItem *dropItem in coordinator.items) {
NSString *movedItem = dropItem.dragItem.localObject;
if (movedItem) {
NSIndexPath *sourceIndexPath = dropItem.sourceIndexPath;
if (sourceIndexPath) {
[self.items removeObjectAtIndex:sourceIndexPath.row];
[self.items insertObject:movedItem atIndex:destinationIndexPath.row];
[tableView moveRowAtIndexPath:sourceIndexPath toIndexPath:destinationIndexPath];
}
}
}
} completion:nil];
}
Xcode is complaining that UITableViewDropItem does not exist.
The class is in all the documentation, it is just not showing up when needed!
Suggestions?
I tried several times to use the PhotosPickerItem loadTransferable function with the goal of receiving some progress value especially when loading large video media.
However, the Progress object returned by the function has always isIndeterminate == true and so doesn't have any progress value to observe.
Is there some way to make it work ? Some configuration I might have overlooked ? Or is it just not working
I might have to revert back to the UIKit photo picker because of this
Hi,
I programmed an app to draw cards from a deck. After a card is drawn it is hidden from the deck. The drawn state is a property of a card struct in an array inside a deck struct.
This worked well in the past since iOS 14. Since Xcode 16 this does not work as before anymore.
This is the Card struct with a Boolfor the drawn state:
struct Card: Codable, Identifiable, Equatable, Hashable {
var isDrawn: Bool
…
}
The cards are stored in an array that is inside a CardDeck struct among other properties:
struct CardDeck: Codable {
var cards: [Card] = []
var cardSpacing: CGFloat
…
mutating func hideCard(card: Card) {
if let cardIndex = self.cards.firstIndex(of: card) {
self.cards[cardIndex].isDrawn = true
}
}
}
The deck is a published property of an observable DeckStore class for permanent storage:
class CardDeckStore: ObservableObject {
@Published var deck: CardDeck = CardDeck()
…
}
The DeckStore class is @StateObject in the App struct:
@main
struct CardApp: App {
@StateObject var store = OpaliaCardDeckStore()
var body: some Scene {
WindowGroup {
ContentView(deck: $store.deck)
}
}
}
Here is the simplified DrawCardsView where I present and draw the cards:
struct DrawCardsView: View {
@Binding var deck: CardDeck
var body: some View {
// Was a NavigationView before
NavigationStack() {
HStack(spacing: deck.cardSpacing) {
ForEach($deck.cards) { $card in
if card.isDrawn {
CardBackView(card: card)
.hidden()
}
else {
NavigationLink(destination: DrawnCardView(card: card, deck: $deck)) {
CardBackView(card: card)
}
}
}
}
}
}
}
To hide a drawn card, hideCard() is called in the DrawnCardView:
struct DrawnCardView: View {
var card: Card
@Binding var deck: CardDeck
@State var drawnCard: DrawnCard = .init()
var body: some View {
DrawnCardSimpleView(drawnCard: self.drawnCard)
.onDisappear(perform: {
deck.hideCard(card: self.card)
})
}
}
I am not a pro in programming and there are better solutions to program this, but this worked until I upgraded to Xcode 16. Now it seems the isDrawn state of a card does not update the DrawCardsView right away anymore. A drawn card is not hidden and still present when returning to DrawCardsView from DrawnCardView. After tapping the same card again or another update of the UI, the card will then be hidden.
I do not know the reason. It seems the binding of the isDrawn state inside an element of the card array in the observable object is not working anymore. Other properties of the observable object like cardSpacing do work as expected.
I can empty the cards array and fill it with new cards without problems in the DrawCardsView.
I eliminated the ForEach loop by addressing the array elements directly, but to no avail. I tried different solutions I found on the internet, but nothing worked.
I was under the impression that every change in an observable object would update the UI.
Any ideas for a explanation/solution?
Thanks,
Christian
I've encountered what appears to be a bug with widget background image tinting in SwiftUI. When using an image in containerBackground(for: .widget) to fill the entire widget, adding the .containerBackgroundRemovable(false) modifier breaks the widget's tinting behavior:
The background image becomes permanently tinted, ignoring any widgetAccentedRenderingMode(_ renderingMode: WidgetAccentedRenderingMode?) settings
Text elements become tinted even with .widgetAccentable(false) applied
Sample code:
struct MyWidget: Widget {
var body: some WidgetConfiguration {
AppIntentConfiguration(kind: "MyWidget", intent: MyWidgetIntent.self, provider: Provider()) { entry in
MyWidgetView(entry: entry)
.containerBackground(for: .widget) {
Image("background")
.resizable()
.widgetAccentedRenderingMode(.fullColor)
.scaledToFill()
}
}
.containerBackgroundRemovable(false) // This causes the issue
}
}
Workaround: I've managed to resolve this by using a ZStack with disabled content margins and passing the widget size through the entry. However, this seems like unintended behavior with the .containerBackgroundRemovable(false) modifier.
Has anyone else encountered this issue or found a better solution?
Device: iPhone 15 Pro
iOS Version: 18.1
Xcode Version: 16.1
I'm seeing a discrepancy in the metrics of the "New York" system font returned from various Macs. Here's a sample (works well in Playgrounds):
import Cocoa
let font = NSFont(descriptor: .preferredFontDescriptor(forTextStyle: .body).withDesign(.serif)!, size: NSFont.systemFontSize)!
print("\(font.fontName) \(font.pointSize)")
print("ascender: \(font.ascender)")
let layoutManager = NSLayoutManager()
print("lineHeight: \(layoutManager.defaultLineHeight(for: font))")
When I run this on multiple Macs, I get two types of different results. Some – most Macs – report this:
.NewYork-Regular 13.0
ascender: 12.3779296875
lineHeight: 16.0
However, when I run on my own Mac (and also on the one of a colleague), I get this instead:
.NewYork-Regular 13.0
ascender: 14.034145955454255
lineHeight: 19.0
It's clearly the same font in the same point size. Yet the font has different metrics, causing a layout manager to also compute a significantly different line height.
So far I've found out that neither CPU generation/architecture nor macOS version seem to play a role. This issue has been reproducible since at least macOS 14. Having just migrated to a new Mac, the issue is still present.
This does not affect any other system or commonly installed font. It's only New York (aka the serif design).
So I assume this must be something with my setup. Yet I have been unable to find anything that may cause this. Anybody have some ideas? Happy to file a bug report but wanted to check here first.
I am working on a scrollable chart that displays days on the horizontal axis. As the user scrolls, I always want them to be able to snap to a specific day. I implemented the following steps described in this WWDC23 session to achieve this.
I have set the chartScrollTargetBehavior to .valueAligned(matching: DateComponents(hour: 0))
I have set the x value unit on the BarMark to Calendar.Component.day
I ended up with the chart code that looks like this:
Chart(dates, id: \.self) { date in
BarMark(
x: .value("Date", date, unit: Calendar.Component.day),
y: .value("Number", 1)
)
.annotation {
Text(date.formatted(.dateTime.day()))
.font(.caption2)
}
}
.chartXAxis {
AxisMarks(format: .dateTime.day())
}
.chartScrollableAxes(.horizontal)
.chartScrollTargetBehavior(.valueAligned(matching: DateComponents(hour: 0)))
.chartXVisibleDomain(length: fifteenDays)
.chartScrollPosition(x: $selection)
However, this fails to work reliably. There is often a situation where the chart scroll position lands on, for instance, Oct 20, 11:56 PM, but the chart snaps to Oct 21.
I attempted to solve this problem by introducing an intermediate binding between a state value and a chart selection. This binding aims to normalize the selection always to be the first moment of any given date. But this hasn't been successful.
private var selectionBinding: Binding<Date> {
Binding {
Calendar.current.startOfDay(for: selection)
} set: { newValue in
self.selection = Calendar.current.startOfDay(for: newValue)
}
}
It's also worth mentioning that this issue also exists in Apple's sample project on Swift Charts.
How would you approach solving this? How can I find a way to make the chart scroll position blind to time values and only recognize whole days?
Here's the minimal reproducible example project for your reference.
Error:App is ambiguous for type lookup in this context
code in UnqueHolidayApp
import SwiftUI
import RealmSwift
@main
struct UniqueHolidayApp: App {
init() {
migrateRealmIfNeeded()
}
var body: some Scene {
WindowGroup {
ContentView()
}
}
private func migrateRealmIfNeeded() {
let config = Realm.Configuration(
schemaVersion: 1,
migrationBlock: { migration, oldSchemaVersion in
if oldSchemaVersion < 1 {
// Realm will handle changes automatically for simple additions/removals
}
}
)
Realm.Configuration.defaultConfiguration = config
}
}
Hello. There seems to be a bug specifically in the iOS 18.2 (both Beta 1 and 2) and not seen in the previous versions.
The bug is: when LazyVGrid is nested inside NavigationStack and some elements of the LazyVGrid have animations, navigating into any nested view and then going back to the initial view with the LazyVGrid causes all animations to stop working.
Here is the example code inline:
struct ContentView: View {
@State private var count: Int = 0
var body: some View {
NavigationStack {
LazyVGrid(
columns: Array(
repeating: GridItem(spacing: 0),
count: 1
),
alignment: .center,
spacing: 0
) {
VStack {
Text(String(count))
.font(.system(size: 100, weight: .black))
.contentTransition(.numericText())
.animation(.bouncy(duration: 1), value: count)
Button("Increment") {
count += 1
}
NavigationLink(destination: { Text("Test") }, label: { Text("Navigate") })
}
}
}
.padding()
}
}
Once you run the application on iOS 18.2 Beta (I've tried on a real device only), the steps to reproduce are:
Tap on the "Increment button"
You should see the number change with an animation
Tap on the "Navigate" button
Tap "Back" to go to the initial screen
Tap "Increment" again
The number changes without an animation
I can confirm that this affects not only .contentTransition() animation but any animation within the LazyVGrid, I've tested this in my real app.
Let me know if I can provide more details. Thank you!
I encountered a strange behavior that reminded me of when .sheet() modifiers didn't inherit environment objects. Unless I'm missing something very obvious, it seems to me that TableColumn may expose the same issue. At least on macOS, because the very same code does not crash on iOS.
I'm posting this here before reporting a SwiftUI bug.
Below is a gist for a playground:
https://gist.github.com/keeshux/4a963cdebb1b577b87b08660ce9d3364
I also observe inconsistent behavior when building with Xcode 16.1 or 15.4, specifically:
https://github.com/passepartoutvpn/passepartout/issues/872#issuecomment-2477687967
The workaround I resorted to is re-propagating the environment from the parent:
https://github.com/passepartoutvpn/passepartout/pull/873/files#diff-c662c4607f2adfd0d4e2c2a225e0351ba9c21dbdd5fc68f23bc1ce28a20bce4dR45
I’m experiencing an issue with the search bar on my iPhone 16 Pro. When I start typing in the search bar (as shown in the screenshot), the keyboard overlaps with the search suggestions, making it hard to see the contacts and apps that are displayed. The interface seems cluttered, and it becomes difficult to accurately tap on the desired suggestion or contact.
Steps to Reproduce:
1. Swipe down to access the search bar on the iPhone 16 Pro.
2. Type a few letters to bring up suggestions for apps, contacts, and messages.
Expected Result: The search results should display clearly above the keyboard without overlapping or cluttered suggestions.
Actual Result: The keyboard overlaps with the search results, making it difficult to view or select items accurately.
Device and OS Details:
• iPhone 16 Pro
• iOS Version (please replace with your specific version)
Has anyone else encountered this issue? Any insights on possible fixes or settings adjustments would be appreciated.
I'm running into an issue where, eventually, something goes "wonky" on some detail items won't present the DetailView when they are clicked on.
At first, everything is fine, I can edit (and see results reflected in realtime). I can reorder the list, and I can add Detail items to the list. However, after a while, I start seeing the default detail view (Text("Select a detail item to view")) whenever I click on some items. I've not been able to predict where a failure will occur.
In the real app I have a persisted JSON document that never seems to get corrupted. And reflects the edits I perform.
With this sample app, I can pretty reliably trigger the issue by moving a detail item in the list, and then adding a detail item, but, it will eventually fail without those actions.
Am I doing something that's "forbidden"?
(You can create a new app and replace the ContentView.swift with the code below to run this and play with it)
import SwiftUI
struct ContentView: View {
@State var main = Main()
var body: some View {
NavView(main: $main)
.onAppear {
for index in 1..<11 {
main.details.append(
Detail(
title: "Detail \(index)",
description: "Description \(index)"))
}
}
}
}
struct NavView: View {
@Binding var main: Main
var body: some View {
NavigationSplitView {
ListView(main: $main)
} detail: {
Text("Select a detail item to view")
}
}
}
struct ListView: View {
@Binding var main: Main
@State private var addedDetailCount = 0
var body: some View {
List($main.details, editActions: .move) { $detail in
NavigationLink(destination: DetailView(detail: $detail)) {
Text("\(detail.title)")
}
}
.toolbar {
Button(
LocalizedStringKey("Add Detail"), systemImage: "plus"
) {
addedDetailCount += 1
main.details.append(
.init(title: "new Detail \(addedDetailCount)", description: "description"))
}
}
}
}
struct DetailView: View {
@Binding var detail: Detail
var body: some View {
Form {
Text("id: \(detail.id)")
TextField("Title", text: $detail.title)
TextField("Detail", text: $detail.description)
}
.padding()
}
}
struct Main {
var details = [Detail]()
}
struct Detail: Identifiable {
var id = UUID()
var title: String
var description: String
}
#Preview {
ContentView()
}
Hello community:
Is there any way to change the button color of the screen time permission to match app style?