[英]Updating Objective-C syntax with Swift equivalent for unused static
I am stuck on translating a method from the following bit. 我被困在翻译下面的方法。
In original Objective-C, the method is: 在原始的Objective-C中,方法是:
+ (CGFloat)defaultFontSize
{
CGFloat pointSize = 16.0;
NSString *contentSizeCategory = [[UIApplication sharedApplication] preferredContentSizeCategory];
pointSize += SLKPointSizeDifferenceForCategory(contentSizeCategory); //stucj here
return pointSize;
}
In Swift, I have done the following so far: 到目前为止,在Swift中,我已完成以下操作:
let defaultFontSize: Float {
get {
let pointSize = 16.0
let contentSizeCategory = UIApplication.shared.preferredContentSizeCategory
//What do here for SLKPointSizeDifferenceForCategory?
}
}
In particular, I don't know how to translate SLKPointSizeDifferenceForCategory
, which is an unused static CGFloat
: 特别是,我不知道如何转换
SLKPointSizeDifferenceForCategory
,它是unused static CGFloat
:
__unused static CGFloat SLKPointSizeDifferenceForCategory(NSString *category)
{
if ([category isEqualToString:UIContentSizeCategoryExtraSmall]) return -3.0;
if ([category isEqualToString:UIContentSizeCategorySmall]) return -2.0;
if ([category isEqualToString:UIContentSizeCategoryMedium]) return -1.0;
if ([category isEqualToString:UIContentSizeCategoryLarge]) return 0.0;
if ([category isEqualToString:UIContentSizeCategoryExtraLarge]) return 2.0;
if ([category isEqualToString:UIContentSizeCategoryExtraExtraLarge]) return 4.0;
if ([category isEqualToString:UIContentSizeCategoryExtraExtraExtraLarge]) return 6.0;
if ([category isEqualToString:UIContentSizeCategoryAccessibilityMedium]) return 8.0;
if ([category isEqualToString:UIContentSizeCategoryAccessibilityLarge]) return 10.0;
if ([category isEqualToString:UIContentSizeCategoryAccessibilityExtraLarge]) return 11.0;
if ([category isEqualToString:UIContentSizeCategoryAccessibilityExtraExtraLarge]) return 12.0;
if ([category isEqualToString:UIContentSizeCategoryAccessibilityExtraExtraExtraLarge]) return 13.0;
return 0;
}
Any guidance is much appreciated. 任何指导是非常感谢。
That's just a function that returns a CGFloat
: 那只是一个返回
CGFloat
的函数:
func SLKPointSizeDifference(for category: UIContentSizeCategory) -> CGFloat {
typealias c = UIContentSizeCategory // for the sake of reducing boilerplate below
switch category {
case c.extraSmall: return -3
case c.small: return -2
case c.medium: return -1
case c.large: return 0
case c.extraLarge: return 2
case c.extraExtraLarge: return 4
case c.extraExtraExtraLarge: return 6
case c.accessibilityMedium: return 8
case c.accessibilityLarge: return 10
case c.accessibilityExtraLarge: return 11
case c.accessibilityExtraExtraLarge: return 12
case c.accessibilityExtraExtraExtraLarge: return 13
default: return 0
}
}
__unused
is just a flag that tells the compiler not to warn if that function is never used. __unused
只是一个标志,告诉编译器不要警告该函数是否从未使用过。 See more here . 在这里查看更多。
static
just limits the scope of that function's existence to the current file. static
只是将该函数的存在范围限制为当前文件。
UIContentSizeCategory
is imported into Swift as a struct, which is more strongly typed than just using raw strings. UIContentSizeCategory
作为结构导入到Swift中,它的类型比仅使用原始字符串要强。
__unused
only tells the compiler "don't warn me if I don't use this variable". __unused
仅告诉编译器“如果我不使用此变量,请勿警告我”。 , and in this context I believe that means no warning should be shown if the result of SLKPointSizeDifferenceForCategory
goes unused. ,在这种情况下,我认为如果
SLKPointSizeDifferenceForCategory
的结果未使用,则不会显示任何警告。
As for the Slack SDK function you're trying to port , why not simply include SlackTextViewController in your bridging header and then you can pick up the original function like magic. 至于要尝试移植的Slack SDK函数 ,为什么不直接在桥接头中包含SlackTextViewController,然后再选择像魔术一样的原始函数。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.