标签:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
|
class Test { var _index = 0 var index: Int { get { return _index } set { _index = newValue if _index < 0 { _index += 3 } else if _index > 2 { _index -=3 } } } func onNext(){ index++ } func onPre(){ index-- } } |
Swift - 使用set,get确保索引加减在正常的范围内
标签:
原文地址:http://www.cnblogs.com/Free-Thinker/p/4838617.html