I am using the current Xcode-Version and in the Build-Settings I have Swift 5. But always get the error of the
Type 'NSAttributedString.Key' has no member 'font'
This are the imports:
import UIKit
import SwiftUI
import PDFKit
and in this Code I like to use the attributes
static func createContentPage(for report: CustomerOrderWorkReports, size: CGSize) -> PDFPage? { let renderer = UIGraphicsImageRenderer(size: size) let img = renderer.image { ctx in let font = UIFont.systemFont(ofSize: 72) let paragraphStyle = NSMutableParagraphStyle() paragraphStyle.alignment = .center paragraphStyle.firstLineHeadIndent = 5.0 let attributes: [NSAttributedString.Key: Any] = [ NSAttributedString.Key.font: font, NSAttributedString.Key.paragraphStyle: paragraphStyle ] var text = "Datum: (DateFormatter.localizedString(from: report.addDate ?? Date(), dateStyle: .medium, timeStyle: .none))n" text += "Positions and worktime:n" text.draw(with: CGRect(x: 20, y: 20, width: size.width - 40, height: size.height - 40), options: .usesLineFragmentOrigin, attributes: attributes, context: nil) } return PDFPage(image: img) }
But always get the error, that I had written. with the paragraphStyle, the error is the same. Also I had restarted Xcode and always erased the simulator.
The build be successfully and the Text would be added to the PDF-File.
But the error still stay.
Restarted Xcode and also the Computer.
Miracle Johnson is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.