Post

Replies

Boosts

Views

Activity

TextKit 2 viewport
TextKit 2 looks great. The video demonstrates the sample app on both MacOS and iPad. However the downloaded code only works on MacOS and the documentation says the NSTextViewportLayoutController is only available on MacOS, so when can we expect the IOS versions. And what about integration with SwiftUI?
2
0
1.1k
Jul ’21
Dynamic type & custom font
If I call let font = UIFont.preferredFont(forTextStyle:.body) Then font.pointSize has value 17 If, however, I call this with a font such as Arial             let font = UIFont.fontWithNameAndTraits(fontName,                                                     size: styleAttributes.fontSize ?? 12,                                                     bold: styleAttributes.bold ?? false,                                                     italic: styleAttributes.italic ?? false)             let fontMetrics = UIFontMetrics(forTextStyle: .body)             let scaledFont = fontMetrics.scaledFont(for: font) Then scaledFont.pointSize has value 12. I was expecting 17, so I must be doing something wrong. Any suggestion? The function fontWithNameAndTraits is:     class func fontWithNameAndTraits(_ name:String, size:CGFloat, bold:Bool, italic:Bool)-UIFont {         let fontRef = UIFont.getFontRefForNameAndTraits(name, size:size, bold:bold, italic:italic)         let fontNameKey = CTFontCopyName(fontRef , kCTFontPostScriptNameKey)! as String         return UIFont(name: fontNameKey as String, size:CTFontGetSize(fontRef ))!     }
1
0
987
Apr ’21
Defining Transformer for NSAttributedString
Coredata used to save attributed strings, but now requires a secure coding transformer. I have tried the code below, but it fails claiming This decoder will only decode classes that adopt NSSecureCoding. Class '__SwiftValue' does not adopt it The transformer has been registered and the attributes given the name 'AttributedStringToDataTransformer' Any suggestions as to what is wrong? Here's the code: class AttributedStringToDataTransformer: ValueTransformer {     override func transformedValue(_ value: Any?) - Any? {         let boxedData = try! NSKeyedArchiver.archivedData(withRootObject: value!, requiringSecureCoding: true)         return boxedData   }     override func reverseTransformedValue(_ value: Any?) - Any? {         let typedBlob = value as! Data         let data = try! NSKeyedUnarchiver.unarchivedObject(ofClasses: [NSAttributedString.self], from: typedBlob)         return (data as! NSAttributedString)     } } extension AttributedStringToDataTransformer {     /// The name of the transformer. This is the name used to register the transformer using `ValueTransformer.setValueTrandformer(_"forName:)`.     static let name = NSValueTransformerName(rawValue: String(describing: AttributedStringToDataTransformer.self))     /// Registers the value transformer with `ValueTransformer`.     public static func register() {        ValueTransformer.setValueTransformer(AttributedStringToDataTransformer(), forName: name)     } }
1
0
869
Mar ’21
Error initialising UnsafeMutablePointer<ObjCBool>
The following code compiles ok in one function:         let stop:UnsafeMutablePointerObjCBool stop.initialize(to: false) text.enumerateAttribute(kStyleKey,                                 in: NSRange(location: 0, length: text.string.count),                                 options: []) { (value, range, stop) in but the following code which is virtually the same fails the initialise with the error "Constant 'stop' being used before being initialised" :         let stop:UnsafeMutablePointerObjCBool stop.initialize(to: false) attributedText.enumerateAttribute(kStyleKey,                                           in: NSRange(location: selectedRange.location, length: selectedRange.length),                                 options: []) { (value, range, stop) in Any suggestions - looks like a compiler issue to me.
10
0
2.2k
Mar ’21