//Is my post method correct because google and claude are telling me I must use content type for the json and use .setvalue. I thought that my process was correct because I encode the data to turn into json and then make the request
func createTask(_ task: Task) async throws -> Task {
if let url = URL(string: "(baseURL)/todos"){
var request = URLRequest(url: url)
request.httpMethod = "POST"
let encoder = JSONEncoder()
do{
let data = try encoder.encode(task)
request.httpBody = data
let (data, response) = try await URLSession.shared.data(for: request)
return task
//we want to make encoder and then turn the data into json and put it in body
}
catch{
throw JSONErrors.encodingFailed
}
}
else{
throw URLError(.badURL)
}
}
Swift
RSS for tagSwift is a powerful and intuitive programming language for Apple platforms and beyond.
Posts under Swift tag
200 Posts
Selecting any option will automatically load the page
Post
Replies
Boosts
Views
Activity
It appears that starting with macOS Sequoia, Quick Look Preview extension no longer loads MapKit maps correctly anymore. Map tiles do not appear, leaving users with a beige background.
Users report that polylines do render correctly, but annotations appears black.
This was previously working fine in prior macOS versions including Sonoma.
STEPS TO REPRODUCE
Create a macOS app project, with an associated document.
Ensure project has a Quick Look preview extension, with necessary basic setups.
Ensure that the extension mentioned in (2) must have a MKMapView. Any other cosmetic changes, etc, does not need to be implemented to observe the base issue. Do note that it has been reported that in addition to the map tiles not loading, annotations don't render correctly as well.
With the code below, JSON data is parsed and is stored in the variable data in the .onAppear function, however an empty set of data is passed to the Content view. How can that be fixed so that the JSON data passes to the DataView?
struct ContentView: View {
@State var data: [Data]
@State var index: Int = 0
var body: some View {
VStack {
DataView(data: data[index])
}
.onAppear {
let filePath = Bundle.main.path(forResource: "data", ofType: "json")
let url = URL(fileURLWithPath: filePath!)
data = getData(url: url)
}
}
func getData(url: URL) -> [Data] {
do {
let data = try Data(contentsOf: url)
let jsonDecoded = try JSONDecoder().decode([Data].self, from: data)
return jsonDecoded
} catch let error as NSError {
print("Fail: \(error.localizedDescription)")
} catch {
print("Fail: \(error)")
}
return []
}
}
Good afternoon, all!
I was wondering if there was a timeline for when the App Store and/or TestFlight will drop support for Swift 5?
I know Swift 6 was released last year and historically App Store requires a certain SDK minimum for upload. I was wondering if any SDK update was on the docket that would effectively force applications onto Swift 6?
Looking at past releases, I had estimated mid to late 2026, but I wanted to confirm?
Swift 4
Released September 2017
Became the default SDK in Xcode 9
Strongly "encouraged" via the iOS 12 SDK in late 2018
Essentially "required" by early 2019
Swift 5
Released March 2019
Became the default SDK in Xcode 10.2
Strongly "encouraged" via the iOS 12.1 SDK in early 2019
Essentially "required" by late 2020
Swift 6
Released June 2024
Became the default SDK in Xcode 16
Strongly "encouraged" via the iOS 18 SDK in April 2025
**Essentially "required" by mide-late 2026 ?? **
Thank you in advance!
Topic:
App Store Distribution & Marketing
SubTopic:
App Store Connect
Tags:
App Store
Swift
Release Notes
TestFlight
Hi team, in iOS latest version 26.0, we are getting searchBar at bottom of the screen. Is there any option to change the position of the search? I need to move it to top as like in previous iOS version.
Greetings, Please type slowly, I'm new at this.
iOS 18.x.
Added search to a list, visibility toggled with a toolbar button, using this line of code:
.searchable(text: $searchText, isPresented: $isSearchPresented, placement:
.navigationBarDrawer(displayMode: .automatic), prompt: "Search...")
Realized I was re-stating defaults, changed it to this:
.searchable(text: $searchText, isPresented: $isSearchPresented, prompt: "Search...")
In both cases, it works great when in the middle of the list, just like I wanted. However, when I scroll to the top of the list, the serach field is displayed even when 'isPresented' is false. Is there any way to keep the search field hidden even at the top of the list?
..thanks!
I'm struggling to convert Swift 5 to Swift 6.
As advised in doc, I first turned strict concurrency ON. I got no error.
Then, selected swift6… and problems pop up.
I have a UIViewController with
IBOutlets: eg a TextField.
computed var eg duree
func using UNNotification: func userNotificationCenter
I get the following error in the declaration line of the func userNotificationCenter:
Main actor-isolated instance method 'userNotificationCenter(_:didReceive:withCompletionHandler:)' cannot be used to satisfy nonisolated requirement from protocol 'UNUserNotificationCenterDelegate'
So, I declared the func as non isolated.
This func calls another func func2, which I had also to declare non isolated.
Then I get error on the computed var used in func2
Main actor-isolated property 'duree' can not be referenced from a nonisolated context
So I declared duree as nonsilated(unsafe).
Now comes the tricky part.
The computed var references the IBOutlet dureeField
if dureeField.text == "X"
leading to the error
Main actor-isolated property 'dureeField' can not be referenced from a nonisolated context
So I finally declared the class as mainActor and the textField as nonisolated
@IBOutlet nonisolated(unsafe) weak var dureeField : UITextField!
That silences the error (but declaring unsafe means I get no extra robustness with swift6) just to create a new one when calling dureeField.text:
Main actor-isolated property 'text' can not be referenced from a nonisolated context
Question: how to address properties inside IBOutlets ? I do not see how to declare them non isolated and having to do it on each property of each IBOutlet would be impracticable.
The following did work, but will make code very verbose:
if MainActor.assumeIsolated({dureeField.text == "X"}) {
So I must be missing something.
Does the iPhone or iPad support reception of the following communication standards?
If so, please let me know if there is an swift API available.
・Bluetooth 5.x Long Range
・Wi-Fi Neighbor Awareness Networking (Wi-Fi Aware)
・Wi-Fi Beacon
I've been testing the safeAreaBar modifier to develop a custom tab bar. From my understanding, this should enable the .scrollEdgeEffectStyle to work with this bar, but I don't see any effect.
Could you please clarify the difference between safeAreaBar and safeAreaInset?
Just testing an existing app with Xcode 26.
I notice that content of UIBarButtonItem (either text or image) disappears when tapped (and reappear on release).
Those are custom, bordered buttons.
Attribute inspector:
Buttons in Xcode:
When selected in Xcode, we see a rectangle inside the rounder rect of iOS 26
In simulator:
When tapped in simulator:
I have edited code from
backButton.setTitleTextAttributes([
.font : boldFont,
.foregroundColor : UIColor.systemBlue,
], for: .normal)
to
backButton.setTitleTextAttributes([
.font : boldFont,
.foregroundColor : UIColor.systemBlue,
], for: [.normal, .focused, .selected, .highlighted])
to no avail.
What am I missing ?
As a fun project, I'm wanting to model an electronic circuit.
Components inherit from a superclass (ElectronicComponent). Each subclass (e.g. Resistor) has certain methods to return properties (e.g. resistance), but may vary by the number of outlets (leads) they have, and what they are named.
Each outlet connects to a Junction.
In my code to assemble a circuit, while I'm able to manually hook up the outlets to the junctions, I'd like to be able to use code similar to the following…
class Lead: Hashable // implementation omitted
{
let id = UUID()
unowned let component: ElectronicComponent
weak var connection: Junction?
init(component: ElectronicComponent, to connection: Junction? = nil)
{
self.component = component
self.connection = connection
}
}
@dynamicMemberLookup
class ElectronicComponent
{
let id = UUID()
var connections: Set<Lead> = []
let label: String?
init(label: String)
{
self.label = label
}
subscript<T>(dynamicMember keyPath: KeyPath<ElectronicComponent, T>) -> T
{
self[keyPath: keyPath]
}
func connect(lead: KeyPath<ElectronicComponent, Lead>, to junction: Junction)
{
let lead = self[keyPath: lead]
lead.connection = junction
connections.insert(lead)
}
}
class Resistor: ElectronicComponent
{
var input, output: Lead?
let resistance: Measurement<UnitElectricResistance>
init(_ label: String, resistance: Measurement<UnitElectricResistance>)
{
self.resistance = resistance
super.init(label: label)
}
}
let resistorA = Resistor("R1", resistance: .init(value: 100, unit: .ohms))
let junctionA = Junction(name: "A")
resistorA.connect(lead: \.outlet2, to: junctionA)
While I'm able to do this by implementing @dynamicMemberLookup in each subclass, I'd like to be able to do this in the superclass to save repeating the code.
subscript<T>(dynamicMember keyPath: KeyPath<ElectronicComponent, T>) -> T
{
self[keyPath: keyPath]
}
Unfortunately, the compiler is not allowing me to do this as the superclass doesn't know about the subclass properties, and at the call site, the subclass isn't seen as ElectronicComponent.
I've been doing trial and error with protocol conformance and other things, but hitting walls each time.
One possibility is replacing the set of outlets with a dictionary, and using Strings instead of key paths, but would prefer not to.
Another thing I haven't tried is creating and adopting a protocol with the method implemented in there. Another considered approach is using macros in the subclasses, but I'd like to see if there is a possibility of achieving the goal using my current approach, for learning as much as anything.
I'm trying to work with the beta version of the Declared Age Range framework based on an article's tutorial but am getting the following error:
[C:1-3] Error received: Invalidated by remote connection.
and AgeRangeService.Error.notAvailable is being thrown on the call to requestAgeRange. I'm using Xcode 26 beta 5 and my simulator is running the 26.0 beta. The iCloud account that I have signed into the simulator has a DOB set as well.
This is my full ContentView where I'm trying to accomplish this.
struct ContentView: View {
@Environment(\.requestAgeRange) var requestAgeRange
@State var advancedFeaturesEnabled = false
var body: some View {
VStack {
Button("Advanced Features") {}
.disabled(!advancedFeaturesEnabled)
}
.task {
await requestAgeRangeHelper()
}
}
func requestAgeRangeHelper() async {
do {
let ageRangeResponse = try await requestAgeRange(ageGates: 16)
switch ageRangeResponse {
case let .sharing(range):
if let lowerBound = range.lowerBound, lowerBound >= 16 {
advancedFeaturesEnabled = true
}
case .declinedSharing:
break
// Handle declined sharing
default:
break
}
} catch AgeRangeService.Error.invalidRequest {
print("Invalid request")
// Handle invalid request (e.g., age range < 2 years)
} catch AgeRangeService.Error.notAvailable {
print("Not available")
// Handle device configuration issues
} catch {
print("Other")
}
}
}
I am using below code to change navigationBar bg colour, but the text is hidden in large title. It works fine in previous versions. Kindly refer below code and attached images.
Code:
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
navigationController?.navigationBar.prefersLargeTitles = true
navigationItem.largeTitleDisplayMode = .always
let appearance = UINavigationBarAppearance()
appearance.backgroundColor = UIColor(
red: 0.101961,
green: 0.439216,
blue: 0.388235,
alpha: 1.0
)
navigationController?.navigationBar.standardAppearance = appearance
navigationController?.navigationBar.scrollEdgeAppearance = appearance
navigationController?.navigationBar.compactAppearance = appearance
}
Referenced images:
Hi,
In Xcode 16.4, the atomic_flag() method can be used, but in Xcode 26.0, it is not available. An error message saying Cannot find 'atomic_flag' in scope is displayed. This can be reproduced simply by trying to use atomic_flag() in a newly created empty project.
Thank you.
Xcode: Version 26.0 beta 4 (17A5285i), macOS: 15.5(24F74)
import SwiftUI
struct ContentView: View {
var body: some View {
VStack {
Image(systemName: "globe")
.imageScale(.large)
.foregroundStyle(.tint)
Text("Hello, world!")
}
.padding()
.task {
_ = atomic_flag()
}
}
}
Hello Apple Developer Community: I have a problem with the fullscreencover. I can see the Things, that shouldn’t be visible behind it.
I’m currently developing with iOS 26 and only there it happens.
I hope you can help me :)
Have a nice day
By setting the PKCanvasView background color to blue, I can tell that the PKCanvasView for each PDFPage is created normally, but it does not respond to touch. Specifically, whether it is finger or applepencil, all the responses of the page occur from PDFView(such as zoom and scroll), and PKCanvasView can not draw, please how to solve?
class PDFAnnotatableViewController: UIViewController, PDFViewDelegate {
private let pdfView = PDFView()
private var pdfDocument: PDFDocument?
let file: FileItem
private var userSettings: UserSettings
@Binding var selectedPage: Int
@Binding var currentMode: Mode
@Binding var latestPdfChatResponse: LatestPDFChatResponse
@State private var pdfPageCoordinator = PDFPageCoordinator()
@ObservedObject var userMessage: ChatMessage
init(file: FileItem,
userSettings: UserSettings,
drawDataList: Binding<[DrawDataItem]>,
selectedPage: Binding<Int>,
currentMode: Binding<Mode>,
latestPdfChatResponse: Binding<LatestPDFChatResponse>,
userMessage: ChatMessage) {
self.file = file
self.userSettings = userSettings
self._selectedPage = selectedPage
self._currentMode = currentMode
self._latestPdfChatResponse = latestPdfChatResponse
self.userMessage = userMessage
super.init(nibName: nil, bundle: nil)
DispatchQueue.global(qos: .userInitiated).async {
if let document = PDFDocument(url: file.pdfLocalUrl) {
DispatchQueue.main.async {
self.pdfDocument = document
self.pdfView.document = document
self.goToPage(selectedPage: selectedPage.wrappedValue - 1)
}
}
}
}
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
override func viewDidLoad() {
super.viewDidLoad()
setupPDFView()
}
private func setupPDFView() {
pdfView.delegate = self
pdfView.autoScales = true
pdfView.displayMode = .singlePage
pdfView.displayDirection = .vertical
pdfView.backgroundColor = .white
pdfView.usePageViewController(true)
pdfView.displaysPageBreaks = false
pdfView.displaysAsBook = false
pdfView.minScaleFactor = 0.8
pdfView.maxScaleFactor = 3.5
pdfView.pageOverlayViewProvider = pdfPageCoordinator
if let document = pdfDocument {
pdfView.document = document
goToPage(selectedPage: selectedPage)
}
pdfView.frame = view.bounds
pdfView.autoresizingMask = [.flexibleWidth, .flexibleHeight]
view.addSubview(pdfView)
NotificationCenter.default.addObserver(
self,
selector: #selector(handlePageChange),
name: .PDFViewPageChanged,
object: pdfView
)
}
// Dealing with page turning
@objc private func handlePageChange(notification: Notification) {
guard let currentPage = pdfView.currentPage, let document = pdfView.document else { return }
let currentPageIndex = document.index(for: currentPage)
if currentPageIndex != selectedPage - 1 {
DispatchQueue.main.async {
self.selectedPage = currentPageIndex + 1
}
}
}
func goToPage(selectedPage: Int) {
guard let document = pdfView.document else { return }
if let page = document.page(at: selectedPage) {
pdfView.go(to: page)
}
}
// Switch function
func togglecurrentMode(currentMode: Mode){
DispatchQueue.main.async {
if self.currentMode == .none{
self.pdfView.usePageViewController(true)
self.pdfView.isUserInteractionEnabled = true
} else if self.currentMode == .annotation {
if let page = self.pdfView.currentPage {
if let canvasView = self.pdfPageCoordinator.getCanvasView(forPage: page) {
canvasView.isUserInteractionEnabled = true
canvasView.tool = PKInkingTool(.pen, color: .red, width: 20)
canvasView.drawingPolicy = .anyInput
canvasView.setNeedsDisplay()
}
}
}
}
}
}
class MyPDFPage: PDFPage {
var drawing: PKDrawing?
func setDrawing(_ drawing: PKDrawing) {
self.drawing = drawing
}
func getDrawing() -> PKDrawing? {
return self.drawing
}
}
class PDFPageCoordinator: NSObject, PDFPageOverlayViewProvider {
var pageToViewMapping = [PDFPage: PKCanvasView]()
func pdfView(_ view: PDFView, overlayViewFor page: PDFPage) -> UIView? {
var resultView: PKCanvasView? = nil
if let overlayView = pageToViewMapping[page] {
resultView = overlayView
} else {
let canvasView = PKCanvasView(frame: view.bounds)
canvasView.drawingPolicy = .anyInput
canvasView.tool = PKInkingTool(.pen, color: .systemYellow, width: 20)
canvasView.backgroundColor = .blue
pageToViewMapping[page] = canvasView
resultView = canvasView
}
if let page = page as? MyPDFPage, let drawing = page.drawing {
resultView?.drawing = drawing
}
return resultView
}
func pdfView(_ pdfView: PDFView, willEndDisplayingOverlayView overlayView: UIView, for page: PDFPage) {
guard let overlayView = overlayView as? PKCanvasView, let page = page as? MyPDFPage else { return }
page.drawing = overlayView.drawing
pageToViewMapping.removeValue(forKey: page)
}
func savePDFDocument(_ pdfDocument: PDFDocument) -> Data {
for i in 0..<pdfDocument.pageCount {
if let page = pdfDocument.page(at: i) as? MyPDFPage, let drawing = page.drawing {
let newAnnotation = PDFAnnotation(bounds: drawing.bounds, forType: .stamp, withProperties: nil)
let codedData = try! NSKeyedArchiver.archivedData(withRootObject: drawing, requiringSecureCoding: true)
newAnnotation.setValue(codedData, forAnnotationKey: PDFAnnotationKey(rawValue: "drawingData"))
page.addAnnotation(newAnnotation)
}
}
let options = [PDFDocumentWriteOption.burnInAnnotationsOption: true]
if let resultData = pdfDocument.dataRepresentation(options: options) {
return resultData
}
return Data()
}
func getCanvasView(forPage page: PDFPage) -> PKCanvasView? {
return pageToViewMapping[page]
}
}
Is there an error in my code? Please tell me how to make PKCanvasView painting normally?
I am developing an AppKit application in MacOS with Swift.
Our application requires a complex, multi-windowed interface and must deliver a very fast, responsive experience.
As a performance test, I built a sample app that creates 3 windows programmatically, each containing 500 NSTextFields (with each text-field assigned 35 different properties).
Code flow: https://gist.github.com/Raunit-TW/5ac58ac9c6584f93e2ee201aa8118139
This takes around 77 milliseconds to render the windows - I need to find a way to reduce this time, as low as possible.
Thanks.
I am trying to extend my PersistedModels like so:
@Versioned(3)
@Model
class MyType {
var name: String
init() { name = "hello" }
}
but it seems that SwiftData's@Model macro is unable to read the properties added by my @Versioned macro. I have tried changing the order and it ignores them regardless. version is not added to schemaMetadata and version needs to be persisted. I was planning on using this approach to add multiple capabilities to my model types. Is this possible to do with macros?
VersionedMacro
/// A macro that automatically implements VersionedModel protocol
public struct VersionedMacro: MemberMacro, ExtensionMacro {
// Member macro to add the stored property directly to the type
public static func expansion(
of node: AttributeSyntax,
providingMembersOf declaration: some DeclGroupSyntax,
in context: some MacroExpansionContext
) throws -> [DeclSyntax] {
guard let argumentList = node.arguments?.as(LabeledExprListSyntax.self),
let firstArgument = argumentList.first?.expression else {
throw MacroExpansionErrorMessage("@Versioned requires a version number, e.g. @Versioned(3)")
}
let versionValue = firstArgument.description.trimmingCharacters(in: .whitespaces)
// Add the stored property with the version value
return [
"public private(set) var version: Int = \(raw: versionValue)"
]
}
// Extension macro to add static property
public static func expansion(
of node: SwiftSyntax.AttributeSyntax,
attachedTo declaration: some SwiftSyntax.DeclGroupSyntax,
providingExtensionsOf type: some SwiftSyntax.TypeSyntaxProtocol,
conformingTo protocols: [SwiftSyntax.TypeSyntax],
in context: some SwiftSyntaxMacros.MacroExpansionContext
) throws -> [SwiftSyntax.ExtensionDeclSyntax] {
guard let argumentList = node.arguments?.as(LabeledExprListSyntax.self),
let firstArgument = argumentList.first?.expression else {
throw MacroExpansionErrorMessage("@Versioned requires a version number, e.g. @Versioned(3)")
}
let versionValue = firstArgument.description.trimmingCharacters(in: .whitespaces)
// We need to explicitly add the conformance in the extension
let ext = try ExtensionDeclSyntax("extension \(type): VersionedModel {}")
.with(\.memberBlock.members, MemberBlockItemListSyntax {
MemberBlockItemSyntax(decl: DeclSyntax(
"public static var version: Int { \(raw: versionValue) }"
))
})
return [ext]
}
}
VersionedModel
public protocol VersionedModel: PersistentModel {
/// The version of this particular instance
var version: Int { get }
/// The type's current version
static var version: Int { get }
}
Macro Expansion:
Yesterday on Explore the biggest updates from WWDC Curt Clifton shared .background(.tint, in: .rect(corner: .containerConcentric)). XCode26 beta 3 don‘t recognize it. how when we can use it??
I had project going great, where i needed to do stuff with pdfs, drawing on top them etc. Since apple is all closed sourced i needed to become a bit hacky. Anyways, i have a problem since the new ios 26 update which breaks the behaviour. I simplified the code very much into a demo project, where you can quickly see what's wrong.
When swiping left to go to the next page, it does change the page etc in the pdf Document, but visually nothing happens. I am stuck on the first page. I dont know what to do, tried a lot of things, but nothing works. Anyone skilled enough to help me out?
import UIKit
import PDFKit
import SwiftUI
class PDFViewController: UIViewController {
var pdfView: PDFView!
var gestureHandler: GestureHandler!
override func viewDidLoad() {
super.viewDidLoad()
setupPDFView()
setupGestureHandler()
loadPDF()
}
private func setupPDFView() {
pdfView = PDFView(frame: view.bounds)
// Your exact configuration
pdfView.autoScales = true
pdfView.pageShadowsEnabled = false
pdfView.backgroundColor = .white
pdfView.displayMode = .singlePage
view.addSubview(pdfView)
// Setup constraints
pdfView.translatesAutoresizingMaskIntoConstraints = false
NSLayoutConstraint.activate([
pdfView.topAnchor.constraint(equalTo: view.topAnchor),
pdfView.leadingAnchor.constraint(equalTo: view.leadingAnchor),
pdfView.trailingAnchor.constraint(equalTo: view.trailingAnchor),
pdfView.bottomAnchor.constraint(equalTo: view.bottomAnchor)
])
}
private func setupGestureHandler() {
gestureHandler = GestureHandler(pdfView: pdfView)
gestureHandler.setupSwipeGestures(on: view)
}
private func loadPDF() {
if let path = Bundle.main.path(forResource: "sonate12", ofType: "pdf"),
let document = PDFDocument(url: URL(fileURLWithPath: path)) {
pdfView.document = document
} else {
print("Could not find sonate12.pdf in bundle")
}
}
}
class GestureHandler {
private weak var pdfView: PDFView?
init(pdfView: PDFView) {
self.pdfView = pdfView
}
func setupSwipeGestures(on view: UIView) {
// Left swipe - go to next page
let leftSwipe = UISwipeGestureRecognizer(target: self, action: #selector(handleSwipe(_:)))
leftSwipe.direction = .left
view.addGestureRecognizer(leftSwipe)
// Right swipe - go to previous page
let rightSwipe = UISwipeGestureRecognizer(target: self, action: #selector(handleSwipe(_:)))
rightSwipe.direction = .right
view.addGestureRecognizer(rightSwipe)
}
@objc private func handleSwipe(_ gesture: UISwipeGestureRecognizer) {
guard let pdfView = pdfView,
let document = pdfView.document,
let currentPage = pdfView.currentPage else {
print("🚫 No PDF view, document, or current page available")
return
}
let currentIndex = document.index(for: currentPage)
let totalPages = document.pageCount
print("📄 Current state: Page \(currentIndex + 1) of \(totalPages)")
print("👆 Swipe direction: \(gesture.direction == .left ? "LEFT (next)" : "RIGHT (previous)")")
switch gesture.direction {
case .left:
// Next page
guard currentIndex < document.pageCount - 1 else {
print("🚫 Already on last page (\(currentIndex + 1)), cannot go forward")
return
}
let nextPage = document.page(at: currentIndex + 1)
if let page = nextPage {
print("➡️ Going to page \(currentIndex + 2)")
pdfView.go(to: page)
pdfView.setNeedsDisplay()
pdfView.layoutIfNeeded()
// Check if navigation actually worked
DispatchQueue.main.asyncAfter(deadline: .now() + 0.1) {
if let newCurrentPage = pdfView.currentPage {
let newIndex = document.index(for: newCurrentPage)
print("✅ Navigation result: Now on page \(newIndex + 1)")
if newIndex == currentIndex {
print("⚠️ WARNING: Page didn't change visually!")
}
}
}
} else {
print("🚫 Could not get next page object")
}
case .right:
// Previous page
guard currentIndex > 0 else {
print("🚫 Already on first page (1), cannot go back")
return
}
let previousPage = document.page(at: currentIndex - 1)
if let page = previousPage {
print("⬅️ Going to page \(currentIndex)")
pdfView.go(to: page)
pdfView.setNeedsDisplay()
pdfView.layoutIfNeeded()
let bounds = pdfView.bounds
pdfView.bounds = CGRect(x: bounds.origin.x, y: bounds.origin.y, width: bounds.width + 0.01, height: bounds.height)
pdfView.bounds = bounds
// Check if navigation actually worked
DispatchQueue.main.asyncAfter(deadline: .now() + 0.1) {
if let newCurrentPage = pdfView.currentPage {
let newIndex = document.index(for: newCurrentPage)
print("✅ Navigation result: Now on page \(newIndex + 1)")
if newIndex == currentIndex {
print("⚠️ WARNING: Page didn't change visually!")
}
}
}
} else {
print("🚫 Could not get previous page object")
}
default:
print("🤷♂️ Unknown swipe direction")
break
}
}
}
struct PDFViewerRepresentable: UIViewControllerRepresentable {
func makeUIViewController(context: Context) -> PDFViewController {
return PDFViewController()
}
func updateUIViewController(_ uiViewController: PDFViewController, context: Context) {
// No updates needed
}
}
You can look at the code here as well: https://github.com/vallezw/swift-bug-ios26