I try to create a sheet that shows a textfield and the textfield should gain the focus immediately after the sheet is presented. This use case is explained in Session 10162 at 11:21 and at 13:31 my desired behavior is shown. I could not get this to work in my own code and downloaded the sample code from here:
https://developer.apple.com/documentation/swiftui/focus-cookbook-sample
Then I opened the sample code and run it in the simulator. It does not focus when the sheet appears in a iOS 18 simulator using Xcode 16 installed via the AppStore. It does gain focus if I use the "add" Button.
No changes made on the sample code. Just adjusted the Team setting to get a clean build. The behavior I get locally under iOS 18 is not what is shown in the session and I can't understand why.
I tried the following Simulators (and platforms) iPhone 16, iPad Pro (M4, 11inch) and my Mac. On none of those the last item got focus just by presenting the sheet.
Is it not possible to test this in a simulator? Could I have a configuration error? Given all the information I found yet, this seems like a Bug.
It would be very helpful if someone could replicate my problem. Thank you for your help.
Programm Versions:
Xcode: Version 16.0 (16A242d)
MacOS: 15.0 (24A335)
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.
Post
Replies
Boosts
Views
Activity
It seems like it is no longer possible to open the main window of an app after the app has been launched by the system if the "Auto Start" functionality has been enabled.
I am using SMAppService.mainApp to enable to auto start of my app. It is shown in the macOS system settings and the app is automatically started - but the main window is not visible.
How can I change this behaviour so the main window of the app is always visible when started automatically?
I have not noticed this behaviour before the release of macOS Sequoia. My app is using Swift 6 and the latest version of macOS and Xcode.
Regards
As you can see, when I swipe to see the context actions in the collectionview, the searchbar flicks. Same story when, in a popover, i change the PreferredContentSize.
Hi folks,
I’ve been trying to use the new .animation(_:body:) overload without success. I’m attempting to animate multiple properties of a view, each with different animations. This overload seems to be the perfect candidate to achieve that.
Here's the code I'm using:
struct ContentView: View {
@State private var isAnimating = false
var body: some View {
Text("Hello World")
.font(.largeTitle)
.animation(.easeOut(duration: 1)) {
$0.foregroundStyle(isAnimating ? .red : .blue)
}
.animation(.linear(duration: 10)) {
$0.offset(x: isAnimating ? -100 : 0)
}
.onAppear {
isAnimating = true
}
}
}
Pretty straightforward, but I don’t get any animations at all.
Of course, I could wrap isAnimating = true in a withAnimation closure, but the WWDC session about those APIs mentions this is not needed. Furthermore, if I do that, the animations I provide in .animation(_:body:) are not being used.
I’m really confused by this new API, and I’m starting to think it doesn’t work as advertised.
I've been having trouble with finding a good way to allow the user to close the keyboard. Naturally, I'd like to use the keyboard toolbar but it's so inconsistent, it's impossible. Sometimes it shows up, other times it doesn't. At the moment, it's not appearing at all no matter where I put it. On the NavigationStack, on the List inside of it, on the TextField. It just doesn't appear. I added a TapGesture to my view to set my FocusState that I'm using for the fields back to nil, however, this stops the Picker I have from working. I tried using SimultaneousGesture with TapGesture, and that didn't work.
For example:
.simultaneousGesture(
TapGesture()
.onEnded() {
if field != nil {
field = nil
}
}
)
With the current setup, each TextField switches to the next TextField in the onSubmit. The last one doesn't, which will close the keyboard, but I want to give people the option to close the keyboard before that. Does anyone have a good way to close the keyboard?
Hi there,
I'm trying to migrate my app to using the UIDocumentViewController so I can use the new launch experience. My app exports a custom file type and uses UIDocument + UIDocumentBrowserViewController.
I tried creating a UIDocumentViewController and making it the root view of my app but it doesn't recognise my custom document type.
class Document_VC: UIDocumentViewController {
var storyCardsDocument: PlotCardDocument? {
self.document as? PlotCardDocument
}
override func viewDidLoad() {
super.viewDidLoad()
configureViewForCurrentDocument()
}
override func documentDidOpen() {
configureViewForCurrentDocument()
}
func configureViewForCurrentDocument() {
guard let document = storyCardsDocument,
!document.documentState.contains(.closed)
&& isViewLoaded else { return }
print("Document opened: \(document.fileURL)")
}
}
The app opens but when I navigate to a document made in a previous version of the app it is greyed out. I also don't see a 'New' button in the launcher view.
To try and see what I was doing wrong, I tested the markdown app sample code. When I make the UIDocumentViewController the root and try to open or create a new markdown document I get the following error:
no document class found. Define the correct UIDocument subclass with the key UIDocumentClass in the info.plist's CFBundleDocumentTypes dictionary.
When the home screen is in tinted mode in iOS 18, the widget gallery seems to display widgets with the background inset from the edge of the widget (i.e. negative padding).
You can see this behavior in the Apple News widget too, where the full-bleed content outside of the inset is very light. This only happens in the sample gallery, not when the widgets are placed on the home screen.
For my widgets, this outer edge contains important content and the clipping behavior makes the widgets look poorly designed when viewed in the gallery.
Is there any way to turn this behavior off and just show the widget normally in the gallery with no weird inset — the way it will actually display when added to the home screen?
If it matters, my widgets are currently configured with:
.contentMarginsDisabled()
.containerBackground(for: .widget) {
// ... (background color) */
}
Hello. I am having trouble trying to create a control in control center view that opens a specific view in my app using AppIntents (iOS18 )and WidgetKit, can someone help me please? I feel like the original videos and documentations are incomplete.
I am making an IOS application using XCode Storyboard.
I have a UICollectionViewController in the following structure
UIViewController -> UIView -> UITabBarController -> UICollectionViewController
The app loads without crashing, and UICollectionViewController.viewDidLoad() and .numberOfSections() execute correctly.
But anything that I put in
override func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath)
does not seem to execute. Once the app loads, no cells load. And any print statement in the function doesn't execute either.
All elements have their corresponding class correctly assigned in the Storyboard Identity Inspector, and the cells have the correct reusable identifier.
How can I make it work correctly?
My Collection View Controller:
class ValidCardsCollectionViewController: UICollectionViewController {
let dataSource: [String] = ["hearts", "clubs", "diamonds", "spades"]
override func viewDidLoad() {
super.viewDidLoad()
print(dataSource)
}
override func numberOfSections(in collectionView: UICollectionView) -> Int {
print("Loading \(dataSource.count) cells")
return dataSource.count
}
override func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
var cell = UICollectionViewCell()
if let cardCell = collectionView.dequeueReusableCell(withReuseIdentifier: "CardCell", for: indexPath) as? CardCollectionViewCell{
cardCell.configure(with: dataSource[indexPath.row])
cell = cardCell
}
print("loading cell")
return cell
}
My UICollectionViewCell:
class CardCollectionViewCell: UICollectionViewCell {
@IBOutlet weak var lblStr: UILabel!
func configure(with str:String){
lblStr.text = str
}
}
Storyboard layout:
Simulator:
Is there a way to workaround this issue? Can I revert back to Beta 1?
Failed to build module 'Charts'; this SDK is not supported by the compiler (the SDK is built with 'Apple Swift version 6.0 effective-5.10 (swiftlang-6.0.0.7.41 clang-1600.0.24.1)', while this compiler is 'Apple Swift version 6.0 effective-5.10 (swiftlang-6.0.0.9.11 clang-1600.0.26.2)'). Please select a toolchain which matches the SDK.
The following code crashes on macOS 15 Sequoia:
import Foundation
let key = NSAttributedString.Key("org.example.key")
let value = Value()
let string = NSMutableAttributedString()
string.append(NSAttributedString(string: "a", attributes: [:]))
string.append(NSAttributedString(string: "b", attributes: [key: value]))
string.append(NSAttributedString(string: "c", attributes: [:]))
string.enumerateAttribute(key, in: NSRange(location: 0, length: string.length)) { value, range, stop in
print(range)
}
class Value: Equatable, Hashable {
static func == (lhs: Value, rhs: Value) -> Bool {
return lhs === rhs
}
func hash(into hasher: inout Hasher) {
hasher.combine(ObjectIdentifier(self))
}
}
The error is
EXC_BAD_ACCESS (code=1, address=0x0)
I wanted to run it on my external macOS 14 partition to confirm that it didn't crash before updating to macOS 15, but for some reason macOS will just restart and boot again into macOS 15. So I tried with macOS 13, which I was allowed to start for some reason, and I was able to confirm that the code doesn't crash.
Is this a known issue, and is there a workaround? Removing the two lines that add the letters a and c, or just declaring class Value without conformance to Equatable, Hashable, interestingly, solves the issue.
While I am able to use #Preview to preview a Widget, it seems to be not possible to easily preview a Widget placeholder. With a "classic" preview I can use .redacted(reason: .placeholder), but this has limitation e.g. it will ignore .contentMarginsDisabled()
struct MyWidget_Previews: PreviewProvider {
static var previews: some View {
Group {
MyWidgetView(entry: SimpleEntry(date: .now, emoji: "😀"))
MyWidgetView(entry: SimpleEntry(date: .now, emoji: "😀"))
.redacted(reason: .placeholder)
}
.previewContext(WidgetPreviewContext(family: .systemMedium))
.containerBackground(.white, for: .widget)
}
}
If I use #Preview, the .redacted modifier won't work, and I seem to have to put it in the MyWidget implementation.
#Preview(as: .systemMedium) {
MyWidget()
} timeline: {
SimpleEntry(date: .now, emoji: "😀")
SimpleEntry(date: .now, emoji: "🤩")
}
Am I missing something?
HI
i have found libsystem_kernel.dylib crash. i can't reproduce this error even this is not unrecognisable. here is stack trace
Crashed: com.apple.main-thread
0 libsystem_kernel.dylib 0xaac mach_msg_trap + 8
1 libsystem_kernel.dylib 0x107c mach_msg + 72
2 CoreFoundation 0x6c88 + 368
3 CoreFoundation 0xaf90 + 1160
4 CoreFoundation 0x1e174 CFRunLoopRunSpecific + 572
5 GraphicsServices 0x1988 GSEventRunModal + 160
6 UIKitCore 0x4e5a88 + 1080
7 UIKitCore 0x27ef78 UIApplicationMain + 336
8 libTweaks.dylib 0x2a6b4 _apdecr_UIApplicationMain(int, char**, NSString*, NSString*) + 108
9 libswiftUIKit.dylib 0x27ee4 $s5UIKit17UIApplicationMainys5Int32VAD_SpySpys4Int8VGGSgSSSgAJtF + 100
10 REDDI 0x214d6c main + 4368469356 (AppDelegate.swift:4368469356)
11 ??? 0x1028a84d0 (Missing)
When a NavigationSplitView's sidebar has a default selected value, the detail's toolbar item disappears when resizing the view from compact to regular size.
@State private var selectedId: String? = "anything"
NavigationSplitView {
List(selection: $selectedId) {
Text("Sidebar")
}
} detail: {
Text("Detail")
.toolbar {
Button("Button") {}
}
}
There is no way to get the toolbar item back, other than reloading the view. I have no idea why this happens.
In my example I have a dummy Text("Sidebar") without a value, but the problem occurs regardless of its content.
Tested on Simulator iPadOS 18.0, and I've seen this happen in our production app.
Hello!
I discovered a bug on Catalyst about a three years ago but it still seems to be not fixed. My bug report number is FB9705748.
The Internet is silent on this so I'm even not sure, perhaps it's only me.
So to the problem. When you display UICollectionViewController or UIViewController that contains UICollectionView, interact with the collection view then dismiss the view controller, the displayed view controller isn't released if dismissal is done through navigation bar item.
The problem occurs only when the run target is My Mac (Mac Catalyst). Everything is fine when you run on iOS or via My Mac (Designed for iPad).
The sample project is uploaded to GitHub. It has a video that shows this strange behavior, see the log for 'deinit' messages.
I did have some workaround to fix this but it stops to work, presumable on the new macOS. Also, chances are that it's not only UICollectionView which initiates the glitch, it's just that I only encounter it with collection views.
I am trying to set my UITextView as the first responder with [self.textView becomeFirstResponder] when my view controller called viewDidAppear.
But sometimes it will cause crash with the error: [__NSPlaceholderArray initWithObjects:count:]: attempt to insert nil object from objects[0]
all I did is just:
- (void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
[self.textView becomeFirstResponder];
}
So if anyone can tell me what happened and how to do? when I call the [self.textView becomeFirstResponder], what will be insert into the responders list? self.textView itself?
Thanks very much!
Hi everyone,
I’m wondering about Core Data. When creating a private context using newBackgroundContext(), does it automatically set the parent to the view context, or is it independent?
Additionally, if I update objects in the context created by newBackgroundContext(), will the view context automatically notice the changes, and vice versa?
Lastly, are there other ways to set parent-child context relationships between contexts?
I'd appreciate it if anyone could clarify this for me.
Thanks in advance! 😊
Using just basic rule
.chartScrollableAxes(.horizontal)
.chartXVisibleDomain(length: 6)
Feature is working fine for iOS 17.x devices
I am in the process of evaluating Swift 6 and I noticed that when using the completion handler version of the requestAuthorization the application crashes with EXC_BAD_INSTRUCTION exception.
Using this code:
let center = UNUserNotificationCenter.current()
center.requestAuthorization(options: [.alert, .sound, .badge]) { success, error in
print(success)
}
Crashes when the project is build with Swift 6 and works normalising when build with Swift 5.
The only solution that I have found so far is to switch to using the async version of that API:
Task {
let center = UNUserNotificationCenter.current()
do {
if try await center.requestAuthorization(options: [.alert, .sound, .badge]) == true {
print("success")
} else {
print("fail")
}
} catch {
print("Error")
}
}
Is the a known issue?
I have submitted feedback with ID "FB15294185".
Hi everyone,
I’m wondering about Core Data. When creating a private context using newBackgroundContext(), does it automatically set the parent to the view context, or is it independent? I'd appreciate it if anyone could clarify this for me.
Thanks in advance! 😊