gpt4 book ai didi

ios - NSAttributedString.Key.writingDirection 上的 swift 4.2 崩溃

转载 作者:可可西里 更新时间:2023-11-01 00:38:38 24 4
gpt4 key购买 nike

我的 iOS 应用程序中有这段代码:

let subAttr: [NSAttributedString.Key : Any] = [NSAttributedString.Key.font : font,
NSAttributedString.Key.foregroundColor : color,
NSAttributedString.Key.writingDirection : NSWritingDirection.leftToRight]

这会导致崩溃:

2019-01-24 18:12:04.425440+0300 Haraj[5461:1355738] -[_SwiftValue count]: unrecognized selector sent to instance 0x281c752f0
2019-01-24 18:12:04.425619+0300 Haraj[5461:1355738] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[_SwiftValue count]: unrecognized selector sent to instance 0x281c752f0'
*** First throw call stack:
(0x1f5327ef8 0x1f44f5a40 0x1f523f154 0x1f532d810 0x1f532f4bc 0x1f525b954 0x1f90f5e3c 0x1f90f5cf4 0x1f9049030 0x1f9048fb8 0x1f9003050 0x1f9016e28 0x1f9016b6c 0x1f9004070 0x1ff8d7e2c 0x1ff956e38 0x1ff8dc0b0 0x221be3e24 0x221be446c 0x222536c4c 0x22253740c 0x222537068 0x222541210 0x221be38f0 0x22253fd50 0x222540200 0x2225400d4 0x1f5cc551c 0x22254045c 0x2225400d4 0x2225409a4 0x2225405c4 0x2225415e4 0x2225e7e90 0x2225fbfa8 0x1f9909a34 0x1f990e9c4 0x2225e7430 0x2225edfe0 0x22237e130 0x22237e478 0x222349bfc 0x222367ae8 0x2225fbf44 0x1f9909a34 0x1f990e9c4 0x2225e7430 0x221b019bc 0x221afc0b0 0x221afa280 0x2225b7314 0x2225b75d0 0x2225c5490 0x2225c0ecc 0x2225b7058 0x221b027cc 0x221b02da8 0x221b040a8 0x221ae6298 0x2225fbf44 0x1f9909a34 0x1f990e9c4 0x1f986d9d4 0x1f989c2f4 0x222181bf4 0x1f52b5b94 0x1f52b0828 0x1f52b0dc8 0x1f52b05b8 0x1f7524584 0x222158bc8 0x10257be3c 0x1f4d70b94)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb) po 0x281c752f0
__C.NSWritingDirection

(lldb)

这在 Swift 3 中运行良好,但我最近迁移到了 Swift 4.2。有什么帮助吗?

最佳答案

NSAttributedString.Key.writingDirection 的文档指出:

The value of this attribute is an NSArray object containing NSNumber objects representing the nested levels of writing direction overrides, in order from outermost to innermost.

This attribute provides a means to override the default bidirectional text algorithm, equivalent to using the Unicode bidi control characters LRE, RLE, LRO, or RLO paired with PDF, but as a higher-level attribute. (See Unicode Standard Annex #9 for information about the Unicode bidi formatting codes.) The NSWritingDirectionAttributeName constant is a character-level attribute that provides a higher-level alternative to the inclusion of explicit bidirectional control characters in text. It is the NSAttributedString equivalent of the HTML markup using bdo element with the dir attribute.

The values of the NSNumber objects should be 0, 1, 2, or 3, for LRE, RLE, LRO, or RLO respectively, and combinations of NSWritingDirection.leftToRight and NSWritingDirection.rightToLeft with NSTextWritingDirectionEmbedding or NSTextWritingDirectionOverride, as shown in Table 1.

至少你需要提供一个数组:

let subAttr: [NSAttributedString.Key : Any] = [
.font : font,
.foregroundColor : color,
.writingDirection : [ NSNumber(value: NSWritingDirection.leftToRight.rawValue) ]
]

关于ios - NSAttributedString.Key.writingDirection 上的 swift 4.2 崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54349859/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com