Hi,
This issue started with iOS 18, in iOS 17 it worked correctly. I think there was a change in SectionedFetchRequest so maybe I missed it but it did work in iOS 17.
I have a List that uses SectionedFetchRequest to show entries from CoreData. The setup is like this:
struct ManageBooksView: View {
@SectionedFetchRequest<Int16, MyBooks>(
sectionIdentifier: \.groupType,
sortDescriptors: [SortDescriptor(\.groupType), SortDescriptor(\.name)]
)
private var books: SectionedFetchResults<Int16, MyBooks>
var body: some View {
NavigationStack {
List {
ForEach(books) { section in
Section(header: Text(section.id)) {
ForEach(section) { book in
NavigationLink {
EditView(book: book)
} label: {
Text(book.name)
}
}
}
}
}
.listStyle(.insetGrouped)
}
}
}
struct EditView: View {
private var book: MyBooks
init(book: MyBooks) {
print("Init hit")
self.book = book
}
}
Test 1: So now when I change name of the Book entity inside the EditView and do save on the view context and go back, the custom EditView is correctly hit again.
Test 2: If I do the same changes on a different attribute of the Book entity the custom init of EditView is not hit and it is stuck with the initial result from SectionedFetchResults.
I also noticed that if I remove SortDescriptor(\.name) from the sortDescriptors and do Test 1, it not longer works even for name, so it looks like the only "observed" change is on the attributes inside sortDescriptors.
Any suggestions will be helpful, thank you.
Post
Replies
Boosts
Views
Activity
The project setup is as follows:
Uses pods
Has swift bridging header as it uses both Objc and Swift
With Xcode Version 16.0 (16A242d), when building the project everything is fine but when I build the Documentation (Product > Build Documentation), I am getting this error via:
/.../Project/Pods/FirebaseCore/FirebaseCore/Sources/Public/FirebaseCore/FIRLoggerLevel.h:23:28: redefinition of 'FIRLoggerLevel'
...
Building the documentation of the same project with Xcode Version 15.4 works just fine, so the error must come from the new xcodebuild (Xcode 16.0 Build version 16A242d).
Here are the pods in the project:
pod 'Firebase/Crashlytics', '10.29.0'
pod 'Firebase/Performance', '10.29.0'
# (Recommended) Pod for Google Analytics
pod 'FirebaseAnalytics', '10.29.0'
pod 'GoogleAnalytics', '3.21'
pod 'GoogleTagManager', '7.4.3'
pod 'FirebaseRemoteConfig', '10.29.0'
pod 'GoogleUtilities', '7.13.0'
Tried with all latest, but the same issue persists.
Any ideas, on how to resolve this? I read that it is not possible to disable the pods being build by docc as they are dependencies of the target which is being build by the docc process, if that is not true, maybe I can disable docc from building the Pods.
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".
Since iOS 18 I have noticed a strange issue which happens to the TabView in SwiftUI when you switch from Dark to Light mode.
With this code:
import SwiftUI
struct ContentView: View {
var body: some View {
TabView {
List {
ForEach(0..<100, id: \.self) { index in
Text("Row: \(index)")
}
}.tabItem {
Image(systemName: "house")
Text("Home")
}
}
}
}
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
}
}
The TabBar does not switch colours when going from dark to light, it work correctly when going from light to dark.
Here is a video of iOS 18 with the issue:
Here is a video of iOS 17.5 with same code and no issue:
On real device it looks (better), the color does update but with delay.
I have submitted a feedback bug report, but in the meanwhile has anyone been back to resolve this?
Hi,
It seams that the public func isSuperset(of other: CharacterSet) -> Bool API gives inconsistent results for some emoji symbols when uses with and without prefix text. Here is a playground example:
import Foundation
let input1 = "🥀"
let input11 = "a🥀"
let input2 = "😀"
let input22 = "a😀"
let letters = CharacterSet.letters
print("'\(input1)' is part of 'CharacterSet.letters': \(letters.isSuperset(of: CharacterSet(charactersIn: input1)))") // Gives false
print("'\(input11)' is part of 'CharacterSet.letters': \(letters.isSuperset(of: CharacterSet(charactersIn: input11)))") // INCORRECT: Should give false, but it gives true
print("'\(input2)' is part of 'CharacterSet.letters': \(letters.isSuperset(of: CharacterSet(charactersIn: input2)))") // Gives false
print("'\(input22)' is part of 'CharacterSet.letters': \(letters.isSuperset(of: CharacterSet(charactersIn: input22)))") // Gives false
Output:
'🥀' is part of 'CharacterSet.letters': false
'a🥀' is part of 'CharacterSet.letters': true
'😀' is part of 'CharacterSet.letters': false
'a😀' is part of 'CharacterSet.letters': false
Has anyone observed this?
The idea is to make it easer to update documentation when API changes or when code is not correct.
Is it possible to make the code file declared like this:
@Code(name: "AppDelegate.swift", file: AppDelegate.swift)
And the content of the AppDelegate.swift file is:
import UIKit
@main
class AppDelegate: UIResponder, UIApplicationDelegate {
func application(
_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
) -> Bool {
compiler error should be raised here
return true
}
}
After doing "Product > Build Documentation" the output gives the following documentation and there is not warning or errors during the build:
Thank you for your answers.
If you handle textField(_:shouldChangeCharactersIn:replacementString:) and return false for a paste operation, once user does and "shake to undo" the provided range is out of bounds of the text field's text. Is this expected?
Here is a sample code that simply limits the input to 5 characters:
class ViewController: UIViewController, UITextFieldDelegate {
@IBOutlet weak var textField: UITextField!
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
textField.delegate = self
}
func textField(_ textField: UITextField, shouldChangeCharactersIn range: NSRange, replacementString string: String) -> Bool {
let text = textField.text ?? ""
let currentString = text as NSString
let newString = currentString.replacingCharacters(in: range, with: string)
return newString.count < 5
}
}
Steps to reproduce a the crash:
UsernameTextFieldShake[40533:8359309] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFString replaceCharactersInRange:withString:]: Range or index out of bounds'
Type "test"
Copy the text
Paste the text at the end of the text field's text
The paste will not be allowed as it is above 5 length.
Shake the device
Press undo
Crash, due to let newString = currentString.replacingCharacters(in: range, with: string)
Is there a correct way to guard agains this "rogue" range?
Is this range expected to be provided to the textField(_:shouldChangeCharactersIn:replacementString:), one might think because the previous handling returned false that the undo should happen on the previous accepted command (which was at step 1)
Thank you for the responses.
With iOS 17 creation of HKWorkout is deprecated via its init functions and the recommendation is to use HKWorkoutBuilder. If you try to init HKWorkout like you would pre iOS 17 you get this warning of deprecation:
The problem is that I am creating this HKWorkout object inside unit tests in order to test a service that works with such objects. And HKWorkoutBuilder requires a HKHealthStore which itself requires to be authenticated to be able to create HKWorkoutActivity instances, like it would be when an app is running. But since the unit tests cannot accept the request on the HKHealthStore I am not sure if using HKWorkoutBuilder inside unit tests is possible.
I've also tried to inherit HKHealthStore and override all of its methods, but still, store requires authorization.
Any ideas on how to proceed with creating HKWorkout for unit test purposes?
Hi, I want to enable swipeActions for some rows of a List while other rows do not have this action.
Here is an example:
List {
ForEach(1..<100) { i in
Text("\(i)")
.swipeActions(edge: .leading) {
Button {
total += i
} label: {
Label("Add \(i)", systemImage: "plus.circle")
}
.tint(.indigo)
}
.swipeActions(edge: .trailing) {
Button {
total -= i
} label: {
Label("Subtract \(i)", systemImage: "minus.circle")
}
}
}
}
What would be the best approach to disable the swipeActions for let say the 50 row?
Hi, with iOS 17 creation of HKWorkout is deprecated via its init functions and the recommendation is to use HKWorkoutBuilder:
The problem is that I am creating this HKWorkout object inside unit tests in order to test a service that works with such objects. And HKWorkoutBuilder requires a HKHealthStore which itself requires to be authenticated to be able to create HKWorkoutActivity instances, like it would be when an app is running. But since the unit tests cannot accept the request on the HKHealthStore I am not sure if using HKWorkoutBuilder inside unit tests is possible.
Any ideas on how to proceed with creating HKWorkout for unit test purposes?
Hi,
I am creating a custom NSSecureUnarchiveFromDataTransformer in order to handle attributes of entities of type NSDateComponents.
It all works and I did not see any warnings in the "Issue navigator" inside Xcode but with Xcode 15 I started seeing this warning:
/Users/.../CustomNSSecureUnarchiveFromDataTransformer/CoreData:1:1 no NSValueTransformer with class name 'CustomSecureUnarchiveFromDataTransformer' was found for attribute 'testDate' on entity 'Item'
My use case is very simple, I have this custom transformer:
@objc(CustomSecureUnarchiveFromDataTransformer)
final class CustomSecureUnarchiveFromDataTransformer: NSSecureUnarchiveFromDataTransformer {
override class var allowedTopLevelClasses: [AnyClass] {
return [NSDateComponents.self]
}
static let name = NSValueTransformerName(rawValue: String(describing: CustomSecureUnarchiveFromDataTransformer.self))
public static func register() {
let transformer = CustomSecureUnarchiveFromDataTransformer()
ValueTransformer.setValueTransformer(transformer, forName: name)
}
}
which is set to the Core data entity's "Transformer":
which leads to the warning in Xcode 15.
App works just fine and there are no problems during run time, but this warning is shown and I want to fix it.
Here is a simple test project https://github.com/VladimirAmiorkov/CustomNSSecureUnarchiveFromDataTransformer
Hi,
The UIApplication.shared.applicationIconBadgeNumber has been deprecated in iOS 17 and the recommendation is to use setBadgeCount(_:withCompletionHandler:) but what if I only want to read this number and not change it?
How would one only read this number in iOS 17?