我不知道如何將以下 Objective-C 代碼轉換為 Swift,因為我之前沒有使用過 Objective-C。我應該怎么做?如果有人遇到過類似的事情,將不勝感激下面的 Objective-C 代碼在 Swift 中的樣子。
// header (.h) file:
#import <UIKit / UIKit.h>
@interface UIDevice(SystemVersion)
- BOOL systemVersionLessThan: (NSString *) target
@end
// implementation (.m) file
#import "UIDevice SystemVersion.h"
@implementation UIDevice(SystemVersion)
- BOOL systemVersionLessThan: (NSString *) target {
[[self systemVersion] compare: target options: NSNumericSearch] == NSOrderedAscending
}
我似乎無法理解在 Swift 中執行此操作的正確方法。這更有可能與它真正應該的相去甚遠。
import UIKit
extension UIDevice {
func SystemVersion() {
if systemVersionLessThan -> {}
}
}
uj5u.com熱心網友回復:
直譯是_
extension UIDevice {
func systemVersionLessThan(_ target: String) -> Bool {
systemVersion.compare(target, options: .numeric) == .orderedAscending
}
}
您也可以使用
extension UIDevice {
func systemVersionLessThan(_ target: String) -> Bool {
systemVersion.localizedStandardCompare(target) == .orderedAscending
}
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/537851.html
標籤:迅速目标-c用户界面设备
