You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

iOS 16中NSLocalizedString跨Swift/OC传递的相等性判断异常求助

iOS 16下Swift与Objective-C本地化字符串-isEqualToString比较结果不一致的疑似Bug

在iOS 16中发现一个疑似Bug:当Swift侧通过NSLocalizedString获取的本地化字符串传递给Objective-C后,与Objective-C侧调用NSLocalizedString获取的同内容本地化字符串进行-isEqualToString:比较时,结果会因参数顺序不同而出现不一致。该问题在iOS 15中不存在,目前暂未明确根源是NSLocalizedString还是-isEqualToString:。

示例代码

Swift代码

class ViewController: UIViewController {
    override func viewDidLoad() {
        super.viewDidLoad()
        let tc = TestClass()
        tc.receive(NSLocalizedString("Start", comment:""))
    }
}

Objective-C代码

@implementation TestClass
- (void)receive:(NSString *)swiftString {
    NSString *objcString = NSLocalizedString(@"Start", @"");
    BOOL result1 = [swiftString isEqualToString:objcString];
    BOOL result2 = [objcString isEqualToString:swiftString];
    NSLog(@"result: %d, %d", result1, result2);
}
@end

本地化配置(以日语为例,非拉丁语系均可复现)

"Start" = "開始";

输出结果

result: 0, 1

请问是否有其他开发者遇到过这个问题?

内容的提问来源于stack exchange,提问作者刘maxwell

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.16 05:50:34