I have a crash on 19 [UITextField inputAssistantItem] + 68
It is running on a Simulator, is this related?
Details:
========= code in app ================================
numberTextField = CursorInCenterTextField()
numberTextField.listener = self
numberTextField.delegate = self
numberTextField.textAlignment = .left
numberTextField.adjustsFontSizeToFitWidth = true
numberTextField.isUserInteractionEnabled = true
numberTextField.inputView = UIView()
numberTextField.inputAssistantItem.leadingBarButtonGroups = []
numberTextField.inputAssistantItem.trailingBarButtonGroups = []
numberTextField.font = UIFont.systemFont(ofSize: 24.0, weight: .medium)
numberTextField.autocorrectionType = .no
numberTextField.returnKeyType = .search
========= crash stack from ips file ========================
Incident Identifier: 50AF117D-546E-409E-8915-6E4607C83BC0
CrashReporter Key: 4AB5D894-3E17-F998-4B64-F931D05DC65D
Hardware Model: Macmini9,1
Process: Glip [47003]
Path: /Users/USER/Library/Developer/CoreSimulator/Devices/83049BCF-16F7-481C-BE83-58727242A065/data/Containers/Bundle/Application/82E219BC-96B5-4A0F-AB20-D068A88C792F/Glip.app/Glip
Identifier: com.glip.mobile.rc
Version: 25.1.10 (132)
Code Type: X86-64 (Native(?))
Role: Foreground
Parent Process: launchd_sim [38628]
Coalition: com.apple.CoreSimulator.SimDevice.83049BCF-16F7-481C-BE83-58727242A065 [1342]
Date/Time: 2024-12-04 22:47:10.4249 +0800
Launch Time: 2024-12-04 22:47:02.4577 +0800
OS Version: macOS 14.5 (23F79)
Release Type: User
Baseband Version: None
Report Version: 104(?)
Exception Type: EXC_BAD_ACCESS (SIGSEGV)
Exception Subtype: KERN_INVALID_ADDRESS at 0x00000001b3531d10
Exception Codes: 0x0000000000000001, 0x00000001b3531d10
Exception Note: EXC_CORPSE_NOTIFY(?)
VM Region Info: 0x1b3531d10 is not in any region. Bytes after previous region: 3427601 Bytes before following region: 176880
REGION TYPE START - END [ VSIZE] PRT/MAX SHRMOD REGION DETAIL
Rosetta Generic 1b31ec000-1b31ed000 [ 4K] rw-/rwx SM=PRV
---> GAP OF 0x370000 BYTES
Rosetta Generic 1b355d000-1b355e000 [ 4K] rw-/rwx SM=PRV
Termination Reason: SIGNAL;[11] Segmentation fault: 11
Terminating Process: exc handler [47003]
Triggered by Thread: 0
Kernel Triage:
None
Thread 0 name: com.apple.main-thread
Thread 0 Crashed:
0 None 0x11e1e0144 0x0 + 4800250180
1 CoreUI 0x14fa08817 -[CUIStructuredThemeStore renditionWithKey:usingKeySignature:] + 406
2 CoreUI 0x14fa3e8ac -[CUICatalog _storageRefForRendition:representsODRContent:] + 94
3 CoreUI 0x14fa3b244 -[CUICatalog namedVectorGlyphWithName:scaleFactor:deviceIdiom:layoutDirection:glyphContinuousSize:glyphContinuousWeight:glyphPointSize:appearanceName:locale:] + 1909
4 CoreUI 0x14fa3b3a5 -[CUICatalog namedVectorGlyphWithName:scaleFactor:deviceIdiom:layoutDirection:glyphSize:glyphWeight:glyphPointSize:appearanceName:locale:] + 74
5 UIKitCore 0x167c4f99c __78-[_UIAssetManager imageNamed:configuration:cachingOptions:attachCatalogImage:]_block_invoke_2 + 201
6 UIKitCore 0x167c51fce __88-[_UIAssetManager _performLookUpObjectForTraitCollection:outNamedLookup:objectAccessor:]_block_invoke + 79
7 UIKitCore 0x16713340e -[UITraitCollection _enumerateThemeAppearanceNamesForLookup:] + 215
8 UIKitCore 0x167c51f3d -[_UIAssetManager _performLookUpObjectForTraitCollection:outNamedLookup:objectAccessor:] + 172
9 UIKitCore 0x167c520c0 -[_UIAssetManager _lookUpObjectForTraitCollection:objectAccessor:] + 40
10 UIKitCore 0x167c4f709 __78-[_UIAssetManager imageNamed:configuration:cachingOptions:attachCatalogImage:]_block_invoke + 849
11 UIKitCore 0x167c4f137 -[_UIAssetManager imageNamed:configuration:cachingOptions:attachCatalogImage:] + 291
12 UIKitCore 0x167c5001d -[_UIAssetManager imageNamed:configuration:] + 224
13 UIKitCore 0x1670c1b87 +[UIImage _systemImageNamed:withConfiguration:allowPrivate:] + 297
14 UIKitCore 0x167ae8cc0 +[UIAssistantBarButtonItemProvider configuredSymbolImageWithName:size:keyboardLanguageCode:] + 585
15 UIKitCore 0x167ae747e +[UIAssistantBarButtonItemProvider barButtonItemForAssistantItemStyle:target:forcePlainButton:] + 2850
16 UIKitCore 0x167ae90f1 +[UIAssistantBarButtonItemProvider defaultSystemLeadingBarButtonGroupsForItem:] + 206
17 UIKitCore 0x167ae9935 +[UIAssistantBarButtonItemProvider systemDefaultAssistantItem] + 55
18 UIKitCore 0x167719194 -[UIResponder(UIResponderInputViewAdditions) inputAssistantItem] + 67
19 UIKitCore 0x167b67898 -[UITextField inputAssistantItem] + 68
20 Glip 0x105915dbc BaseDialPadViewController.setupTopContainerViewConstraintAndSubViews() + 780
21 Glip 0x105917869 BaseDialPadViewController.setupContentViewForM1X() + 2681
22 Glip 0x105915781 BaseDialPadViewController.setupUI() + 193
........
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
Activity
I've run into a problem with the following setup:
I have a Core Data database with parent objects with a relationship to many child objects. I have a main view using SwiftUI FetchedResults that displays the parent objects in a list and properties about the child objects. I have a second view that lets you change properties of the child objects.
The parent object has the property: name (string). The child object has: name (string) and star (bool). On the main view I display a list of parent objects and how many child objects are starred. On the second view I update if a child object is starred. Upon updating the property on the second view and saving, the first view does not update until you relaunch the app.
Here is the main view:
struct ContentView: View {
@Environment(\.managedObjectContext) private var viewContext
@FetchRequest(sortDescriptors: [SortDescriptor(\.name)])
private var parents: FetchedResults<Parent>
@State private var editingParent: Parent?
var body: some View {
List {
ForEach(parents) { parent in
VStack(alignment: .leading) {
Text(parent.name ?? "No Name")
Text("\(parent.children!.count) children")
Text("\(getNumberOfStar(parent: parent)) Stared")
}
.onTapGesture {
editingParent = parent
}
}
}
.sheet(item: $editingParent) { parent in
ChildrenView(parent: parent)
}
Button {
PersistenceController.shared.saveParent(name: "New Parent")
} label: {
Text("Add Parent")
}.padding()
Button {
parents.forEach { parent in
PersistenceController.shared.delete(parent: parent)
}
} label: {
Text("Delete All")
}.padding()
}
//this function does not get called when the database changes
func getNumberOfStar(parent: Parent) -> Int {
let children = parent.children!.allObjects as! [Child]
let starred = children.filter({$0.star == true})
return starred.count
}
}
This is the child view:
@FetchRequest var children: FetchedResults<Child>
var parent: Parent
init(parent: Parent) {
self.parent = parent
_children = FetchRequest<Child>(sortDescriptors: [], predicate: NSPredicate(format: "parent = %@", parent))
}
var body: some View {
List {
ForEach(children) { child in
HStack {
Text(child.name ?? "No Name")
Text(child.star ? "⭐️" : "")
Spacer()
Button {
PersistenceController.shared.updateStar(child: child)
} label: {
Text("Toggle Star")
}
}
}
}
Button {
PersistenceController.shared.saveChild(name: "New Child", parent: parent)
} label: {
Text("Add Child")
}
}
}
This is the Persistence Controller:
static let shared = PersistenceController()
let container: NSPersistentContainer
init(inMemory: Bool = false) {
container = NSPersistentContainer(name: "Model")
if inMemory {
container.persistentStoreDescriptions.first!.url = URL(fileURLWithPath: "/dev/null")
}
container.loadPersistentStores(completionHandler: { (storeDescription, error) in
if let error = error as NSError? {
// Replace this implementation with code to handle the error appropriately.
// fatalError() causes the application to generate a crash log and terminate. You should not use this function in a shipping application, although it may be useful during development.
/*
Typical reasons for an error here include:
* The parent directory does not exist, cannot be created, or disallows writing.
* The persistent store is not accessible, due to permissions or data protection when the device is locked.
* The device is out of space.
* The store could not be migrated to the current model version.
Check the error message to determine what the actual problem was.
*/
fatalError("Unresolved error \(error), \(error.userInfo)")
}
})
container.viewContext.automaticallyMergesChangesFromParent = true
}
func save() {
let viewContext = container.viewContext
do {
try viewContext.save()
} catch {
/**
Real-world apps should consider better handling the error in a way that fits their UI.
*/
let nsError = error as NSError
fatalError("Failed to save Core Data changes: \(nsError), \(nsError.userInfo)")
}
}
func saveParent(name: String) {
let newParent = Parent(context: container.viewContext)
newParent.name = name
save()
}
func saveChild(name: String, parent: Parent) {
let newChild = Child(context: container.viewContext)
newChild.name = name
newChild.parent = parent
newChild.star = false
save()
}
func updateStar(child: Child) {
child.star.toggle()
save()
}
func delete(parent: Parent) {
let viewContext = container.viewContext
viewContext.delete(parent)
save()
}
}
Finally here is the App struct:
struct Core_Data_Child_Save_ExampleApp: App {
let persistenceController = PersistenceController.shared
var body: some Scene {
WindowGroup {
ContentView()
.environment(\.managedObjectContext, persistenceController.container.viewContext)
}
}
}
In WWDC 2023 there was a good summary of how to handle the iOS 17 Observation capability.
But despite the clear graphics, it was still ambiguous (for me.)
I want to inject a class (view-model) so that it can be used in the complete view heirarchy, and used in bindings to allow bi-directional communication.
As far as I can tell there are 2 ways of declaring the VM (alternatives 1 and 2 in my code), and 2 ways of consuming the VM in a view (alternatives 3 and 4 in my code). Using the flow-diagram I can't determine which is best.
Here's the crux of my #Observable problem.
import SwiftUI
// MARK: - Model
struct MyMod {
var title = "Hello, World!"
}
// MARK: - MVV
@Observable
class MyMVV {
var model: MyMod
init() {
self.model = MyMod()
}
}
// MARK: - App
@main
struct MyApp: App {
@Bindable var myGlobalMVV = MyMVV() // Alternative 1
// @State var myGlobalMVV = MyMVV() // Alternative 2
var body: some Scene {
WindowGroup {
ContentView()
.environment(myGlobalMVV) // inject
}
}
}
struct ContentView: View {
var body: some View {
ContentDeepHierarchyView()
}
}
struct ContentDeepHierarchyView: View {
@Environment(MyMVV.self) var myGlobalMVV // digest
var body: some View {
@Bindable var myLocalMVV = myGlobalMVV // Alternative 3
TextField("The new title", text: $myLocalMVV.model.title) // Alternative 3
TextField("The new title", text: Bindable(myGlobalMVV).model.title) // Alternative 4
}
Opinions?
Hello,
I have these two errors in this particular block of code: Capture of 'self' with non-sendable type 'MusicPlayer?' in a @Sendable closure and Capture of 'localUpdateProgress' with non-sendable type '(Double, Double) -&gt; Void' in a @Sendable closure
` @MainActor
func startProgressTimer(updateProgress: @escaping (Double, Double) -&gt; Void) {
timer?.invalidate() // Stop any existing timer
let localUpdateProgress = updateProgress
timer = Timer.scheduledTimer(withTimeInterval: 1.0, repeats: true) { [weak self] _ in
guard let self = self,
let audioPlayer = self.audioPlayer,
let currentItem = audioPlayer.currentItem else {
print("currentItem is nil or audioPlayer is unavailable")
return
}
let currentTime = currentItem.currentTime().seconds
let duration = currentItem.duration.seconds
localUpdateProgress(currentTime, duration)
}
}`
I've tried nearly every solution and can't think of one that works. Any help is greatly appreciated :)
I have a view controller that is hosing a WKWebView. My view controller overrides buildMenu(with builder: UIMenuBuilder), and prior to the beta, this was called reliably. However under 18.2 beta 4, it is not called at all, despite no code changes on my part.
Things I've tried:
Ensured that my responder chain is set up correctly.
Walked through the debugger via a symbolic breakpoint on [UIResponder buildMenuWithBuilder:] to understand that the web view is the last object to get a buildMenuWithBuilder message.
Any feedback or commiseration would be appreciated.
Hello, following is the issue: I have a @Observable view model which has an array of @Observable Items.
Tapping an item leads to a detail like view to submit a value to the item. This work thru bindings. However I have the need to replace the contents of the array entirely with a fresh version loaded from the network. It will contain the "same" objects with the same id but some values might have changed. So replacing the entire array seems to not update the UI because the IDs are the same as before. Also this seems to break the bindings because when replacing the array, editing no longer updates the UI.
How to test the behavior:
Launch the app in simulator.
Add some values to the items by tapping on an item and then on add.
Notice how changes are updated.
Tap the blue button to sync fresh data to the array. (Not replacing the actual array)
Confirm everything is still working
Replace the array with the red button.
Editing and UI updates are broken from now on.
What is the proper way to handle this scenario?
Project: https://github.com/ChristianSchuster/DTS_DataReplaceExample.git
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 NsTextList and it has [NsTextListElement], I want to replace an NsTextListElement with other element like NsTextParagraph or NstextListElement or an AttributedString. For some reason the below method is not working at all. And I couldn't find any alternate way of replacing the elements
textLayoutManager.replaceContents(in: element.elementRange, with: NSAttributedString(string: "happy"))
I'm playing around with using an app to automate some of my personal work flows, and one of the things I wanted to do was to be able to drag a .webloc file onto my app icon in the dock, to launch it.
I've got public.data set up as a document type for it in Xcode, which translated to
<key>CFBundleDocumentTypes</key>
<array>
<dict>
<key>CFBundleTypeRole</key>
<string>Viewer</string>
<key>LSHandlerRank</key>
<string>Default</string>
<key>LSItemContentTypes</key>
<array>
<string>public.data</string>
</array>
</dict>
</array>
in the Info.plist for it, which seems correct. When I drag a .webloc file onto the Dock icon, it appears to be willing to accept it, but nothing seems to happen.
In the app, I've got an AppDelegate.swift file which has
extension Notification.Name {
static let receivedURLsNotification = Notification.Name("ReceivedURLsNotification")
}
class AppDelegate: NSObject, NSApplicationDelegate {
func application(_ application: NSApplication, open urls: [URL]) {
guard !urls.isEmpty else { return }
NotificationCenter.default.post(name: .receivedURLsNotification, object: nil, userInfo: ["URLs": urls])
}
}
(I copied it almost verbatim from a Medium post.)
In the app swift file, I have
@main
struct LoggerApp: App, DropDelegate {
@NSApplicationDelegateAdaptor(AppDelegate.self) var appDelegate
I set a breakpoint on application(_:NSApplication, open:[URL]), and did my drag, and the breakpoint never triggered.
I added the application(didFinishLaunching(_:Notification) method, and that does get invoked when the app launches, so the app delegate does seem to be working. That seems to indicate the problem is somewhere else?
I am developing a library for RichTextEditor for SwiftUI, and I am facing issues with implementing NSParagraphStyle related features like nested bullet lists and text alignment. I have searched a lot and personally feel that the documentation is not enough on this topic, so here I want to discuss how we can achieve the nested list with UI/NSTextView and natively available NSTextList in NSParagraphStyle.textLists. The problem is I am not able to understand how I can use this text list and how to manage adding list and removing list with my editor
I have seen code that work adding attributes to each string and then merge them, but I don't want that, I want to add/update/remove attributes from selected text and if text is not selected then want to manage typing attributes to keep applied attributes to current position
To store the data, I used the following api:
(nullable UIPasteboard *)pasteboardWithName:(UIPasteboardName)pasteboardName create:(BOOL)create
The official document says that starting from iOS10, clipboard data does not support persistence, but from the test practice, I use this clipboard to save the data always exists, no matter uninstall and reinstall the APP, restart the phone, or even update the system, then what scenarios may lead to the clipboard data is deleted, using this scheme to store data is reliable?
程序从服务端获取有透明图片的pdf(Data格式)文档后, 通过PDFDocument(data: pdfData!) 加载pdf,显示正常,当我用document?.dataRepresentation()将显示的pdf转换为Data格式后再传给服务端,此时的pdf上的透明图片背景变成黑色了。只有在ios18的iPad上有此问题,ios18以下系统iPad和iPhone无此问题, ios18的iPhone也没有此问题
Topic:
UI Frameworks
SubTopic:
UIKit
Greetings all,
Would anyone be able to assist and tell me why on my desktop Button( auto completion shows 1 choice
() (action: @escaptin () -> Void, label: @escaping () -> Label)
while on my laptop, Button( auto completion shows more choices, starting with
I (_ configuration:)
I (action:label:)
etc....
How do I get my desktop to act like my laptop?
Hi,
I'm trying to build iOS app, but I found out that .onPreferenceChange has strange behaviour if the view contains an if statement below view which sets .preference.
Here is an repository with minimal reproduction: https://github.com/Mordred/swiftui-preference-key-bug
There should be displayed title text on the top and bottom of the screen. But the bottom is empty.
If you delete if statement if true { at https://github.com/Mordred/swiftui-preference-key-bug/blob/main/PreferenceKeyBug/PreferenceKeyBug.swift then it works fine.
Hello everyone!
I was implementing a MFMessageComposeViewController to send messages.
Currently I'm observing behaviour that attachments button is always disabled. But thing is that I'm showing MFMessageComposeViewController only when canSendText() && canSendAttachments() are true.
if MFMessageComposeViewController.canSendText() && MFMessageComposeViewController.canSendAttachments() {
let composeVC = MFMessageComposeViewController()
composeVC.messageComposeDelegate = self
composeVC.body = "Test message"
self.present(composeVC, animated: true, completion: nil)
}
I've checked that mms are enabled.
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.
Hi, need some help with an iOS application we are trying to make future safe. Basically, we know that our app would require SwiftUI so the app is made in that framework, however we require some important elements that are available only in UIKit, so we've made a bridge that allows us to pass UIKit views to SwiftUI to display them. So most of the app actually has UI made in UIKit, however, we now need to use the Charts framework present in SwiftUI, we've used SwiftUI buttons in our UIKit before by passing them through a HostingController (Passing SwiftUI buttons to UIKit to use). And we are currently considering to the same for SwiftUI Charts. Just to recap, it's a SwiftUI iOS app, that is mostly made in UIKit (through a bridge) but also has other SwiftUI elements injected into it. What we want to know that, is this the best way to do this? Or is there a better way to have UIKit and SwiftUI work more comfortably with eachother. The reason for such looping around is also because we interoping our C++ code to Swift for making this application, since we are making it for many other platforms and the business logic is in C++. Let me know if there are better ways to go about this!
This is a reproducible issue, create a blank project and put a cell inside a scrollview lazyVstack, I need to have the confirmation dialog on the button or else on iPad it will crash but having the .confirmationDialog inside the lazyVstack leads to unexpected behavior. If you try to click through the cells from 1-10 the .confirmationDialog will stop working after a few taps on the cells. Not sure what the workaround is I'm trying to do something similar in my app with post cells and it's just not working well. I've also noticed that a similar thing happens with .alert if you have it inside the LazyVStack.
struct ContentView: View {
var body: some View {
ScrollView {
LazyVStack {
ForEach(0..<10) { number in
cell(number: number)
}
}
}
}
}
struct cell: View {
@State private var isShowingDialog: Bool = false
let number : Int
var body : some View {
Button {
print("Tapped Cell")
isShowingDialog.toggle()
} label: {
Text("\(number)")
.frame(height: 200)
.frame(maxWidth: .infinity)
.border(.black)
}
.padding(.horizontal, 16)
.confirmationDialog("Options", isPresented: $isShowingDialog, titleVisibility: .visible) {
Button("Some Button", role: .destructive) {
print("Did Tap Option Button")
}
Button("Some Other Button") {
print("Did Tap Other Option Button")
}
}
}
}
My picker looks like this:
Picker("Color", selection: $backgroundColor.animation(), content: {
ForEach(TransactionCategory.Colors.allCases, id: \.self) { color in
Text(color.rawValue)
.tag(color)
.foregroundStyle(color.getColor())
}
})
This changes a tint color which is applied to the entire tabview. I can see that it's working because the buttons in the top tab bar are changing color as I change the picker value. However, the color of the text inside the picker is not changing until I go back one view and then come back to this view. I tried setting an ID on the picker and then updating it when the picker value changes, but that didn't work.
Any ideas?
Wrapping views with a VStack breaks animation, but using an extension to do the same thing fixes it.
I was having issues with views transitioning between being visible and not visible inside of List. They would appear, but the animation would be jerky. I switched to using a Section, and the animation looked much better. However, the spacing between views and padding wasn't what I wanted. So I wrapped some of the views inside the Section with a VStack.
But first, this is how my view SectionView looks:
struct SectionView<Content: View>: View {
let title: String
@ViewBuilder var content: () -> Content
var body: some View {
Section {
Text(title)
.font(.title3.bold())
content()
}
.listRowInsets(EdgeInsets(top: 10, leading: 20, bottom: 10, trailing: 20))
.listRowBackground(Color.clear)
.listRowSeparator(.hidden)
.contentShape(.rect)
}
}
Below was in a separate view:
SectionView(title: "Title") {
Group {
HStack {
// Stuff here
}
if let selectedMonth {
VStack(alignment: .leading, spacing: 10) {
// Stuff here
}
}
}
.animation(.smooth, value: selectedMonth)
}
This, however, broke the animations again when the VStack appears. It went back to being jerky. So instead of wrapping the content inside of a VStack, I created an extension to do the same thing.
extension View {
@ViewBuilder
func condensed() -> some View {
VStack(alignment: .leading, spacing: 10, content: {
self
})
}
}
So now instead of wrapping it in a VStack, I do this:
if let selectedMonth {
Group {
// Stuff here
}
.condensed()
}
The animations look good again. I just can't figure out why that is. Can anyone help me understand this?