What is the preprocessor macro to test whether an application extension is being built?

前端 未结 3 1582
日久生厌
日久生厌 2021-02-04 06:18

This question is based purely on publicly released documents regarding the introduction of application extensions in iOS.

With the introduction of app extensions in iOS

3条回答
  •  情深已故
    2021-02-04 06:39

    Update: Unfortunately, it doesn't actually work because it is working in __has_feature(attribute_availability_app_extension)-feature manner. Sad.

    It is not actually that was asked but it is should be noted:

    If you are using Swift, you have @available(iOSApplicationExtension) attribute! It is not actually preprocessor's feature but it is kind of compile time feature.

    Example:

    @available(iOSApplicationExtension, message="It is meaningless outside keyboard extension")
    public var rootInputViewController: UIInputViewController {
        return storedInputViewController
    }
    

    Or with #-notation (but probably not):

    public static var rootInputViewController: UIInputViewController! {
        guard #available(iOSApplicationExtension 8, *) else {
            return nil
        }
    
        return storedInputViewController!
    }
    

提交回复
热议问题