[swift-users] How to write better Swift

Geordie J geojay at gmail.com
Mon Jul 10 10:35:21 CDT 2017


Would "didSet" on a normal variable work for you?

var status: Int {
  didSet { doSomething() }
}

Geordie


> Am 10.07.2017 um 17:34 schrieb Gerriet M. Denkmann via swift-users <swift-users at swift.org>:
> 
> This works (Xcode Version 8.3.2 (8E2002)):
> 
> class SomeClass
> {
> 	private var privateStatus: Int	
> 
> 	var status: Int
> 	{
> 		get{ return privateStatus }
> 		set(new)
> 		{
> 			if new == privateStatus {return}
> 		
> 			… do something here …
> 
> 			privateStatus = new
> 		}
> 	}
> }
> 
> But is this “privateStatus” really necessary?
> If not, how can it be avoided?
> 
> Gerriet.
> 
> _______________________________________________
> swift-users mailing list
> swift-users at swift.org
> https://lists.swift.org/mailman/listinfo/swift-users



More information about the swift-users mailing list