• Swift


    struct CenterPoint {
        var x = 0,y = 0
    }
    func + (left:CenterPoint,right:CenterPoint) -> CenterPoint {
        return CenterPoint.init(x: left.x + right.x, y: left.y + right.y)
    }
    func == (left:CenterPoint,right:CenterPoint) -> Bool {
        return (left.x == right.x) && (left.y == right.y)
    }
    func != (left:CenterPoint,right:CenterPoint) -> Bool {
        return !(left == right)
    }
    func += (left:inout CenterPoint,right:CenterPoint){
         left = left + right
        print(left)
    }
    class AreaViewController: UIViewController {
    
        override func viewDidLoad() {
            super.viewDidLoad()
            self.view.backgroundColor = UIColor.white
            //1.0,闭区间运算符:a...b
            for icount in 512...1000 {
                print(icount)
            }
            //1.2,半闭区间运算符:a..<b
            var fruits = ["apple","orange","banana"]
            for i in 0..<fruits.count {
                print("i---(fruits[i])")
            }
            fruits.append("Longan")
            
            //1.3,倒序循环
            for j in (0..<10).reversed() {
                print(j)
            }
            //1.4,字符串范围也可以使用区间运算符
            let words = "mujin.com"
            let index = words.index(words.startIndex, offsetBy: 4)
            let index2 = words.index(words.startIndex, offsetBy: 6)
            let range1 = Range(uncheckedBounds: (lower: index, upper: index2))
            let rangeStr1 = String(words[range1]) //ge
            print(rangeStr1)
            //使用区间运算符
            let range2 = words.index(words.startIndex, offsetBy: 4)..<words.index(words.startIndex, offsetBy: 6)
            let rangeStr2 = String(words[range2])
            print(rangeStr2)
            
            //1.5,区间运算符除了返回一个Range外,还可以接受Comparable的输入,返回ClosedInterval或HalfOpenInterval
            let interval = "a"..."z"
            for c in words {
                if !interval.contains(String(c)){
                    print("(c)不是小写字母")
                }
            }
            //通过 + 进行方法重载相加
            var point1 = CenterPoint.init(x: 2, y: 3)
            let point2 = CenterPoint.init(x: 4, y: 5)
            let point3 = point1 + point2
            print(point3)
            print(point1 == point2)
            print(point1 != point2)
            point1 += point2
        }
  • 相关阅读:
    google的开源项目总结
    Google Breakpad 完全解析(二) —— Windows前台实现篇
    Google Breakpad 完全解析(一) —— Windows入门篇
    PVS-Studio静态通用分析规则
    C,C++开源项目中的100个Bugs
    一日一点RakNet(3)--介绍
    C++开源跨平台类库集
    如何实现数组的随机排序?
    JavaScript原型,原型链 ? 有什么特点?
    js的基本数据类型
  • 原文地址:https://www.cnblogs.com/edensyd/p/9405994.html
Copyright © 2020-2023  润新知