Construct and manage graphical, event-driven user interfaces for iOS or tvOS apps using UIKit.

UIKit Documentation

Post

Replies

Boosts

Views

Activity

App crashing randomly - Not possible to remove variable
** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Not possible to remove variable: 400: unknown var (bug!) with engine as delegate:0x283c8ed40{id: 33112} colIndex:32 from engine NSISEngine: 0x129248130{ delegate:0x12934eaa0 EngineVars:  0: objective{id: 33102} rowIndex:0  1: UIImageView:0x12924ec90.Height{id: 32592} rowIndex:1073741824  2: 0x280a04be0.marker{id: 32591} colIndex:1073741825  3: UIImageView:0x12924ec90.Width{id: 32807} rowIndex:1  4: 0x280dc35a0.posErrorMarker{id: 32871} colIndex:1  5: 0x280dc35a0.negError{id: 32872} rowIndex:88  6: 0x280dc3d80.posErrorMarker{id: 32873} colIndex:1073741826  7: 0x280dc3d80.negError{id: 32874} rowIndex:1073741825  8: UIImageView:0x129353f00.Width{id: 32594} rowIndex:2  9: 0x280979d60.marker{id: 32593} colIndex:3 10: 0x280dc1e60.posErrorMarker{id: 32875} colIndex:4 11: 0x280dc1e60.negError{id: 32876} rowIndex:3 12: UIImageView:0x129353f00.Height{id: 32822} rowIndex:1073741826 13: 0x280dc39c0.posErrorMarker{id: 32877} colIndex:1073741827 14: 0x280dc39c0.negError{id: 32878} rowIndex:1073741898 15: UIButton:0x1293540d0.Width{id: 32817} rowIndex:4 16: 0x280dc2040.posErrorMarker{id: 32879} rowIndex:93 17: 0x280dc2040.negError{id: 32880} colIndex:6 18: UIButton:0x1293540d0.Height{id: 32820} rowIndex:1073741827 19: 0x280dc3de0.posErrorMarker{id: 32881} rowIndex:96 20: 0x280dc3de0.negError{id: 32882} colIndex:1073741830 21: UILabel:0x129353300.Width{id: 32811} rowIndex:5 22: 0x280dc3e40.posErrorMarker{id: 32883} colIndex:44 23: 0x280dc3e40.negError{id: 32884} rowIndex:90 24: UILabel:0x129353300.Height{id: 32842} colIndex:1073741828 25: 0x280dc27c0.posErrorMarker{id: 32885} colIndex:1073741831 26: 0x280dc27c0.negError{id: 32886} rowIndex:1073741828 27: UILabel:0x129353c90.Width{id: 32840} rowIndex:6 28: 0x280dc1da0.posErrorMarker{id: 32887} colIndex:9 29: 0x280dc1da0.negError{id: 32888} rowIndex:97 30: UILabel:0x129353c90.Height{id: 32829} colIndex:1073741832 31: 0x280dc31e0.posErrorMarker{id: 32889} colIndex:1073741833 32: 0x280dc31e0.negError{id: 32890} rowIndex:1073741900 33: UIImageView:0x12934e490.Width{id: 32596} rowIndex:1073741905 34: UIImageView:0x12934e490.Height{id: 32597} colIndex:1073741844 35: 0x280963a70.marker{id: 32595} colIndex:11 36: 0x280dc2ee0.posErrorMarker{id: 32891} colIndex:12 37: 0x280dc2ee0.negError{id: 32892} rowIndex:8 38: 0x280dc1d40.posErrorMarker{id: 32893} colIndex:1073741835 39: 0x280dc1d40.negError{id: 32894} rowIndex:1073741830 40: UIButton:0x1293543b0.Width{id: 32832} rowIndex:9 41: 0x280dc1440.posErrorMarker{id: 32895} colIndex:0 42: 0x280dc1440.negError{id: 32896} rowIndex:1073741845 43: UIButton:0x1293543b0.Height{id: 32827} rowIndex:1073741831 44: 0x280dc3840.posErrorMarker{id: 32897} colIndex:1073741836 45: 0x280dc3840.negError{id: 32898} rowIndex:1073741829 46: UILabel:0x129353a20.Width{id: 32848} rowIndex:10 and another thousand or so lines. this crash occurs after I change the language and open the workout page to start a workout immediately, and sometimes on the second time, I open the workout page.
10
0
5.6k
Feb ’21
Is it OK to use UIDocument for a shoebox-style app?
I have an existing app which uses a JSON-based file format currently saved to Application Support (so not user visible). It only needs a single data store per-user. I would like to integrate it with iCloud to make this file available on other devices. Is it considered acceptable to use UIDocument on its own for loading/saving the single file? By this I mean without using UIDocumentBrowserViewController or another file picker. Just my app loading right into the main UI but using UIDocument to open/read/save/close the data file. I am hoping this would allow me to let UIDocument do most of the boilerplate work around NSFileCoordinator and NSFilePresenter. Can anyone confirm if this is a thing that is known to be OK? Or am I going against the frameworks here?
1
0
672
Jun ’21
App Hanging with CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION
Hi, One of our users is having an issue with our iOS App hanging consistently. The trace produced is not always the same but some parts are consistent between hangs. We have not been able to reproduce on our end. One sample stack trace from user is: CrashReporter Key: bf76ea06932831ef2338cbe2b08c552b6140ef83 Hardware Model: iPhone12,3 Version: 100.0.0 Role: Foreground OS Version: iOS 14.6 App Hang: The app was terminated while unresponsive 0 libsystem_kernel.dylib ___psynch_cvwait 1 libsystem_pthread.dylib __pthread_cond_wait 2 Metal -[_MTLCommandBuffer waitUntilCompleted] 3 CoreImage CI::MetalContext::readback_bitmap(CI::Bitmap*, CI::swizzle_info) 4 CoreImage ____ZN2CI16image_get_bitmapEPNS_7ContextEPNS_5ImageE6CGRectP12CGColorSpacePNS_6BitmapEPKNS_17RenderDestinationE_block_invoke 5 CoreImage CI::recursive_tile(CI::RenderTask*, CI::Context*, CI::RenderDestination const*, char const*, CI::Node*, CGRect const&, CI::PixelFormat, CI::swizzle_info const&, CI::TileTask* ( block_pointer)(CI::ProgramNode*, CGRect)) 6 CoreImage CI::tile_node_graph(CI::Context*, CI::RenderDestination const*, char const*, CI::Node*, CGRect const&, CI::PixelFormat, CI::swizzle_info const&, CI::TileTask* ( block_pointer)(CI::ProgramNode*, CGRect)) 7 CoreImage CI::image_get_bitmap(CI::Context*, CI::Image*, CGRect, CGColorSpace*, CI::Bitmap*, CI::RenderDestination const*) 8 CoreImage -[CIContext render:toBitmap:rowBytes:bounds:format:colorSpace:] 9 CoreUI -[CUIShapeEffectStack _newFlattenedImageFromShapeCGImage:withScale:ciContext:blendOverImage:] 10 CoreUI -[CUICatalog imageByStylingImage:stylePresetName:styleConfiguration:foregroundColor:scale:] 11 UIKitCore -[UIImage _imageWithStylePresets:tintColor:traitCollection:] 12 UIKitCore -[UIImageView _renditionForSource:size:withCGImageProvider:lazy:] 13 UIKitCore -[_UIImageContentContextualEffect _renditionWithCGImageProvider:size:lazy:] 14 UIKitCore -[_UIImageContent renditionWithSize:scale:applyingEffect:] 15 UIKitCore -[_UIImageContent renditionApplyingEffect:] 16 UIKitCore -[_UIImageCGImageContent renditionApplyingEffect:] 17 UIKitCore -[_UIImageContentLayout _materializeContentsIfNeeded] 18 UIKitCore -[_UIImageContentLayout contentsMultiplyColor] 19 UIKitCore -[UIImageView _updateContentsMultiplyColorAndSwizzleFromLayout:] 20 UIKitCore -[UIImageView _setImageViewContents:] 21 UIKitCore -[UIImageView _updateState] 22 UIKitCore +[UIView(Animation) performWithoutAnimation:] 23 UIKitCore -[UIImageView _updateImageViewForOldImage:newImage:] 24 UIKitCore -[UIImageView setImage:] 25 UIKitCore -[UIButton _updateImageView] 26 UIKitCore -[UIButton layoutSubviews] 27 UIKitCore -[UIView(CALayerDelegate) layoutSublayersOfLayer:] 28 QuartzCore -[CALayer layoutSublayers] 29 QuartzCore CA::Layer::layout_if_needed(CA::Transaction*) 30 QuartzCore CA::Layer::layout_and_display_if_needed(CA::Transaction*) 31 QuartzCore CA::Context::commit_transaction(CA::Transaction*, double, double*) 32 QuartzCore CA::Transaction::commit() 33 QuartzCore CA::Transaction::observer_callback(__CFRunLoopObserver*, unsigned long, void*) 34 CoreFoundation ___CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ 35 CoreFoundation ___CFRunLoopDoObservers 36 CoreFoundation ___CFRunLoopRun 37 CoreFoundation _CFRunLoopRunSpecific 38 GraphicsServices _GSEventRunModal 39 UIKitCore -[UIApplication _run] 40 UIKitCore _UIApplicationMain 42 libdyld.dylib _start What could be causing the above? Thanks in advance for your help.
2
0
1.7k
Jun ’21
Does changing app display name changes its URL on the app store?
I want change display name of the app (the one which is displayed below the app icon on user's device). I do not intend to change the app's name or its bundle identifier. I know how to do it, but want to know if this will also affect the URL of my app on the app store? Reason I ask this is I already have published QR codes directing to my app on the app store. If changing the app's display name is also going to change these URLs, then I will need to publish new QR codes.
3
1
1.1k
Jul ’21
UIApplication.willEnterForegroundNotification not fired when Notification Center puts app in background
Using addObserver func of NotificationCenter.default, subscribing to UIApplication.willEnterForegroundNotification does not work when the backgrounding is triggered from Notification Center (swipe down from top when app is active to get Notification Center).  It also seems that UIApplication.willResignActiveNotification is called twice, based on Print() logs, when Notification Center triggers the backgrounding. If you background the app via lock screen or manual swipe, or switch to another app, the UIApplication.willEnterForegroundNotification does get called, so it seems to be specific to Notification Center. UIApplication.willResignActiveNotification does fire correctly but then resuming the app never calls the appMovedToForeground func below: notificationCenter.addObserver(self, selector: #selector(appMovedToForeground), name: UIApplication.willEnterForegroundNotification,object: nil) occurs on: iOS 14.4.2, iPhone 11 & iOS 14.6, SE(2)
3
0
4.7k
Jul ’21
Constrain view's top anchor to just at the edge of sensor housing
What might be a good way to constrain a view's top anchor to be just at the edge of a device's Face ID sensor housing if it has one? This view is a product photo that would be clipped too much if it ignored the top safe area inset, but if it was positioned relative to the top safe area margin this wouldn't be ideal either because of the slight gap between the sensor housing and the view (the view is a photo of pants cropped at the waist). What might be a good approach here?
0
0
943
Aug ’21
accessibilityTextHeadingLevel not working in NSAttributedString
Hey guys, I have an NSAttributedString within my app (created from HTML). I assign this string to a UITextView. I would like certain parts of that text to be marked with an 'header' accessibility trait (all the headlines in that text) so that voice over can identify them properly. I was under the impression that I can just use accessibilityTextHeadingLevel to do so, but the text in that given range is still setup with the 'text' accessibility trait: var myString = NSMutableAttributedString(...) let range = NSRange(location: 0, length: 44) myString.addAttribute(NSAttributedString.Key.accessibilityTextHeadingLevel, value: 1, range: range) How is accessibilityTextHeadingLevel supposed to work?
3
0
987
Sep ’21
How do you apply a diffable data source UI snapshot only after awaiting (with async/await) data fetched from the network?
I'm new to async/await, and am currently migrating my completion handler code to Swift 5.5's concurrency features. After generating an sync alternative in Xcode to my function func fetchMatchRecords(completion: @escaping ([Match]) -> Void), it becomes func fetchMatchRecords() async -> [Match]. I'm not sure how it would be used in the context of UIKit and diffable data sources. In a viewDidLoad, previously it would be MatchHistoryController.shared.fetchMatchRecords() { matches in DispatchQueue.main.async { self.dataSource.apply(self.initialSnapshot(), animatingDifferences: false) } } But I'm not sure how it would be used now Task { await MatchHistoryController.shared.fetchMatchRecords() } self.dataSource.apply(self.initialSnapshot(), animatingDifferences: false) How would I make sure that the snapshot is applied only after awaiting a successful fetch result? Here's the definition of initialSnapshot() that I used: func initialSnapshot() -> NSDiffableDataSourceSnapshot<Section, Match> { var snapshot = NSDiffableDataSourceSnapshot<Section, Match>() snapshot.appendSections([.main]) snapshot.appendItems(MatchHistoryController.shared.matches) return snapshot }
1
0
1.6k
Sep ’21
Metal + UIKit Timing Issues
Hi! I am currently finalizing a new app that uses Metal to render a 3D scene and a UIKit overlay to display controls for interacting with objects in the scene. The render loop is driven via a CADisplayLink with its preferredFramesPerSecond set to 60. I have recently noticed an issue where the app reports a steady 60 fps frame rate in the Xcode debug navigator, but still felt sluggish on the device. This feeling was only present on devices with ProMotion and often started after interactions with the UIKit overlay. I started investigating by using Metal System Trace and quickly found an explanation for the sluggish feeling: occasionally, the app would switch from its nominal 16ms-16ms-16ms cadence to 12ms-20ms-12ms, thus still averaging 60 fps, but with inconsistent frame times. Pictures of the timeline can be found here. I have tried setting the CAMetalLayer's presentsWithTransaction to true, waiting for the command buffer to be scheduled and then presenting the drawable, but, unfortunately, the problem persists. If anybody can think of a potential reason / solution for this, I would be very thankful.
5
0
2.5k
Jan ’22
What does this UICollectionView exception mean?
In my application using UICollectionViewDiffableDataSource and compositional layout, I saw this exception Thread 1: "This solver does not handle estimated items so this method does nothing. Are you calling this in error?" that was thrown in dataSource.apply(snapshot, animatingDifferences: animated). I don't understand what it is telling me and how I should fix it. Any idea?
4
0
1k
Feb ’22
UISplitViewController and UITabBarController in iOS 15 is always full screen
I'm reworking my app and update code and design. Because my app is one both iPhone and iPad, i'm using Splitview to handle the configurations. But my app has 4 section that I manage using a Tab bar and each tab has a SplitView. As you can see in images, the problem is that if I attach directly the UISplitViewController to UITabBarController you don't see two columns but only one (the primary or secondary view) both iPhone landscape orientation and iPad. A solution that I found is to attach the splitviewcontroller to a view that contains a ContainerViewController e connect the split view to this container. If you do this, you see the split view work correctly ma the problem is the customization of appearance (look at image 3) So may questions are: why I have to embed a split view in a container view controller and i can't connect it directly to tabbar as we done until now? Is there an other better solution then put a split view in a containerView? Thank you )
2
0
1.6k
Mar ’22
Why does a MainActor class / function not run on Main Thread?
When marking the ViewController and the function with @MainActor, the assertion to check that the UI is updated on main thread fails. How do I guarantee that a function is run on Main Thread when using @MainActor? Example code: import UIKit @MainActor class ViewController: UIViewController {     let updateObject = UpdateObject()     override func viewDidLoad() {         super.viewDidLoad()                  updateObject.fetchSomeData { [weak self] _ in             self?.updateSomeUI()         }     }     @MainActor     func updateSomeUI() {         assert(Thread.isMainThread) // Assertion failed!     } } class UpdateObject {     func fetchSomeData(completion: @escaping (_ success: Bool) -> Void) {         DispatchQueue.global().async {             completion(true)         }     } } Even changing DispatchQueue.global().async to Task.detached does not work. Tested with Xcode 13.2.1 and Xcode 13.3 RC
5
0
2.2k
Mar ’22
The application crashes in the App Store when launch on iPhone with iOS 15.3.1.
My application is currently crashing in production in iPhone devices running iOS 15.x. The app will work as normal while running developer mode, enterprise builds and Test Flight builds. Unfortunately, I am unable to reproduce this issue even app is downloaded from the app store. I observed crash is happening at main.m. Can someone help me to reproduce this issue? How to read this crash log file? Please find the crash log details attached. 2022-03-04_14-15-23.6227_+0900-a1899fd803a4ed683466702be71b9d224b4cd5bc.crash
3
1
2.4k
Mar ’22
Could not find a navigation controller for segue. Random Crash for years now...
I've been seeing this crash happening for a few years now. It's rare and unreproducible. The App's storyboard is large and it can occur on any segue and randomly it seems Could not find a navigation controller for segue 'some-segue-on-storyboard'. Push segues can only be used when the source controller is managed by an instance of UINavigationController. I've tried various things to prevent it. Double checked it was on the main thread to keep the UI happy and assumed all this time that it was just an iOS glitch/bug that Apple would get around to fixing. That or it is a side effect of low memory. Anyone got any suggestions for how to fix or what to investigate?
5
0
786
Mar ’22
UICollectionViewDiffableDataSource apply snapshot calls willDisplay for all cells
I have some code which currently assumes that UICollectionViewDelegate - collectionView(_: UICollectionView, willDisplay _: UICollectionViewCell, forItemAt indexPath: IndexPath) will be called as the user scrolls through the collection view and cells are about to be displayed on-screen. However on refactoring this screen to use the UICollectionViewDiffableDataSource APIs I noticed that willDisplay is called for every indexPath in the collection view's data as a result of calling UICollectionViewDiffableDataSource apply`. This is reproducible in Apple's sample app Updating Collection Views Using Diffable Data Sources running on iOS 15. Is this behaviour intentional? Is there another reliable way to be informed of when a cell is about to be displayed as the user is scrolling through the collection view? As a workaround I am using a boolean flag to indicate when the data source is updating and setting that to false in the completion of UICollectionViewDiffableDataSource apply. Many thanks!
5
0
1.9k
May ’22
iOS 15 prewarming and didFinishLaunchingWithOptions
Hi, Just want to understand what is the current state of iOS 15 prewarming app delegate behaviour. There is a lot of confusion (and a lack of documentation) about which app delegate methods are called during prewarming. It's not clear if didFinishLaunchingWithOptions will be called or not during prewarming. A lot of applications are counting on UserDefaults and Keychain access in didFinishLaunchingWithOptions, but sadly these two features seems to be unavailable during prewarming causing issues. Some users say that this was the case before 15.4 and that from 15.4 the didFinishLaunchingWithOptions app delegate method is no more called during prewarming. Just want to know if we can have an official statement about this. It is safe, from iOS 15.4 onwards, to use UserDefaults and access Keychain in the didFinishLaunchingWithOptions app delegate method? Thank you
1
2
1.7k
May ’22
UITextView erases foreground color of attributedText
This issue is driving me crazy. I load an NSAttributedString in UITextView and within moments after loading the foregroundColor attribute of text is erased(i.e becomes white) without me doing anything. Here is the code and NSLog dump. How do I debug this I wonder? class ScriptEditingView: UITextView, UITextViewDelegate { var defaultFont = UIFont.preferredFont(forTextStyle: .body) var defaultTextColor = UIColor.white private func commonInit() { self.font = UIFont.preferredFont(forTextStyle: .body) self.allowsEditingTextAttributes = true self.textColor = defaultTextColor self.backgroundColor = UIColor.black self.isOpaque = true self.isEditable = true self.isSelectable = true self.dataDetectorTypes = [] self.showsHorizontalScrollIndicator = false } } And then in my ViewController that contains the UITextView, I have this code: textView = ScriptEditingView(frame: newTextViewRect, textContainer: nil) textView.delegate = self view.addSubview(textView) textView.allowsEditingTextAttributes = true let guide = view.safeAreaLayoutGuide // 5 textView.translatesAutoresizingMaskIntoConstraints = false NSLayoutConstraint.activate([ textView.leadingAnchor.constraint(equalTo: guide.leadingAnchor), textView.trailingAnchor.constraint(equalTo: guide.trailingAnchor), textView.topAnchor.constraint(equalTo: view.topAnchor), textView.bottomAnchor.constraint(equalTo: view.bottomAnchor) ]) textView.attributedText = attributedString NSLog("Attributed now") dumpAttributesOfText() DispatchQueue.main.asyncAfter(deadline: .now() + 1.0) { NSLog("Attributes after 1 sec") self.dumpAttributesOfText() } And here is code to dump attributes of text: private func dumpAttributesOfText() { textView.attributedText?.enumerateAttributes(in: NSRange(location: 0, length: textView.attributedText!.length), options: .longestEffectiveRangeNotRequired, using: { dictionary, range, stop in NSLog(" range \(range)") if let font = dictionary[.font] as? UIFont { NSLog("Font at range \(range) - \(font.fontName), \(font.pointSize)") } if let foregroundColor = dictionary[.foregroundColor] as? UIColor { NSLog("Foregroundcolor \(foregroundColor) at range \(range)") } if let underline = dictionary[.underlineStyle] as? Int { NSLog("Underline \(underline) at range \(range)") } }) } The logs show this: 2022-07-02 13:16:02.841199+0400 MyApp[12054:922491] Attributed now 2022-07-02 13:16:02.841370+0400 MyApp[12054:922491] range {0, 14} 2022-07-02 13:16:02.841486+0400 MyApp[12054:922491] Font at range {0, 14} - HelveticaNeue, 30.0 2022-07-02 13:16:02.841586+0400 MyApp[12054:922491] Foregroundcolor UIExtendedGrayColorSpace 1 1 at range {0, 14} 2022-07-02 13:16:02.841681+0400 MyApp[12054:922491] range {14, 6} 2022-07-02 13:16:02.841770+0400 MyApp[12054:922491] Font at range {14, 6} - HelveticaNeue, 30.0 2022-07-02 13:16:02.841855+0400 MyApp[12054:922491] Foregroundcolor kCGColorSpaceModelRGB 0.96863 0.80784 0.27451 1 at range {14, 6} 2022-07-02 13:16:03.934816+0400 MyApp[12054:922491] Attributes after 1 sec 2022-07-02 13:16:03.935087+0400 MyApp[12054:922491] range {0, 20} 2022-07-02 13:16:03.935183+0400 MyApp[12054:922491] Font at range {0, 20} - HelveticaNeue, 30.0 2022-07-02 13:16:03.935255+0400 MyApp[12054:922491] Foregroundcolor UIExtendedGrayColorSpace 1 1 at range {0, 20}
1
0
1k
Jul ’22