Mohsin Qureshi Mohsin Qureshi - 2 months ago 16
iOS Question

How we can Import Objective-C Constants as Swift Types?

I want to declare constant in

Swift 3
. For example if we have following constant in Objective-C :

HK_EXTERN NSString * const HKQuantityTypeIdentifierHeight;
HK_EXTERN NSString * const HKQuantityTypeIdentifierBodyMass;

Answer

Add New Swift file : Constant.swift

import Foundation
import HealthKit

let HK_EXTERN_Height : NSString = HKQuantityTypeIdentifierHeight
let HK_EXTERN_BodyMass : NSString = HKQuantityTypeIdentifierBodyMass

Use in ViewController.swift

print(HK_EXTERN_Height)
print(HK_EXTERN_BodyMass)

Hope this help you....

Comments