Post

Replies

Boosts

Views

Activity

Can I give additional context to Foundation Models?
I'm interested in using Foundation Models to act as an AI support agent for our extensive in-app documentation. We have many pages of in-app documents, which the user can currently search, but it would be great to use Foundation Models to let the user get answers to arbitrary questions. Is this possible with the current version of Foundation Models? It seems like the way to add new context to the model is with the instructions parameter on LanguageModelSession. As I understand it, the combined instructions and prompt need to consume less than 4096 tokens. That definitely wouldn't be enough for the amount of documentation I want the agent to be able to refer to. Is there another way of doing this, maybe as a series of recursive queries? If there is a solution based on multiple queries, should I expect this to be fast enough for interactive use?
4
0
209
1w
In iOS 26, the tab bar never disappears when new controller is pushed
In my app, I have a tab bar controller whose first tab is a navigation controller. Taking a certain action in that controller will push a new controller onto the navigation stack. The new controller has hidesBottomBarWhenPushed set to true, which hides the tab bar and shows the new controller's toolbar. It's worked like this for years. But in the iOS 26 simulator (I don't have the beta installed on any physical iPhones yet), when I tried this behavior in my app, I instead saw: the tab bar remained exactly where it was when I pushed the new controller the toolbar never appeared at all and all of its buttons were inaccessible If you set the deployment target to iOS 18 and run the code in an iOS 18 simulator: when you tap "Tap Me", the new controller is pushed onto the screen simultaneously, the tab bar hides and the second controller's toolbar appears. If you set the deployment target to iOS 26 and run the code in an iOS 26 simulator: when you tap "Tap Me", the new controller is pushed onto the screen the toolbar never appears and the tab bar remains unchanged after the push animation completes Is this a bug in the iOS 26 beta, or is it an intentional behavior change in how hidesBottomBarWhenPushed works in these cases? Below is sample code that reproduces the problem: class TabController: UIViewController { override func viewDidLoad() { super.viewDidLoad() let button = UIButton(type: .roundedRect, primaryAction: UIAction(title: "Test Action") { action in let newController = SecondaryController() self.navigationController!.pushViewController(newController, animated: true) }) button.setTitle("Tap Me", for: .normal) button.translatesAutoresizingMaskIntoConstraints = false self.view.addSubview(button) NSLayoutConstraint.activate([ self.view.centerXAnchor.constraint(equalTo: button.centerXAnchor), self.view.centerYAnchor.constraint(equalTo: button.centerYAnchor), ]) } } class SecondaryController: UIViewController { override func loadView() { super.loadView() self.toolbarItems = [ UIBarButtonItem(image: UIImage(systemName: "plus"), style: .plain, target: nil, action: nil) ] } override func viewWillAppear(_ animated: Bool) { super.viewWillAppear(animated) self.navigationController?.isToolbarHidden = false } } class SceneDelegate: UIResponder, UIWindowSceneDelegate { var window: UIWindow? var tabController: UITabBarController? func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) { guard let windowScene = (scene as? UIWindowScene) else { return } let tab1 = UITab(title: "Test 1", image: UIImage(systemName: "globe"), identifier: "test1") { _ in UINavigationController(rootViewController: TabController()) } let tab2 = UITab(title: "Test 2", image: UIImage(systemName: "globe"), identifier: "test2") { _ in UINavigationController(rootViewController: TabController()) } window = UIWindow(windowScene: windowScene) self.tabController = UITabBarController(tabs: [tab1, tab2]) self.window!.rootViewController = self.tabController self.window!.makeKeyAndVisible() } }
Topic: UI Frameworks SubTopic: UIKit Tags:
2
1
182
Jun ’25
Safe way to query for the existence of a CKRecordZone?
There's some logic in my app that first checks to see if a specific CloudKit record zone exists. If it doesn't, it creates the zone, and then my application continues on with its work. The way I've implemented this right now is by catching the zoneNotFound error when I call CKDatabase#recordZone(for:) (docs) and creating the zone when that happens: do { try await db.recordZone(for: zoneID) } catch let ckError as CKError where [.zoneNotFound, .userDeletedZone].contains(ckError.code) { // createZone is a helper function try await createZone(zoneID: zoneID, context: context) } This works great, but every time I do this, an error is logged in CloudKit Console, which creates a lot of noise and makes it harder to see real errors. Is there a way to do this without explicitly triggering a CloudKit error? I just found CKDatabase#recordZones(for:) (docs), which seems like it returns an empty array instead of throwing an error if the zone doesn't exist. Will calling that and looking for a non-empty array work just as well, but without logging lots of errors in the console?
1
0
52
Apr ’25
UIContextMenuInteraction not working if view is originally offscreen
I’m having a weird UIKit problem. I have a bunch of views in a UIScrollView and I add a UIContextMenuInteraction to all of them when the view is first loaded. Because they're in a scroll view, only some of the views are initially visible. The interaction works great for any of the views that are initially on-screen, but if I scroll to reveal new subviews, the context menu interaction has no effect for those. I used Xcode's View Debugger to confirm that my interaction is still saved in the view's interactions property, even for views that were initially off-screen and were then scrolled in. What could be happening here?
Topic: UI Frameworks SubTopic: UIKit Tags:
0
0
44
Mar ’25
Odd, transient .badContainer error in CloudKit
I'm beta-testing a CloudKit-based app. One of my testers suddenly reported that they got a .badContainer CloudKit error: <CKError 0x302619800:"Bad Container" (5/1014); server message = "Invalid container to get bundle ids"; op = <...>; uuid = <...>; container ID = "<...>"> (all private info replaced with <...>) The container ID in the message was exactly what I expected, and exactly what other users are successfully using. When I followed up on the report, the user said she tried again later and everything was fine. It's still working fine days later. What could cause a user to get a .badContainer message, when all other users using the same app are fine, the container ID makes sense, and future runs work fine? Is this something I need to worry about? Does it maybe sometimes happen when CloudKit is having some kind of outage?
1
0
637
Jan ’25
Troubles with CFBundleDocumentTypes and photos
I'm working on adding CFBundleDocumentTypes to my Info.plist so that a user can share an image from other apps on their device and have it open inside my iPhone app. I seem to be able to get this to work for sharing a single photo from the Photos app, but not for (1) multiple photos from the Photos app or (2) images from Safari. One thing that makes this difficult is that my changes to Info.plist sometimes have no effect. I can remove CFBundleDocumentTypes and still see the icon, for example. Or I can add a new accepted UTI, but it has no effect. I've tried cleaning and rebuilding, deleting and reinstalling the app...no success. I tried in the simulator, too, and even Erase Content and Settings didn't force changes to be applied. I'm not sure what else to try here. Anyway, I'd like my app to appear in the Share sheet for photo(s) from the Photos app, Mail and Safari, in particular, but really from any app that supports sharing photos. I can share the config that seemed to work, but since changing it doesn't always have an effect, I can't guarantee that this was the one that worked. At the moment, it doesn't work, but I'm not sure why. Here it is: &lt;key&gt;CFBundleDocumentTypes&lt;/key&gt; &lt;array&gt; &lt;dict&gt; &lt;key&gt;CFBundleTypeIconFiles&lt;/key&gt; &lt;array/&gt; &lt;key&gt;CFBundleTypeName&lt;/key&gt; &lt;string&gt;Image&lt;/string&gt; &lt;key&gt;CFBundleTypeRole&lt;/key&gt; &lt;string&gt;Viewer&lt;/string&gt; &lt;key&gt;LSHandlerRank&lt;/key&gt; &lt;string&gt;Alternate&lt;/string&gt; &lt;key&gt;LSItemContentTypes&lt;/key&gt; &lt;array&gt; &lt;string&gt;public.data&lt;/string&gt; &lt;string&gt;public.jpeg&lt;/string&gt; &lt;string&gt;public.png&lt;/string&gt; &lt;string&gt;public.image&lt;/string&gt; &lt;string&gt;public.gif&lt;/string&gt; &lt;string&gt;public.url&lt;/string&gt; &lt;string&gt;public.content&lt;/string&gt; &lt;/array&gt; &lt;/dict&gt; &lt;/array&gt; &lt;key&gt;LSSupportsOpeningDocumentsInPlace&lt;/key&gt; &lt;true/&gt; In my code, I also defined the following method in my SceneDelegate (though I think the problem is just with Info.plist): func scene(_ scene: UIScene, openURLContexts URLContexts: Set&lt;UIOpenURLContext&gt;) { Here are my questions: How do I make sure that my changes to Info.plist apply? Is there a cache somewhere that I have to force to clear? This is the trickiest part of this, because I can't reliably try an experiment and see if it worked. Adding the specific image UTI’s (public.jpeg, public.png) seemed to help, even though those types should conform to public.image, which conforms to public.data and public.content. Is it actually necessary to specify those? If the user selects multiple photos in the Photos app, my app doesn’t appear, but other third-party apps on my phone do. How can I support multiple photos? This configuration doesn't reliably show my app for Safari images - what do I need to do to make that happen? I had to use “public.data” when I briefly had Safari sharing working, but there doesn't seem to be a way to get a UTI from UIOpenURLContext. Right now, my code just tries to load the data as an image and aborts if UIImage(data:) returns nil. Is this a safe way of doing this? Is there a way to get the UTI for the data?
2
0
615
Jan ’25
Open an app from the photos share sheet
I'd like to add a share extension to my app (an Action app extension, I think). The extension would appear when users share a photo in the Photos app (and, ideally, Safari). If you tapped my app icon on the share sheet, iOS would pass the photo to my app and switch the user from Photos or Safari to my full app, with the shared photo(s) available for my app to work with. I know this is possible, because Instagram (a third-party app) works exactly like this. If you look at an image in the Photos app, tap Share and then tap Instagram, iOS will background the Photos app, activate the Instagram app and let you edit and post your photo in the main Instagram app. It seems like NSExtensionContext#open(_:completionHandler:) might do this if I add a custom URL to my main app, but the documentation for that says: Each extension point determines whether to support this method, or under which conditions to support this method. In iOS, the Today and iMessage app extension points support this method. That would rule out an Action, Photo Editing or Share extension. But then how does Instagram do this, and how can I achieve the same in my app? I know that it's possible for an Action, Photo Editing or Share extension to open as a mini-app on top of the app providing the content. But coordinating the IPC for that is much, much more work (for my particular app) than just switching the user over to the app, with full access to all the functionality and data that my main app usually has access to.
0
0
423
Jan ’25
Is it possible to use a list-style UICollectionView but have multiple columns?
I'm working on a UICollectionView that has a custom compositional layout with multiple columns. I wanted to add swipe actions to the cells (specifically, a delete action). I knew this was possible because of the existence of trailingSwipeActionsConfigurationProvider but I didn't realize that this is only for list layouts, created with UICollectionViewCompositionalLayout.list. But if I use a list layout, I don't think I have any opportunity to add multiple columns. Do I really have to choose between multiple columns and trailing swipe actions? Or is there some way to get both?
Topic: UI Frameworks SubTopic: UIKit Tags:
0
0
482
Jul ’24
Detecting Local Network issues with NWListener
I have an application that uses Bonjour to communicate with other instances of the app on other devices. If I start an NWBrowser and the user has "Local Network" turned off for my app, the stateUpdateHandler for the browser gets .waiting with an error containing the string "PolicyDenied." This lets me show an alert to the user explaining what's happening, with a link to the app's Settings screen. But if I use NWListener (the counterpart of NWBrowser) and have "Local Network" turned off, there's no indication of any problem. After I start the listener, stateUpdateHandler is called with .ready as the state - even though it's not really ready to listen at all. The FAQ for Local Network Privacy suggests that any Bonjour operation will raise kDNSServiceErr_PolicyDenied if Local Network is off. However, in my application, that only seems to be true for browsing, not listening. Is there a way to detect a missing Local Network entitlement for NWListener? I know there are solutions involving sending a message to localhost, etc, but ideally there would be something simpler.
1
0
838
Jun ’24
Sendability for Stream, InputStream, etc.
I have a project with some legacy networking code that uses the Stream (formerly NSStream) family of classes, including Stream, InputStream, OutputStream, and StreamDelegate. None of these are sendable, so I get a lot of warnings when implementing delegate methods in a @MainActor class. These classes seem like they could be sendable. Is this something that will happen soon? Is it a bug I should report? The networking code that uses these classes runs great, and hasn't needed changes for years, so my current solution is to just mark these unchecked: extension Stream: @unchecked Sendable { } extension InputStream: @unchecked Sendable { } extension OutputStream: @unchecked Sendable { } This makes the compiler happy, but makes me feel kind of bad. Is there something else I could do?
2
0
725
Jun ’24
How do I handle changes from sync with Swift Data?
In Core Data, you can use a pinned query generation to make sure that your app is working from a consistent view of the data store. If you have CloudKit sync turned on, and new changes come in that invalidate relationships, your app won't see them right away as long as it's looking at a pinned query generation. Since Swift Data doesn't yet support query generations, how do I deal with this issue in Swift Data apps? For example, let's say I have an address book app. I open a particular contact, and then tap a control on the screen that opens a list of images for that contact. While looking at the images, CloudKit sync retrieves changes made by other devices, which have completely removed the parent contact. How does my app know this has happened? Suppose the image browser screen needs to refer to the parent contact, or make changes to it, but the contact is no longer there because a background sync removed it.
1
0
888
Jun ’24
Show a UIMenu on double-tap?
Is there a way to programmatically show a UIMenu on iOS on a double-tap event? I have an app that's been around for over a decade, so there are some UX patterns that I'm reluctant to mess around with. There is a view in my app with the following properties: Tapping the view once focuses it and brings it to the front Double-tapping it shows a view controller as a sheet, with several operations you can perform on that object Instead of the sheet, I'd like to move to context menus - they look better, and they're more familiar for users. Obviously, adding a context menu for long-press is straightforward (just use UIContextMenuInteraction). But there does not seem to be a way to show the context menu on double-tap. I've discovered that you can use UIButton with showsMenuAsPrimaryAction to show the menu on single-tap, but that doesn't quite work for me. My users expect a single tap to do something else (focus the view) and will be annoyed if single taps start showing menus instead. So, is there a way to show a context menu on double tap in iOS?
Topic: UI Frameworks SubTopic: UIKit Tags:
1
0
905
Jun ’24