Swift 3
に定数を宣言したいと思います。たとえば、Objective-Cで次のような定数がある場合:Objective-C定数をSwift型としてインポートする方法は?
HK_EXTERN NSString * const HKQuantityTypeIdentifierHeight;
HK_EXTERN NSString * const HKQuantityTypeIdentifierBodyMass;
Swift 3
に定数を宣言したいと思います。たとえば、Objective-Cで次のような定数がある場合:Objective-C定数をSwift型としてインポートする方法は?
HK_EXTERN NSString * const HKQuantityTypeIdentifierHeight;
HK_EXTERN NSString * const HKQuantityTypeIdentifierBodyMass;
新スウィフトのファイルを追加します。ViewController.swift
print(HK_EXTERN_Height)
print(HK_EXTERN_BodyMass)
・ホープ、このヘルプあなた....
Thanx :)私を助けるために –
@MohsinQureshiいつでも:) –
私はSwift言語を信じることができます。
でConstant.swift
import Foundation
import HealthKit
let HK_EXTERN_Height : NSString = HKQuantityTypeIdentifierHeight
let HK_EXTERN_BodyMass : NSString = HKQuantityTypeIdentifierBodyMass
使用してに定数を追加しますSwiftでは別のファイルも作成できます。あなたがstructs
を使用する場合、定数の膨大な数が乱雑できるため、定数を使用するための
は、それが、でも賢くです:
import HealthKit
struct Constants {
struct Health {
struct Quantities {
let height : NSString = HKQuantityTypeIdentifierHeight
let bodyMass : NSString = HKQuantityTypeIdentifierBodyMass
static let minWeight: Double = 30.0
}
...
}
...
}
使用法:
print(Constants.Health.Quantities.minWeight)
または
let healthNumbers = Constants.Health.Quantities
print(healthNumbers.minWeight)
あなたはグローバル定数を宣言したいですか? –