Posts

Post not yet marked as solved
0 Replies
212 Views
@Model class modelData { var property1 : String = "" init(property1: string){ ... } } for item in arrayOfManyStrings { let instanceOfModelData = modelData(property1: item) } Trying to create multiple instances of my modelData. I expect the loop to run and create instanceOfModelData 30k times. However it is far too slow. 30-90 seconds depending on device. If I remove the @Model macro, the same loop take < 5 seconds. I obviously need the @Model for swiftData. How to speed up creating instances of instanceOfModelData when using @Model
Posted
by RyanTCB.
Last updated
.
Post not yet marked as solved
2 Replies
242 Views
How to show the keyboard for textfield on ToolbarItem(placement: .keyboard)? I have a button and it's action I want is to show the keyboard. On top of which is ToolbarItem(placement: .keyboard) { HStack{ Button(...) TextField("", text: $bindingText) .textFieldStyle(RoundedBorderTextFieldStyle()) .keyboardType(.numberPad) .multilineTextAlignment(.trailing) } } I know keyboard shows with a textfield focused. How though to show the keyboard for ToolbarItem(placement: .keyboard) Textfield if can't show it without showing the keyboard?
Posted
by RyanTCB.
Last updated
.
Post not yet marked as solved
2 Replies
478 Views
Is SwiftData not designed for large datasets? How to create many instances of my Data Model? I have a loop where I iterate over a CSV file of 30k+ lines. Totalling around 230k elements. I intend to save this data into SwiftData. However it takes around 90 seconds. In previous versions of my app I was using coreData. Then it took just 3 seconds. So after much investigation I have concluded the delay comes from creating instances of the Data Model. To Test this I have : Removed any saves into SwiftData. So only creation of the Model Object occurs. Created an exact copy of the SwiftData Model class but admitted the @Model macro set isAutosaveEnabled to false When I run my loop with the copy class it takes 3 seconds. So It must be creating the SwiftData model instances that causes the *30 delay. The code using swiftData @Model. This loop takes 90+ seconds to complete class TimetableData { var arrivalTime : Int = 0 var departureTime: Int = 0 var departureRoute : Int = 0 var directionOfTravel : Int = 0 var dutyNumber : Int = 0 var facilityIdentifier : String = "" var locationType : String = "" var mode : String = "" var nonStopStatus : Int = 0 var recordIdentifier : String = "" var timetableIdentifier : Int = 0 var trainNumber : String = "" var tripNumber : Int = 0 var tripStartSite : String = "" var uniqueLocationCode : String = "" init(arrivalTime: Int = 0, departureTime: Int = 0, departureRoute: Int = 0, directionOfTravel: Int = 0, dutyNumber: Int = 0, facilityIdentifier: String = "", locationType: String = "", mode: String = "", nonStopStatus: Int = 0, recordIdentifier: String = "", timetableIdentifier: Int = 0, trainNumber: String = "", tripNumber: Int = 0, tripStartSite: String = "", uniqueLocationCode: String = "") { self.name = name self.arrivalTime = arrivalTime self.departureTime = departureTime self.departureRoute = departureRoute self.directionOfTravel = directionOfTravel self.dutyNumber = dutyNumber self.facilityIdentifier = facilityIdentifier self.locationType = locationType self.mode = mode self.nonStopStatus = nonStopStatus self.recordIdentifier = recordIdentifier self.timetableIdentifier = timetableIdentifier self.trainNumber = trainNumber self.tripNumber = tripNumber self.tripStartSite = tripStartSite self.uniqueLocationCode = uniqueLocationCode } } for line in CSVFile { var columnValue = line.components(separatedBy: ",") let timeTableDataEntry = TimetableData ( arrivalTime: Int(columnValue[0])!, departureTime: Int(columnValue[1])!, departureRoute: Int(columnValue[2])!, directionOfTravel: Int(columnValue[3])!, dutyNumber: Int(columnValue[4])!, facilityIdentifier: columnValue[5], locationType: columnValue[6], mode: columnValue[7], nonStopStatus: Int(columnValue[8])!, recordIdentifier: columnValue[9], timetableIdentifier: Int(columnValue[10])!, trainNumber: columnValue[11], tripNumber: Int(columnValue[12])!, tripStartSite: columnValue[13], uniqueLocationCode:columnValue[14] ) } Then The exact same code but omitting the @Model takes around just 3 second. class TimetableDataForTesting { var arrivalTime : Int = 0 var departureTime: Int = 0 var departureRoute : Int = 0 var directionOfTravel : Int = 0 var dutyNumber : Int = 0 var facilityIdentifier : String = "" var locationType : String = "" var mode : String = "" var nonStopStatus : Int = 0 var recordIdentifier : String = "" var timetableIdentifier : Int = 0 var trainNumber : String = "" var tripNumber : Int = 0 var tripStartSite : String = "" var uniqueLocationCode : String = "" init(arrivalTime: Int = 0, departureTime: Int = 0, departureRoute: Int = 0, directionOfTravel: Int = 0, dutyNumber: Int = 0, facilityIdentifier: String = "", locationType: String = "", mode: String = "", nonStopStatus: Int = 0, recordIdentifier: String = "", timetableIdentifier: Int = 0, trainNumber: String = "", tripNumber: Int = 0, tripStartSite: String = "", uniqueLocationCode: String = "") { self.name = name self.arrivalTime = arrivalTime self.departureTime = departureTime self.departureRoute = departureRoute self.directionOfTravel = directionOfTravel self.dutyNumber = dutyNumber self.facilityIdentifier = facilityIdentifier self.locationType = locationType self.mode = mode self.nonStopStatus = nonStopStatus self.recordIdentifier = recordIdentifier self.timetableIdentifier = timetableIdentifier self.trainNumber = trainNumber self.tripNumber = tripNumber self.tripStartSite = tripStartSite self.uniqueLocationCode = uniqueLocationCode } } for line in CSVFile { var columnValue = line.components(separatedBy: ",") let timeTableDataEntry = TimetableDataForTesting ( arrivalTime: Int(columnValue[0])!, departureTime: Int(columnValue[1])!, departureRoute: Int(columnValue[2])!, directionOfTravel: Int(columnValue[3])!, dutyNumber: Int(columnValue[4])!, facilityIdentifier: columnValue[5], locationType: columnValue[6], mode: columnValue[7], nonStopStatus: Int(columnValue[8])!, recordIdentifier: columnValue[9], timetableIdentifier: Int(columnValue[10])!, trainNumber: columnValue[11], tripNumber: Int(columnValue[12])!, tripStartSite: columnValue[13], uniqueLocationCode:columnValue[14] ) }
Posted
by RyanTCB.
Last updated
.
Post not yet marked as solved
0 Replies
167 Views
TLDR; Can I have a widget without a Timeline? My previous watch app had a complication. Simply so it can be added to the watch face for a quick launch of the app. However now seeing that method is deprecated in favour of widgets. Can I add a widget without the need for all the Timeline as all I want is a button on the watch face to launch into my app. No data is updated over time so no need for all the extra timeline code.
Posted
by RyanTCB.
Last updated
.
Post not yet marked as solved
0 Replies
305 Views
There's another thread on here with similar Q but seems to have no resolution. So starting my own. The basics Xcode 15.3.0 beta 3 iOS 17.4 The WatchOS 10.4 I have an iPhone app with a companion watch app. In Xcode if I set the scheme to my iOS app it installs on my phone but the companion watch app does not auto install on my watch. Automatic App Install is turned on in Watch app on iPhone. To run the app on watchOS I have to run it directly from the watch scheme on Xcode. If I delete the app from the watch then go into the iOS watch app on the iOS device to install on my watch I receive an error "This app could not be installed at this time" Is there a known cause solution?
Posted
by RyanTCB.
Last updated
.
Post not yet marked as solved
1 Replies
479 Views
27" intel Mac Ventura 13.6.4 Developer site says MacOS 13.5 or later required for Xcode 15.3 Beta. Download, Expand .xip, Attempt to open application "You can’t use this version of the application “Xcode-beta” with this version of macOS. You have macOS 13.6.4. The application requires macOS 14.0 or later." Developer site clearly says 13.5 or Later which 13.6.4 is. So why on wasting my time downloading and unarchiving dos it now claim to need 14.0??
Posted
by RyanTCB.
Last updated
.
Post not yet marked as solved
1 Replies
336 Views
Submitted a TSI 4 days ago. Heard nothing back. Status Used. Surely a TSI is a fulfilled request and not just ignored? Also the forum tags don't have TSI so not sure where this post will end up
Posted
by RyanTCB.
Last updated
.
Post marked as solved
1 Replies
380 Views
2 versions 1 works 1 doesn't. UIViewRepresentable to show a PDF @AppStorage(DefaultsKey.userActiveBook.rawValue) var activeBook : URL = Bundle.main.url(forResource: "BookPlaceHolder", withExtension: "pdf")! func makeUIView(context: Context) -&gt; PDFView { do { let pdfData = try Data(contentsOf: activeBook) pdfView.document = PDFDocument(data: pdfData) //&lt;---- is nil ... } catch let Error { print(Error) } } fails with Error Domain=NSCocoaErrorDomain Code=260 "The file “BookPlaceHolder.pdf” couldn’t be opened because there is no such file." func makeUIView(context: Context) -&gt; PDFView { do { let pdfData = try Data(contentsOf: Bundle.main.url(forResource: "BookPlaceHolder", withExtension: "pdf")!) pdfView.document = PDFDocument(data: pdfData) ... } catch let Error { print(Error) } } Works perfectly. What is it with using @AppStorage to access the exact same URL causing the discrepancies ?
Posted
by RyanTCB.
Last updated
.
Post marked as solved
1 Replies
297 Views
How often/ under what circumstances are users sandbox directory URL's changed? So I tried to save a URL to a document in @AppStorage @AppStorage(DefaultsKey.userActiveBook.rawValue) var activeBook : URL = Bundle.main.url(forResource: "BookPlaceHolder", withExtension: "pdf")! When user selects a new document activeBook is updated with the new URL. Issue is when the app relaunches from xCode the path to whatever is stored in activeBook changes. My work around so far is to just access the users Documents Directory via FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).first!. Then appending the last path component of activeBook. sidebar: obviously this doesn't work if the saved URL in activeBook is still the default from Bundle.main.url. I haven't written that workaround as yet. Am I only seeing issues in development due to a fresh relaunch via xCode? If the user only ever terminates the app on their device are the .documentDirectory URL's changing on each launch or do the remain constant? I don't want to write a workaround to ensure the correct URL for whats stored in @AppStorage, if the changing URL's only occurs due to launching from xCode which the end user wont ever encounter that edge case.
Posted
by RyanTCB.
Last updated
.
Post not yet marked as solved
6 Replies
682 Views
So I am trying to sync only some of my Models with iCloud and others kept locally in the default.store. I am having a world of issues so before I start looking for the needle in my haystack. I would like to ask this forum, is my approach one that should work as desired or is my code obviously why things are not working? All my Models have default values and relationships where needed are optionals. iCloud is working but my issue arises when i try to exclude some models. So I want to sync "modelsForCloudSyncing" but not "modelNotForCloudSyncing" In advance thank you var avoidCloudSyncModelContainer : ModelContainer = { let modelNotForCloudSyncing = Schema([NoCloudSyncModel.self]) let modelConfigForNoCloudSync = ModelConfiguration(schema: modelNotForCloudSyncing, cloudKitDatabase: .none) let modelsForCloudSyncing = Schema([CloudSyncModelA.self, CloudSyncModelB.self, CloudSyncModelC.self]) let modelConfigForCloudSync = ModelConfiguration(schema: modelsForCloudSyncing, cloudKitDatabase: .automatic) do { return try ModelContainer(for: NoCloudSyncModel.self, CloudSyncModelA.self, CloudSyncModelB.self, CloudSyncModelC.self, configurations: modelConfigForNoCloudSync, modelConfigForCloudSync) } catch { fatalError("Could not create ModelContainer: \(error)") } }() ... { ContentView() }.modelContainer(avoidCloudSyncModelContainer)
Posted
by RyanTCB.
Last updated
.
Post not yet marked as solved
0 Replies
394 Views
Not developer related but I can't find any help with google and trying to send a crash report to apple just causes spinning beachball. So hoping i can find some much needed help in this forum. Safari runs very slow and every time it launches i get an error producing the log below. Any fix suggestions please. Seeing a WebPrivacy library missing leaves me with no confidence using my mac. I had hoped a software update to Ventura 13.6.3 would resolve but no. Path: /Volumes/VOLUME/*/WebPrivacy.framework/Versions/A/XPCServices/com.apple.WebPrivacy.Service.xpc/Contents/MacOS/com.apple.WebPrivacy.Service Identifier: com.apple.WebPrivacy.Service Version: 34 (34.1.1) Build Info: WebPrivacy-34000000000000~249 (617C13) Code Type: X86-64 (Native) Parent Process: launchd [1] Responsible: Safari [5749] User ID: 501 Date/Time: 2023-11-15 09:15:24.5072 +0000 OS Version: macOS 13.6.3 (22G423) Report Version: 12 Anonymous UUID: EC45AED0-4F92-87DE-6EE8-AE74E4A4BD5E Sleep/Wake UUID: 65B3C137-4BC0-476B-9975-503694B76241 Time Awake Since Boot: 150000 seconds Time Since Wake: 88111 seconds System Integrity Protection: enabled Crashed Thread: 0 Exception Type: EXC_CRASH (SIGABRT) Exception Codes: 0x0000000000000000, 0x0000000000000000 Termination Reason: Namespace DYLD, Code 1 Library missing Library not loaded: /System/Library/PrivateFrameworks/WebPrivacy.framework/Versions/A/WebPrivacy Referenced from: <BF03A141-E3B8-3EC8-B0D3-79F9E987841B> /Volumes/VOLUME/*/WebPrivacy.framework/Versions/A/XPCServices/com.apple.WebPrivacy.Service.xpc/Contents/MacOS/com.apple.WebPrivacy.Service Reason: tried: '/System/Library/PrivateFrameworks/WebPrivacy.framework/Versions/A/WebPrivacy' (no such file), '/System/Volumes/Preboot/Cryptexes/Incoming/OS/System/Library/PrivateFrameworks/WebPrivacy.framework/Versions/A/WebPrivacy' (no such file), '/System/Library/PrivateFrameworks/WebPrivacy.framework/Versions/A/WebPrivacy' (no such file, not in dyld cache), '/System/Library/Frameworks/WebPrivacy.framework/Versions/A/WebPrivacy' (no such file, not in dyld cache) (terminated at launch; ignore backtrace) Thread 0 Crashed: 0 dyld 0x7ff812633c52 __abort_with_payload + 10 1 dyld 0x7ff81264dfd7 abort_with_payload_wrapper_internal + 82 2 dyld 0x7ff81264e009 abort_with_payload + 9 3 dyld 0x7ff8125d28f0 dyld4::halt(char const*) + 375 4 dyld 0x7ff8125cfb71 dyld4::prepare(dyld4::APIs&, dyld3::MachOAnalyzer const*) + 4526 5 dyld 0x7ff8125ce3bd start + 1805 Thread 0 crashed with X86 Thread State (64-bit): rax: 0x0000000002000209 rbx: 0x0000000000000000 rcx: 0x00007ff7b8f8a3c8 rdx: 0x00007ff7b8f8a830 rdi: 0x0000000000000006 rsi: 0x0000000000000001 rbp: 0x00007ff7b8f8a410 rsp: 0x00007ff7b8f8a3c8 r8: 0x00007ff7b8f8a430 r9: 0x0000000000000000 r10: 0x0000000000000127 r11: 0x0000000000000246 r12: 0x0000000000000127 r13: 0x00007ff7b8f8a830 r14: 0x0000000000000001 r15: 0x0000000000000006 rip: 0x00007ff812633c52 rfl: 0x0000000000000246 cr2: 0x0000000000000000 Logical CPU: 0 Error Code: 0x02000209 Trap Number: 133 Binary Images: 0x106f74000 - 0x106f8bfff com.apple.WebPrivacy.Service (34) <bf03a141-e3b8-3ec8-b0d3-79f9e987841b> /Volumes/VOLUME/*/WebPrivacy.framework/Versions/A/XPCServices/com.apple.WebPrivacy.Service.xpc/Contents/MacOS/com.apple.WebPrivacy.Service 0x7ff8125c8000 - 0x7ff8126605ef dyld (*) <d963b325-2b69-3e5a-ab79-8ce1662ec8cc> /usr/lib/dyld External Modification Summary: Calls made by other processes targeting this process: task_for_pid: 0 thread_create: 0 thread_set_state: 0 Calls made by this process: task_for_pid: 0 thread_create: 0 thread_set_state: 0 Calls made by all processes on this machine: task_for_pid: 153 thread_create: 0 thread_set_state: 5851 VM Region Summary: ReadOnly portion of Libraries: Total=171.8M resident=0K(0%) swapped_out_or_unallocated=171.8M(100%) Writable regions: Total=8452K written=0K(0%) resident=0K(0%) swapped_out=0K(0%) unallocated=8452K(100%)
Posted
by RyanTCB.
Last updated
.
Post not yet marked as solved
0 Replies
262 Views
I have to turn off closed captions for every video in the WWDC catalogue. How can i set all videos CC to be off by default?
Posted
by RyanTCB.
Last updated
.