Imagine having an app in which the app introduction will no longer be shown on iOS 14 and up. Methods start as being deprecated and will eventually be marked as obsolete. } Marking a method as deprecated or obsoletedĪnother attribute value is used to mark methods as deprecated or obsoleted. You could specify multiple platforms at once as well if 15, macOS 12.0, *) The asterisk indicates the availability of the declaration on all of the platform names listed above unless specified specifically. Options include platforms as well as the swift key to mark pieces of code as available since a specific Swift version. The list of available attributes as of today is as follows: The platform, in this case, iOS, can be replaced too. Obviously, we could replace the number 14 with any OS version that’s available. However, there’s much more we can do with the available attribute in Swift. In the above examples, we’ve only made use of iOS 14 checks. } Possible values for the available attribute We could do exactly the same for methods using the 14, *) Let appIntroduction = NewAppIntroduction() The #available will help us in this case: Two of them will move the problem to a different place in your code by marking the calling class as available since iOS 14 too. Once you’ll try to create an instance of this class inside a project that supports versions lower than iOS 14 you’ll run into the following error:Īn error occurs if you’re creating an instance that is not available.Īs you can see, the compiler will help us to fix this error with a few suggestions. We can demonstrate this by marking a class or method as available since iOS 14, *) Setting the availability for a class or method
0 Comments
Leave a Reply. |