Post

Replies

Boosts

Views

Activity

Automatically LineMark scaling in Charts
How to scale LineMark to fill all chart automatically? Here is my sample: import SwiftUI import Charts struct EnergyView: View { var body: some View { VStack { Chart { ForEach(DailyEnergy.mockData) { dailyEnergy in LineMark(x: .value("Data", dailyEnergy.date), y: .value("Value", dailyEnergy.energy)) PointMark(x: .value("Data", dailyEnergy.date), y: .value("Value", dailyEnergy.energy)) .annotation(alignment: .center, spacing: 10) { Text("\(Int(dailyEnergy.energy))") .minimumScaleFactor(0.5) .scaledToFit() .frame(width: 40) } } .interpolationMethod(.monotone) } }.frame(height: 100) } } struct EnergyView_Previews: PreviewProvider { static var previews: some View { EnergyView() } } struct DailyEnergy: Identifiable { let id: UUID = .init() let date: Date let energy: Double } extension DailyEnergy { static var mockData: [Self] { [ .init(date: "2023-08-01".formattedDate, energy: 1376), .init(date: "2023-08-02".formattedDate, energy: 1576), .init(date: "2023-08-03".formattedDate, energy: 1875), .init(date: "2023-08-04".formattedDate, energy: 1676), .init(date: "2023-08-05".formattedDate, energy: 1475), .init(date: "2023-08-06".formattedDate, energy: 1574), .init(date: "2023-08-07".formattedDate, energy: 1674) ] } } and here is result what I have: and here is result what I'm expect: I want to build LineMark on full chart view, but how I can do this? I tried to use scalledToFill(), but it change all chart instead only LineMark, also I tried to use .chartYScale(domain: 1200...2800), but in this case I can't be sure that all chart line will be fitted to chart view including my PointMark. Maybe Charts has any function to do this?
0
0
594
Aug ’23
swift ui magic
struct TestView: View { var body: some View { var descriptionShape: any Shape = Circle() descriptionShape = Circle() return Text("description") .clipShape(descriptionShape) } } Why in the .clipShape(descriptionShape) occurs Type 'any View' cannot conform to 'View' error?
3
0
886
Aug ’23
Core Data crash when try to fetch data
I received crash reports from Firebase Crashlytics and the same reports I see in XCode crashes tab, that application crashes in the first 2-5 seconds after launch when trying to fetch some data from DB. One interesting note that it's happens only on iOS 16.1.1, maybe who knows why it's happening? Here are a few parts of the code and stack trace: final class MessagesViewController: UIViewController { ... var conversation: Conversation? private var _fetchedResultsController: NSFetchedResultsController<Message>? private var fetchedResultsController: NSFetchedResultsController<Message>? { if _fetchedResultsController == nil { _fetchedResultsController = createFetchedResultsController() } return _fetchedResultsController } override func viewDidLoad() { super.viewDidLoad() performNewFetch() loadData() } private func performNewFetch() { self.fetchedResultsController?.fetchRequest.fetchLimit = 10 do { try self.fetchedResultsController?.performFetch() self.tableView.reloadData() } catch { } } func loadData() { RestAPI.shared.fetchMessages() { pagination in ... self.fetchedResultsController?.fetchRequest.fetchLimit = pagination.offset + pagination.limit do { try self.fetchedResultsController?.performFetch() self.tableView.reloadData() } catch { } ... } } private func createFetchedResultsController() -> NSFetchedResultsController<Message>? { if let uuid = conversation?.uuid { let fetchRequest = NSFetchRequest<Message>(entityName: "Message") fetchRequest.sortDescriptors = [NSSortDescriptor(key: "createdAt", ascending: false)] fetchRequest.fetchLimit = 10 fetchRequest.fetchOffset = 0 fetchRequest.predicate = NSPredicate(format: "conversation.uuid == %@", uuid) let context = CoreDataManager.shared.managedObjectContext let fetchResultsController = NSFetchedResultsController(fetchRequest: fetchRequest, managedObjectContext: context, sectionNameKeyPath: "sectionDate", cacheName: nil) fetchResultsController.delegate = self return fetchResultsController } else { return nil } } ... } Conversation model: class Conversation: NSManagedObject { @NSManaged public var createdAt: NSDate? @NSManaged public var uuid: String? @NSManaged public var messages: NSSet? } Messages model: class Message: NSManagedObject { @NSManaged public var createdAt: NSDate? @NSManaged public var sectionDate: String? @NSManaged public var conversation: Conversation? } Crash stack trace: Crashed: com.apple.main-thread EXC_BAD_ACCESS KERN_INVALID_ADDRESS 0x000000082a3ab680 Crashed: com.apple.main-thread 0 libobjc.A.dylib 0x307c objc_retain_x8 + 16 1 CoreData 0x4a7f8 __43-[NSFetchedResultsController performFetch:]_block_invoke + 660 2 CoreData 0x837e8 developerSubmittedBlockToNSManagedObjectContextPerform + 156 3 CoreData 0x83338 -[NSManagedObjectContext performBlockAndWait:] + 208 4 CoreData 0x60688 -[NSFetchedResultsController _recursivePerformBlockAndWait:withContext:] + 152 5 CoreData 0x5e574 -[NSFetchedResultsController performFetch:] + 252 6 MyPsychic 0x3a224 MessagesViewController.performNewFetch() + 277 (MessagesViewController.swift:277) 7 MyPsychic 0x39e38 MessagesViewController.viewDidLoad() + 4338048568 (<compiler-generated>:4338048568) 8 MyPsychic 0x3ac24 @objc MessagesViewController.viewDidLoad() + 4338052132 (<compiler-generated>:4338052132) 9 UIKitCore 0x382dc4 -[UIViewController _sendViewDidLoadWithAppearanceProxyObjectTaggingEnabled] + 84 10 UIKitCore 0x1ae40 -[UIViewController loadViewIfRequired] + 712 11 UIKitCore 0x1ab58 -[UIViewController view] + 24 12 UIKitCore 0x2e0f04 -[UINavigationController _startCustomTransition:] + 892 13 UIKitCore 0x1a6f44 -[UINavigationController _startDeferredTransitionIfNeeded:] + 496 14 UIKitCore 0x1a6604 -[UINavigationController __viewWillLayoutSubviews] + 96 15 UIKitCore 0x1a6568 -[UILayoutContainerView layoutSubviews] + 172 16 UIKitCore 0x5020 -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 1980 17 QuartzCore 0x99ec CA::Layer::layout_if_needed(CA::Transaction*) + 500 18 QuartzCore 0x1d0a0 CA::Layer::layout_and_display_if_needed(CA::Transaction*) + 148 19 QuartzCore 0x2e5b0 CA::Context::commit_transaction(CA::Transaction*, double, double*) + 456 20 QuartzCore 0x635ec CA::Transaction::commit() + 652 21 QuartzCore 0x4c8cc CA::Transaction::flush_as_runloop_observer(bool) + 88 22 UIKitCore 0x504b44 _UIApplicationFlushCATransaction + 52 23 UIKitCore 0x652740 _UIUpdateSequenceRun + 84 24 UIKitCore 0xc99fd0 schedulerStepScheduledMainSection + 172 25 UIKitCore 0xc9919c runloopSourceCallback + 92 26 CoreFoundation 0xd5f54 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 28 27 CoreFoundation 0xe232c __CFRunLoopDoSource0 + 176 28 CoreFoundation 0x66210 __CFRunLoopDoSources0 + 244 29 CoreFoundation 0x7bba8 __CFRunLoopRun + 836 30 CoreFoundation 0x80ed4 CFRunLoopRunSpecific + 612 31 GraphicsServices 0x1368 GSEventRunModal + 164 32 UIKitCore 0x3a23d0 -[UIApplication _run] + 888 33 UIKitCore 0x3a2034 UIApplicationMain + 340 34 MyPsychic 0x9368 main + 16 (AppDelegate.swift:16) 35 ??? 0x1ecbe4960 (Missing)
0
1
808
Apr ’23
How to receive changes of push notification via ANCS
I'm trying to implement the apple notification center service (ANCS) and want to display notifications from our application, but sometimes we need to update our notification and in this case, we send new push notifications via APNS with the same apns-collapse-id, and on-device this push notification change correctly, but I expect that this changes will be sent via ANCS to my device, but iOS didn't send it. What did I do wrong? How I can replace/modify the push notification which was sent and receive these changes via ANCS on my device? p.s. We use FCM + APNS for sending push notifications. p.s.s I'm using use iPhone 12 mini with iOS 15.2
0
0
1k
Jan ’22
Change localization of UIDatePicker in iOS 14
In my application users can change localization on the fly without restarting, and I have a date picker with inline preferred style, but it always displays on default language, if I set programmatically locale in 'en' or 'he' - changed the only month but days of the week still display on default language, how I can resolve this issue? P.S. I tried to change locale in this way: UserDefaults.standard.set(['he'], forKey: "AppleLanguages") UserDefaults.standard.synchronize() But it's work only after relaunch of the app. So, how I can change the locale of days of the week on my locale without relaunch the app?
9
0
2k
May ’21