gpt4 book ai didi

ios - 用于 Swift 字典键的 NSGliff - 使用 uintptr_t?

转载 作者:行者123 更新时间:2023-11-29 02:30:48 26 4
gpt4 key购买 nike

我需要使用 NSGlyph 作为 Swift 字典中的键

var glyph:NSGlyph //set to a glyph
var glyphDict:[NSGlyph:CGPath] //Will contain a cache of glyphs previously converted to paths
var path = glyphDict[glyph]

但我得到:

error: '[NSGlyph : CGPath]?' does not have a member named 'subscript'

所以我猜苹果还没有为 NSGlyph 定义下标?

我从 Apple 的 VectorTextLayer 示例代码中找到了这段代码,它成功地使用 CGGlyph 作为 CFDictionary 中的键。我如何调整它以使其在 Swift 字典中工作?

    CGPathRef path = (CGPathRef)CFDictionaryGetValue(glyphDict, (const void *)(uintptr_t)glyph);

我知道代码正在将 CGGlyph 包装到 uintptr_t 中。我怎样才能在 Swift 中做到这一点?

最佳答案

我认为您在问题中复制了不同的代码。当您用作字典的变量是可选的时会发生该错误,因此声明为:

var glyphDict:[NSGlyph:CGPath]?

要解决这个问题,您可以使用可选链接从字典中读取:

var path = glyphDict?[glyph]

请注意,path 本身是可选的。

关于ios - 用于 Swift 字典键的 NSGliff - 使用 uintptr_t?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26904697/

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