개발/swift

Swift @available and #available

lemonade 2020. 11. 10. 10:00
반응형

The difference between @available and #available


When we’d like to adopt new feature in newer swift version, we can use available attribute! 

So that not give up supports for older version.

You may have seen #available and @available. They are almost same but different little bit.

 

@available is used to mark the availability for a class or method.

#available is used to only execute a piece of code for specific platforms or versions

 

 

 


#available used like this in code.

 

 


On the other hand, @available used like this. You often see @available attribute in swift APIs. 

 

 

 


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 error.  You could fix it like this.


Another attribute value is used to mark methods as deprecated or obsoleted. 

Methods start as being deprecated and will eventually be marked as obsoleted.

 

 

 

Happy Coding :)

 

 

반응형
그리드형

'개발 > swift' 카테고리의 다른 글

Swift UIControls with closures  (0) 2020.11.12
Swift URLComponents  (0) 2020.11.12
Swift everything about launch screen  (0) 2020.11.07
Swift how to fix autolayout issue?  (0) 2020.11.05
Swift UICollectionView performBatch  (0) 2020.11.04