在AudioUnit插件中,我使用的是NSFont。
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。任何帮助都很感激。
发布于 2019-11-11 06:53:40
在您的代码中,表达式native2[NSFontAttributeName]是未知类型的,因此属于id类型。编译器将允许您在没有抱怨的情况下发送类型为id的任何消息的对象,但它没有确定消息返回值类型的上下文。
您希望获得NSFont的NSFont属性,但是编译器只是随机地选择任何leading属性选择器,我猜它最终选择了NSCollectionLayoutEdgeSpacing的leading属性,该属性的返回类型为NSCollectionLayoutSpacing而不是float。
我怀疑转换表达式[(NSFont*)(native2[NSFontAttributeName]) leading]会起作用,但是如果我正在编写这段代码,我只需引用原始(类型化)对象,因为您已经拥有它了:
float lineGap = nativefont.leading;https://stackoverflow.com/questions/58795848
复制相似问题