首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >可可NSFont“领先”属性生成错误

可可NSFont“领先”属性生成错误
EN

Stack Overflow用户
提问于 2019-11-11 05:13:22
回答 1查看 56关注 0票数 0

在AudioUnit插件中,我使用的是NSFont。

代码语言:javascript
复制
NSFontManager* fontManager = [NSFontManager sharedFontManager];
NSFont* nativefont = [fontManager fontWithFamily:[NSString stringWithCString: fontFamilyName.c_str() encoding: NSUTF8StringEncoding ] traits:fontTraits weight:5 size:fontSize ];

NSMutableParagraphStyle* style = [[NSMutableParagraphStyle alloc] init];
[style setAlignment : NSTextAlignmentLeft];

NSMutableDictionary* native2 = [[NSMutableDictionary alloc] initWithObjectsAndKeys:
                nativefont, NSFontAttributeName,
                    style, NSParagraphStyleAttributeName,
                    nil];

// .. later
void someFunction(NSMutableDictionary* native2)
{   
    float lineGap = [native2[NSFontAttributeName] leading];

编译器说(关于最后一行):从不兼容的类型 'NSCollectionLayoutSpacing * _Nullable‘分配给'float’

注意:自从切换到Xcode 11.1之后,这只是最近才失败的。XCode 11.1是在一个旧版本的XCode上构建的OK。任何帮助都很感激。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-11-11 06:53:40

在您的代码中,表达式native2[NSFontAttributeName]是未知类型的,因此属于id类型。编译器将允许您在没有抱怨的情况下发送类型为id的任何消息的对象,但它没有确定消息返回值类型的上下文。

您希望获得NSFontNSFont属性,但是编译器只是随机地选择任何leading属性选择器,我猜它最终选择了NSCollectionLayoutEdgeSpacingleading属性,该属性的返回类型为NSCollectionLayoutSpacing而不是float

我怀疑转换表达式[(NSFont*)(native2[NSFontAttributeName]) leading]会起作用,但是如果我正在编写这段代码,我只需引用原始(类型化)对象,因为您已经拥有它了:

代码语言:javascript
复制
float lineGap = nativefont.leading;
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/58795848

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档