I'm attempting to create a standalone watchOS app that fetches the prayer timings of my local mosque in JSON format via an API call. I want the app to fetch the prayer timings in the background, but only once per day, at the start of the day (when prayer timings change, i.e., midnight).
I'm trying to implement this using SwiftUI's backgroundTask modifier as explained in the docs and in this WWDC22 video.
I made sure to enable the Background Modes capability, and this is what my app's Info.plist looks like:
However, I've been unable to get it to work. I would appreciate any assistance I can get and feedback for improvements I can make, even with the Info.plist if anything is incorrect about it. Thank you!
This is what I have so far:
// PrayerTimesCompanionApp.swift
// PrayerTimesCompanion Watch App
import SwiftUI
import WatchKit
@main
struct PrayerTimesCompanion_Watch_AppApp: App {
var body: some Scene {
WindowGroup {
ContentView()
}
.backgroundTask(.appRefresh("TIMINGS_REFRESH")) {
print("Found matching task")
scheduleNextBackgroundRefresh()
}
}
}
// Schedule the next background refresh
func scheduleNextBackgroundRefresh() {
let today = Calendar.current.startOfDay(for: .now)
if let tomorrow = Calendar.current.date(byAdding: .day, value: 1, to: today) {
WKApplication.shared().scheduleBackgroundRefresh(withPreferredDate: tomorrow, userInfo: "TIMINGS_REFRESH" as NSSecureCoding & NSObjectProtocol) { error in
if error != nil {
fatalError("*** An error occurred while scheduling the background refresh task. ***")
}
print("*** Scheduled! ***")
}
}
}
// ContentView.swift
// PrayerTimesCompanion Watch App
import SwiftUI
struct ContentView: View {
@StateObject var prayerTimeModel = PrayerTimesModel()
var body: some View {
List {
VStack {
VStack(spacing: 15) {
// Table Header
HStack {
Text("Prayer")
.bold()
.frame(maxWidth: .infinity, alignment: .leading) // Align to the left
Text("Iqamah")
.bold()
.frame(maxWidth: .infinity, alignment: .trailing) // Align to the right
}
.padding()
// Table Rows (5 prayers)
ForEach(prayerTimeModel.prayerTimes.data.iqamah, id: \.date) { iqamah in
rowView(prayer: "Fajr", time: iqamah.fajr)
rowView(prayer: "Zuhr", time: iqamah.zuhr)
rowView(prayer: "Asr", time: iqamah.asr)
rowView(prayer: "Maghrib", time: iqamah.maghrib)
rowView(prayer: "Isha", time: iqamah.isha)
}
}
.padding()
}
.padding()
.onAppear {
prayerTimeModel.fetch()
}
}
.edgesIgnoringSafeArea(.top)
}
func rowView(prayer: String, time: String) -> some View {
HStack {
Text(prayer)
.frame(maxWidth: .infinity, alignment: .leading)
Text(time)
.frame(maxWidth: .infinity, alignment: .trailing)
}
}
}
#Preview {
ContentView()
}
// PrayerTimesModel.swift
// PrayerTimesCompanion Watch App
import Foundation
import SwiftUI
// Main struct for the response
struct PrayerTimesResponse: Codable {
let status: String
var data: SalahData
let message: [String]
}
// Struct for the data section
struct SalahData: Codable {
var salah: [Salah]
var iqamah: [Iqamah]
}
// Struct for Salah times
struct Salah: Codable {
let date: String
let hijriDate: String
let hijriMonth: String
let day: String
var fajr: String
let sunrise: String
var zuhr: String
var asr: String
var maghrib: String
var isha: String
enum CodingKeys: String, CodingKey {
case date, hijriDate = "hijri_date", hijriMonth = "hijri_month", day, fajr, sunrise, zuhr, asr, maghrib, isha
}
}
// Struct for Iqamah times
struct Iqamah: Codable {
let date: String
var fajr: String
var zuhr: String
var asr: String
var maghrib: String
var isha: String
let jummah1: String
let jummah2: String
enum CodingKeys: String, CodingKey {
case date, fajr, zuhr, asr, maghrib, isha, jummah1 = "jummah1", jummah2 = "jummah2"
}
}
class PrayerTimesModel: ObservableObject {
@Published var prayerTimes: PrayerTimesResponse = PrayerTimesResponse(
status: "Unknown",
data: SalahData(
salah: [Salah(date: "", hijriDate: "", hijriMonth: "", day: "", fajr: "", sunrise: "", zuhr: "", asr: "", maghrib: "", isha: "")],
iqamah: [Iqamah(date: "", fajr: "", zuhr: "", asr: "", maghrib: "", isha: "", jummah1: "", jummah2: "")]),
message: ["No data available"]
)
// fetches the local mosque's prayer timings via an API call
func fetch() {
guard let url = URL(string: "https://masjidal.com/api/v1/time/range?masjid_id=3OA87VLp") else {
return
}
let task = URLSession.shared.dataTask(with: url) { [self] data, _, error in
guard let data = data, error == nil else {
return
}
// Convert to JSON
do {
var prayerTimes = try JSONDecoder().decode(PrayerTimesResponse.self, from: data)
DispatchQueue.main.async {
self.prayerTimes = prayerTimes
}
}
catch {
print(error)
}
}
task.resume()
}
}
SwiftUI
RSS for tagProvide views, controls, and layout structures for declaring your app's user interface using SwiftUI.
Post
Replies
Boosts
Views
Activity
I have implemented a sample video editing timeline using SwiftUI and am facing issues. So I am breaking up the problem in chunks and posting issue each as a separate question. In the code below, I have a simple timeline using an HStack comprising of a left spacer, right spacer(represented as simple black color) and a trimmer UI in the middle. The trimmer resizes as the left and right handles are dragged. The left and right spacers also adjust in width as the trimmer handles are dragged.
Problem: I want to keep the background thumbnails (implemented currently as simple Rectangles filled in different colors) in the trimmer stationary as the trimmer resizes. Currently they move along as the trimmer resizes as seen in the gif below. How do I fix it?
import SwiftUI
struct SampleTimeline: View {
let viewWidth:CGFloat = 340 //Width of HStack container for Timeline
@State var frameWidth:CGFloat = 280 //Width of trimmer
var minWidth: CGFloat {
2*chevronWidth + 10
} //min Width of trimmer
@State private var leftViewWidth:CGFloat = 20
@State private var rightViewWidth:CGFloat = 20
var chevronWidth:CGFloat {
return 24
}
var body: some View {
HStack(spacing:0) {
Color.black
.frame(width: leftViewWidth)
.frame(height: 70)
HStack(spacing: 0) {
Image(systemName: "chevron.compact.left")
.frame(width: chevronWidth, height: 70)
.background(Color.blue)
.gesture(
DragGesture(minimumDistance: 0)
.onChanged({ value in
leftViewWidth = max(leftViewWidth + value.translation.width, 0)
if leftViewWidth > viewWidth - minWidth - rightViewWidth {
leftViewWidth = viewWidth - minWidth - rightViewWidth
}
frameWidth = max(viewWidth - leftViewWidth - rightViewWidth, minWidth)
})
.onEnded { value in
}
)
Spacer()
Image(systemName: "chevron.compact.right")
.frame(width: chevronWidth, height: 70)
.background(Color.blue)
.gesture(
DragGesture(minimumDistance: 0)
.onChanged({ value in
rightViewWidth = max(rightViewWidth - value.translation.width, 0)
if rightViewWidth > viewWidth - minWidth - leftViewWidth {
rightViewWidth = viewWidth - minWidth - leftViewWidth
}
frameWidth = max(viewWidth - leftViewWidth - rightViewWidth, minWidth)
})
.onEnded { value in
}
)
}
.foregroundColor(.black)
.font(.title3.weight(.semibold))
.background {
HStack(spacing:0) {
Rectangle().fill(Color.red)
.frame(width: 70, height: 60)
Rectangle().fill(Color.cyan)
.frame(width: 70, height: 60)
Rectangle().fill(Color.orange)
.frame(width: 70, height: 60)
Rectangle().fill(Color.brown)
.frame(width: 70, height: 60)
Rectangle().fill(Color.purple)
.frame(width: 70, height: 60)
}
}
.frame(width: frameWidth)
.clipped()
Color.black
.frame(width: rightViewWidth)
.frame(height: 70)
}
.frame(width: viewWidth, alignment: .leading)
}
}
#Preview {
SampleTimeline()
}
Hello!
After upgrading to Xcode 16 & Swift 6 & iOS 18 I starting receiveing strange crashes.
Happens randomly in different view and pointing to onGeometryChange action block. I added DispatchQueue.main.async { in hopes it will help but it didn't.
HStack {
...
}
.onGeometryChange(for: CGSize.self, of: \.size) { value in
DispatchQueue.main.async {
self.width = value.width
self.height = value.height
}
}
As far as I understand, onGeometryChange is defined as nonisolated and Swift 6 enforce thread checking for the closures, SwiftUI views are always run on the main thread. Does it mean we can not use onGeometryChange safely in swiftui?
BUG IN CLIENT OF LIBDISPATCH: Assertion failed: Block was expected to execute on queue [com.apple.main-thread (0x1eacdce40)]
Crashed: com.apple.SwiftUI.AsyncRenderer
0 libdispatch.dylib 0x64d8 _dispatch_assert_queue_fail + 120
1 libdispatch.dylib 0x6460 _dispatch_assert_queue_fail + 194
2 libswift_Concurrency.dylib 0x62b58 <redacted> + 284
3 Grit 0x3a57cc specialized implicit closure #1 in closure #1 in PurchaseModalOld.body.getter + 4377696204 (<compiler-generated>:4377696204)
4 SwiftUI 0x5841e0 <redacted> + 60
5 SwiftUI 0x5837f8 <redacted> + 20
6 SwiftUI 0x586b5c <redacted> + 84
7 SwiftUICore 0x68846c <redacted> + 48
8 SwiftUICore 0x686dd4 <redacted> + 16
9 SwiftUICore 0x6ecc74 <redacted> + 160
10 SwiftUICore 0x686224 <redacted> + 872
11 SwiftUICore 0x685e24 $s14AttributeGraph12StatefulRuleP7SwiftUIE15withObservation2doqd__qd__yKXE_tKlF + 72
12 SwiftUI 0x95450 <redacted> + 1392
13 SwiftUI 0x7e438 <redacted> + 32
14 AttributeGraph 0x952c AG::Graph::UpdateStack::update() + 540
15 AttributeGraph 0x90f0 AG::Graph::update_attribute(AG::data::ptr<AG::Node>, unsigned int) + 424
16 AttributeGraph 0x8cc4 AG::Subgraph::update(unsigned int) + 848
17 SwiftUICore 0x9eda58 <redacted> + 348
18 SwiftUICore 0x9edf70 <redacted> + 36
19 AttributeGraph 0x148c0 AGGraphWithMainThreadHandler + 60
20 SwiftUICore 0x9e7834 $s7SwiftUI9ViewGraphC18updateOutputsAsync2atAA11DisplayListV4list_AG7VersionV7versiontSgAA4TimeV_tF + 560
21 SwiftUICore 0x9e0fc0 $s7SwiftUI16ViewRendererHostPAAE11renderAsync8interval15targetTimestampAA4TimeVSgSd_AItF + 524
22 SwiftUI 0xecfdfc <redacted> + 220
23 SwiftUI 0x55c84 <redacted> + 312
24 SwiftUI 0x55b20 <redacted> + 60
25 QuartzCore 0xc7078 <redacted> + 48
26 QuartzCore 0xc52b4 <redacted> + 884
27 QuartzCore 0xc5cb4 <redacted> + 456
28 CoreFoundation 0x555dc <redacted> + 176
29 CoreFoundation 0x55518 <redacted> + 60
30 CoreFoundation 0x55438 <redacted> + 524
31 CoreFoundation 0x54284 <redacted> + 2248
32 CoreFoundation 0x535b8 CFRunLoopRunSpecific + 572
33 Foundation 0xb6f00 <redacted> + 212
34 Foundation 0xb6dd4 <redacted> + 64
35 SwiftUI 0x38bc80 <redacted> + 792
36 SwiftUI 0x1395d0 <redacted> + 72
37 Foundation 0xc8058 <redacted> + 724
38 libsystem_pthread.dylib 0x637c _pthread_start + 136
39 libsystem_pthread.dylib 0x1494 thread_start + 8
My custom control widget is show up and I can set it to Lock Screen, but it doesn't launch my app when I clicked it. any problem?
in A.swift file, code like below:
@available(iOS 18.0, *)
struct LockScreenAppLaunchWidget: ControlWidget {
var body: some ControlWidgetConfiguration {
StaticControlConfiguration(kind: "abc") {
ControlWidgetButton(action: LaunchAppIntent()) { // <-- HERE
Label("Something", systemImage: "arrow.up")
}
}
.displayName("Open app")
}
}
@available(iOS 18, *)
struct LaunchAppIntent: AppIntent {
static var title: LocalizedStringResource = "ABC"
static var description: IntentDescription? = "abcd"
static var openAppWhenRun: Bool = true
@MainActor
func perform() async throws -> some IntentResult & OpensIntent {
return .result()
}
}
Hello!
Previously, using content from one Swift Package in the UI of another would cause preview failures. Now, with Xcode 16, this issue has been improved, and the preview feature is working, though occasional crashes still occur. I have submitted a report regarding this issue.
I’ve encountered some issues while developing a SwiftUI-based application, particularly when using Xcode’s SwiftUI preview feature, which frequently crashes.
My app supports both macOS and iOS. Due to the differences between the platforms, I’ve had to implement some pages using UIKit and reference a few UIKit-based open-source frameworks. For instance, I’m using the LazyPager library, which only supports iOS. During runtime, I ensure LazyPager is only compiled for iOS by using .product(name: "LazyPager", package: "LazyPager", condition: .when(platforms: [.iOS])), which works as expected.
However, when I use Xcode’s SwiftUI preview mode and select macOS as the target, UIKit-related code still gets compiled, leading to a crash, with the error message indicating an issue related to LazyPager's UIKit dependencies.
Since it’s not feasible to ask the maintainers of these open-source libraries to add #if canImport(UIKit) conditionals to their code, I would like to ask if there’s a better way to resolve this issue, ensuring that SwiftUI preview works properly on macOS.
If you have any suggestions or solutions, I would greatly appreciate your assistance. Thank you so much for your help!
import PackageDescription
let package = Package(
name: "ImportLibrary",
platforms: [
.iOS(.v16),
.macOS(.v13)
],
products: [
.library(
name: "ImportLibrary",
targets: ["ImportLibrary"]),
],
dependencies: [
.package(url: "https://github.com/gh123man/LazyPager", from: "1.1.0"),
],
targets: [
.target(
name: "ImportLibrary",
dependencies: [
"SwiftSoup",
"Kingfisher",
"WaterfallGrid",
.product(name: "LazyPager", package: "LazyPager", condition: .when(platforms: [.iOS])),
"QuickModule"
]
),
.testTarget(
name: "ImportLibraryTests",
dependencies: ["ImportLibrary"]),
]
)
Sincerely,
Best regards
There are a couple of questions in here.
I want to do a basic master-detail split view, as so many SwiftUI apps do. But I want to let the user select an arbitrary subset of items in the list, select them all, and delete them (or do other operations).
Select All, by default, is excruciatingly slow. I have a List view with a selection binding to a Set<PersistentIdentifier>. A ForEach inside renders the items from a SwiftData @Query. I have a couple hundred items, each with a String and Date property. The list item renders the String and nothing else.
I click on an item, hit Command-A, and the app locks up for several seconds while it messes with the selection. It never highlights all the items, but sometimes highlights one (usually different from the one I clicked on).I have an .onChange(of: self.selection) in there to debug the selection. It is called many, many times (2-3 times per second, very slowly), and print the selection count, which starts at 135, and goes down by one, to about 103. If I scroll the list, the selection onChange gets called a bunch more times. Sometimes you see the selection highlights change.
My SwiftUI view hierarchy looks like this:
NavigationSplitView
OrdersList
struct
OrdersList : View
{
var
body: some View
{
List(selection: self.$selection)
{
ForEach(self.orders)
{ order in
NavigationLink
{
Text("Order ID: \(order.vendorOrderID ?? "<none>")")
}
label:
{
Text("Order ID: \(order.vendorOrderID ?? "<none>")")
}
}
.onDelete(perform: self.deleteOrders)
.onChange(of: self.selection)
{
print("Selection changed: \(self.selection.count)")
}
}
}
func
deleteOrders(offsets: IndexSet)
{
withAnimation
{
for index in offsets
{
self.modelContext.delete(self.orders[index])
}
}
}
@State var selection = Set<PersistentIdentifier>()
@Query var orders : [Order]
@Environment(\.modelContext) var modelContext
}
If I use the mouse to select a single item, it behaves as expected. The item is selected, the onChange gets called, and if I choose Edit->Delete, the onDelete handler is called.
If I use the mouse to shift-select multiple items, the behavior is similar to Select All above, but the selection Set count starts at the number of items I selected, and then is slowly whittled down to 0 or 1, with some random item being selected.
I’d like for the Edit->Delete command to work with a keystroke (delete). How can I set the shortcut on an existing menu item without having to reimplement its behavior?
After upgrading to MacOS Sequoia and Xcode 16 my app was behaving oddly. While running the application from Xcode, the app appears to save data, but running the app again from Xcode, the data is not there. If I open the app on the iPhone, run it and create data, the data persists even after I kill the app from the app switcher.
I went many rounds through my code and found nothing that helped. I finally ran the sample app that appears when you begin a new project and that is behaving the same way. There are errors thrown.
error: the replacement path doesn't exist: "/var/folders/qv/m7sk8kcd3713j3l4bg8wt1lw0000gn/T/swift-generated-sources/@_swiftmacro_13SwiftDataTest11ContentViewV5items33_BCE1062261466603F5F86A688789BF68LL5QueryfMa.swift"
error: the replacement path doesn't exist: "/var/folders/qv/m7sk8kcd3713j3l4bg8wt1lw0000gn/T/swift-generated-sources/@_swiftmacro_13SwiftDataTest11ContentViewV5items33_BCE1062261466603F5F86A688789BF68LL5QueryfMa.swift"
error: the replacement path doesn't exist: "/var/folders/qv/m7sk8kcd3713j3l4bg8wt1lw0000gn/T/swift-generated-sources/@_swiftmacro_13SwiftDataTest11ContentViewV5items33_BCE1062261466603F5F86A688789BF68LL5QueryfMa.swift"
It looks like iOS 18 app changed the way document-based SwiftUI apps function in a way that breaks our app.
Previously, a ReferenceFileDocument would run its init(configuration:) function before any SwiftUI views would load. Now, it runs it after SwiftUI views load and their onAppear modifiers run.
Because we use a reference-type data model, our views reference a different object than the one loaded from our document's content. Much of our app's functionality is broken, and file saving doesn't work (because the data model writing to disk isn't connected to the views)
I filed a bug report, but this seems like a wild change that should affect more than just us. It wasn't happening earlier in the iOS betas. It feels like it only got added in the last beta, but I'm not sure.
Has anyone else run into this, or have any guidance for how best to deal with this?
My app focuses on a particular day and in the app I have arrow buttons that let you switch to the next or previous day. When one of them is pressed I call WidgetCenter.shared.reloadAllTimelines(). Almost immediately, regardless of how many times they are pressed, I will usually see my widgets immediately update to reflect the new day.
I thought it would be nice to extend this functionality to Lock Screen controls. I had the AppIntent the Lock Screen buttons use call some of the same code that the arrow buttons in my app do, which includes a call to WidgetCenter.shared.reloadAllTimelines().
In the simulator it seemed to work great. I could see my Lock Screen widgets update almost immediately to focus on the new day.
However, when I tried it on an actual device it was a much different story. Usually the first button press will update the widgets but after that it can be much, much longer before the Lock Screen widgets eventually refresh.
It makes sense that the system is probably throttling my requests but is there a way to prevent this so that my Lock Screen controls operate the same way as buttons in my app?
I can't figure out if I've found a VoiceOver problem with Swift Charts or if I'm doing something incorrectly.
I have a loop within a loop showing 2 sets of data in the same chart.
If I touch a month then VO correctly says there are two data series. But if I keep swiping down only data from the first series is read.
ChatGPT said try referencing the outer loop and sure enough that worked if it done in BOTH the label and value.
It sounds really awkward though. For example, "High 89 degrees F High October".
Below the "bad" chart only says something such as "92 degrees F October" when swiping down. The "good" chart will read the high and low temperature data.
VStack {
headerText("BAD")
Chart {
ForEach(processedMonthlyInput) { oneMonth in
ForEach(oneMonth.temperatures, id: \.month) { element in
LineMark(
x: .value("Month", element.month, unit: .month),
y: .value("Temperature", element.tempVal.converted(to: .fahrenheit).value)
)
.accessibilityLabel("\(element.month.formatted(.dateTime.month(.wide)))")
.accessibilityValue(Text("\(element.tempVal.converted(to: tempUnit).formatted(.measurement(width: .abbreviated, numberFormatStyle: .number.precision(.fractionLength(0)))))"))
}
.symbol(by: .value("Type", oneMonth.theType))
.foregroundStyle(by: .value("Type", oneMonth.theType))
.interpolationMethod(.catmullRom)
}
}
.frame(maxHeight: paddingAmount)
.padding(.horizontal)
headerText("GOOD")
Chart {
ForEach(processedMonthlyInput) { oneMonth in
ForEach(oneMonth.temperatures, id: \.month) { element in
LineMark(
x: .value("Month", element.month, unit: .month),
y: .value("Temperature", element.tempVal.converted(to: .fahrenheit).value)
)
.accessibilityLabel("\(oneMonth.theType) \(element.month.formatted(.dateTime.month(.wide)))")
.accessibilityValue(Text("\(oneMonth.theType) \(element.tempVal.converted(to: tempUnit).formatted(.measurement(width: .abbreviated, numberFormatStyle: .number.precision(.fractionLength(0)))))"))
}
.symbol(by: .value("Type", oneMonth.theType))
.foregroundStyle(by: .value("Type", oneMonth.theType))
.interpolationMethod(.catmullRom)
}
}
.frame(maxHeight: paddingAmount)
.padding(.horizontal)
}
My problem: I tap in one of the TextFields defined below and try to type. After typing a single character, the cursor disappears from the TextField and I need to tap in the field again to enter the next character.
I have the following code:
@Observable
final class Species {
. . .
public var list: [String]
. . .
}
struct SpeciesCapture: View {
@State private var species = Species()
@State var trainingList: [String] = []
var body: some View {
NavigationStack {
VStack(alignment: .leading) {
HStack {
Text("some text")
Spacer()
Button("Add") {
trainingList.append("")
}
}
List {
ForEach($trainingList, id: \.self) { $animal in
TextField("Animal", text: $animal)
.textCase(.lowercase)
}
}
}
.onAppear {
trainingList = species.list
. . .
}
. . . // etc.
}
}
}
It appears that I am continually losing focus. How do I fix this problem?
Xcode 16.0 targeting iOS 18. The behavior appears in both Preview and the Simulator. (Haven't tried it on a physical device).
Hey all,
I am facing a new issue on iOS 18 with ScenePhase and .onChange modifier.
Here's roughly the code:
.onChange(of: scenePhase, initial: true) { old, new in
if new == .active {
doStuff()
}
}
on iOS 17 this was working as expected and triggered when eg. ap was brough from background or user navigated back to view
on ios18 though this code gets triggered constatnly in my case when I eg. navigate to another screen on top of the one with that .onChange. after navigation happens, the onChange is being triggered continuosly and does not stop which causes doStuff() to be called multiple times
I encountered a crash with my SwiftUI app for macOS.
NSInvalidArgumentException: -[MTLIGAccelRenderCommandEncoder setVertexBuffer:offset:attributeStride:atIndex:]: unrecognized selector sent to instance
struct ContentView: View {
@State var text = ""
var body: some View {
TextEditor(text: $text)
}
}
When I run macOS app, console print
NSBundle file:///System/Library/PrivateFrameworks/MetalTools.framework/ principal class is nil because all fallbacks have failed
and I found it crash with TextEditor.
Can somebody help me?
App intent is a powerful framework, we can show any swiftui in the result, but button action is not working in it, I have a table of cards to show in the result and I want to implement some action when user selects each card, Button actions are not working here, what should I do
Hi folks,
i have a swiftui app with a custom view (derived from UIRepresenatble)
in this view i load a scenekit scene and start an animation to rotate an object
this all works!
but when the whole thing gets updated, my custom view gets updated too and the former working animation stops!
Please tell me what i'm doing wrong!
Sincerely,
Wolfi
I am developing an app that supports iOS 15 and later.
Up until iOS 17, the behavior of onDrag and onDrop was as follows:
The item is moved by holding it and dragging it to the onDrop area.
When the item is dropped in the onDrop area, the logic is executed, and simultaneously, the item disappears immediately.
However, in iOS 18 the item remains for about 0.5 to 1.0 seconds before disappearing, even though there is no logic in the onDrop.
Is this the expected behavior, or is it a bug?"
A ModelContainer with two configurations for two seperate models with one set to isStoredInMemoryOnly:false and the other one isStoredInMemoryOnly:true crashes after insertion. Anyone git this to work?
import SwiftData
@main
struct RecipeBookApp: App {
var container: ModelContainer
init() {
do {
let config1 = ModelConfiguration(for: Recipe.self)
let config2 = ModelConfiguration(for: Comment.self, isStoredInMemoryOnly: true)
container = try ModelContainer(for: Recipe.self, Comment.self, configurations: config1, config2)
} catch {
fatalError("Failed to configure SwiftData container.")
}
}
var body: some Scene {
WindowGroup {
ContentView()
.modelContainer(container)
}
}
}
struct ContentView: View {
@Environment(\.modelContext) private var context
@Query private var recipes: [Recipe]
@Query private var comments: [Comment]
var body: some View {
VStack {
Button("Insert") {
context.insert(Recipe(name:"Test"))
context.insert(Comment(name:"Test"))
}
List(recipes){ recipe in
Text(recipe.name)
}
List(comments){ comment in
Text(comment.name)
}
}
.padding()
.onAppear(){
context.insert(Recipe(name:"Test"))
context.insert(Comment(name:"Test"))
}
}
}
@Model
class Recipe {
internal init(name:String ) {
self.name = name
}
var id: UUID = UUID()
var name: String = ""
}
@Model
class Comment {
internal init(name:String ) {
self.name = name
}
var id: UUID = UUID()
var name: String = ""
}
Please...
Failed to build module 'Charts'; this SDK is not supported by the compiler (the SDK is built with 'Apple Swift version 6.0 effective-5.10 (swiftlang-6.0.0.7.41 clang-1600.0.24.1)', while this compiler is 'Apple Swift version 6.0 effective-5.10 (swiftlang-6.0.0.9.11 clang-1600.0.26.2)'). Please select a toolchain which matches the SDK.
ANY WORKAROUNDS?
Hello everyone,
I really need your help here :-))
iOS App. 17 and up. Widget extensions and watchOS app as well.
New build for iOS 18 earlier this week.
All platforms works perfect, except the Apple Watch version, which crash constantly on launch. Testing on simulator and testing devices - works perfect. Uploading to TestFlight and running on the same device - crash.
The only thing I see in the crash report is StoredLocationBased.get error. It takes me to nowhere inside the project.
Opened a DTS to Apple as well. Any help here will be fully appreciated.
Thank you so much!
Hi,
The new TabBar, SideBar combination is very nice, but I tried customizing like text sizes, icon sizes using imageScale and all dint have any effect, also shows of selected item in side bar couldn't customize it, is there any suggestions ?
Kind Regards