Swift标准库函数

前端之家收集整理的这篇文章主要介绍了Swift标准库函数前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。


pathway:

The code don't have seen,then search.


1. abs 返回数字的绝对值

数轴上的点到原点的距离叫做绝对值

abs(Int32)

        let number1 = abs(-12.4);
        
        let number2 = abs(-12);
        
        let number3 = abs(-13.0011 / 2);
  
        // print result: 12.4,12,6.50055

2. contains(sequence,element)

如果某个序列sequence(比如说一个数组)包含指定的元素element,则返回

true,否则返回false。

let languages = ["Swift","Objective-C"]
        
        let isInclude1 = languages.contains("Swift");
      
        let isInclude2 = languages.contains("Java");
 
        // print result : true false

学自:http://letsswift.com/2014/06/74-swift-library-functions/

原文链接:https://www.f2er.com/swift/323269.html

猜你在找的Swift相关文章