skip to Main Content

I get this error when I run my app on Xcode 14 beta and I don’t know how to fix it:

Stored properties cannot be marked potentially unavailable with ‘@available’

It doesn’t pop up when I run Xcode 13, and the app runs smoothly. I am in the .xcworkspace file.

7

Answers


  1. I have this error in Flutter project in XCode 14. One of the external packages were using:

    @available(iOS 14.0, *)
    My current fix is:

    Update version in Podfile platform :ios, ‘14.0’,
    pod update &&
    Pod install

    Login or Signup to reply.
  2. Be sure to change both sections of the iOS Deployment Target in the Build Settings tab, like in my picture:
    enter image description here

    Login or Signup to reply.
  3. I had the same problem. As directed by the repository on GitHub, a workaround is to update the Podfile version: platform :ios, '14.0'

    Login or Signup to reply.
  4. In Xcode 13, and lower, you were able to compile if you used a lazy @available stored property as such:

    @available(iOS 10.0, *)
    private(set) lazy var center = UNUserNotificationCenter.current()
    

    However, this does not work in Xcode 14.

    Instead, you need to use a non-available stored property, and use a computed @available property:

    private var _selectionFeedbackGenerator: Any? = nil
    @available(iOS 10.0, *)
    fileprivate var selectionFeedbackGenerator: UISelectionFeedbackGenerator {
        if _selectionFeedbackGenerator == nil {
            _selectionFeedbackGenerator = UISelectionFeedbackGenerator()
        }
        return _selectionFeedbackGenerator as! UISelectionFeedbackGenerator
    }
    

    Answer source

    Login or Signup to reply.
  5. In my case the problem was in flutter_inappwebview package. I’ve fixed it by using the newest version – 5.4.4+3

    https://pub.dev/packages/flutter_inappwebview/install

    Login or Signup to reply.
  6. Let me tell you 100% working solution if this error is being raised due to DKImagePickerController.

    Follow these steps:

    1. Goto your Podfile and replace this https://github.com/miguelpruivo/DKImagePickerController.git url with this https://github.com/zhangao0086/DKImagePickerController.git url.
    2. In your flutter project run following commands:
      2.1) flutter clean
      2.2) flutter pub get
    3. Navigate to ios folder and run following commands:
      3.1) pod install (use arch -x86_64 pod install if you are using M1)
      3.2) pod update (use arch -x86_64 pod update if you are using M1)
    4. Run your project.
    Login or Signup to reply.
  7. Brother, I just find a solution for my project, It may comes to you workaround, but I still would like to share my experience about it;

    class MyClass {
        @available(iOS 15.0, *) // Stored properties cannot be marked potentially unavailable with '@available'
        var myProperty: String
    }
    

    Xcode offers us entire class to make @available

    @available(iOS 15.0, *)
    class MyClass {
        var myProperty: String
    }
    

    This is my workaround solution. You can use the @available attribute on its getter and setter methods instead of the property itself.

    class MyClass {
        private var myValue: String = ""
        
        @available(iOS 15.0, *)
        var myProperty: String {
            get {
                return myValue
            }
            set {
                myValue = newValue
            }
        }
    }
    

    This is from my real project;
    enter image description here

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search