27

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.

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
bmeikle
  • 291
  • 1
  • 3
  • 5
  • 1
    If the problem is in RevenueCat it isn't your code so there's nothing you can do. File a bug with the code authors and go back to Xcode 13. – matt Jul 13 '22 at 18:41
  • Check this: https://stackoverflow.com/questions/64797366/stored-properties-cannot-be-marked-potentially-unavailable-with-available – LoVo Jul 14 '22 at 06:58
  • I faced same issue, any one have solution pls share – Jitendra Chauhan Aug 25 '22 at 05:30
  • I've fixed it like this: https://stackoverflow.com/questions/41904724/using-available-with-stored-properties/73699790#73699790 – mirkancal Sep 13 '22 at 08:30

8 Answers8

21

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

Vishnu
  • 348
  • 2
  • 7
  • Is there a way to solving it not defining the iOS 14 as a global platform? – jed1 Sep 14 '22 at 19:25
  • In my code happened this issue was resolved like what i mentioned above. please mention your exact issue. This issue only happened when i was updating the latest Xcode version. @jed1 – Vishnu Sep 16 '22 at 07:12
13

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

kgaidis
  • 14,259
  • 4
  • 79
  • 93
12

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.
Syed Waleed
  • 967
  • 2
  • 5
  • 7
  • 1
    True story! This is the best solution for this project. This has happened due to some project discontinuation as I can remember. Thanks for documenting. – Randika Vishman Apr 27 '23 at 08:56
11

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

IvanPavliuk
  • 1,460
  • 1
  • 21
  • 16
3

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

George Lee
  • 814
  • 18
  • 34
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'

Renato Leal
  • 181
  • 2
  • 4
0

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

Yılmaz edis
  • 146
  • 3
  • 13
0

My case:

  1. Remove ios folder. (Should save your Info.plist)
  2. flutter create .
  3. Change ios to 14. (Pod file)
  4. flutter pub get => cd ios => pod install => cd .. => flutter run
Thang Tran
  • 171
  • 1
  • 5