Posts

Showing posts from November, 2019

Attributes in Swift @available

Image
Attributes in Swift In Swift Attributes are used to provide some kind of additional information to a declaration or a type. For example if I want a function to be just available for iOS 12 version onwards. The Swift compiler will give warnings in such cases and provides suggestion to fix it as shown below. You can download the example for it from GitHub How do we declare an attribute? Attribute declaration starts with " @ " symbol and can also arguments which is enclosed in parentheses. Arguments specify some more information on how it applies to the existing attribute declaration. @ attributename ( attributearguments ) Example:  Here we have used attribute available and also gave more information on how it applies to the declaration , in this case it's only for iOS platform and available from12.5 version onwards.     @available (iOS,introduced: 12.5)     func methodForiOS12_5_only () {           } Types of Attributes in Swift T