1

我正在实现一个设置游戏,其中我的卡片是由NSAttributedString属性标题组成的按钮。为了检查三个选定的卡片是否构成一组,我想比较每个属性字符串的属性(它们是按钮上的属性标题),因为每个属性都代表一个属性。这无法完成,因为我在比较它们时遇到编译错误。

let at: [NSAttributedString.Key : Any] = [
            .strokeColor : UIColor.blue,
            .foregroundColor : UIColor.white,
            .strokeWidth : -7.0,
            .font : UIFont.systemFont(ofSize: 35)
        ]

let s = NSAttributedString(string: "●", attributes: at)
        let attribute: [NSAttributedString.Key : Any] = [
            .strokeColor : UIColor.blue,
            .foregroundColor : UIColor.white,
            .strokeWidth : -7.0,
            .font : UIFont.systemFont(ofSize: 35)
        ]
let a = NSAttributedString(string: "▲", attributes: attribute)

if(s.attributes(at: 0, effectiveRange: nil) & (a.attributes(at: 0, effectiveRange: nil)) // ## Compilation Error: Any doesn't conform to Eqautable Protocol ##
4

1 回答 1

0

您可以为此目的使用NSAttributedString实例方法。func isEqual(to other: NSAttributedString) -> Bool

于 2021-08-10T11:25:51.700 回答