Translating KVO-ed property to Swift

2017-04-17 Thread Rick Mann
I have a number of properties in Objective-C written like this, short-circuiting notifications when the value doesn't change: - @synthesize version = mVersion - (void) setVersion: (NSString *) inVersion { if (inVersion == nil && mVersion == nil) { return; } if

Re: Translating KVO-ed property to Swift

2017-04-17 Thread Jean-Daniel
One way to solve that is to declare an explicit private stored property for the ivar, and a public computed property for the logic. private var _version: String? = nil var version: String? { get { return _version } set { your set version code } } > Le 17 avr. 2017 à 10:24, Rick

Re: Translating KVO-ed property to Swift

2017-04-17 Thread Quincey Morris
On Apr 17, 2017, at 01:24 , Rick Mann wrote: > > I have a number of properties in Objective-C written like this, > short-circuiting notifications when the value doesn't change: Not in this code you don’t, unless you have a “automaticallyNotifiesObserversOfVersion” method returning false elsewh

Re: Translating KVO-ed property to Swift

2017-04-17 Thread Quincey Morris
On Apr 17, 2017, at 01:43 , Jean-Daniel wrote: > > var version: String? { A slight correction: this declaration actually must be: > dynamic var version: String? { otherwise KVO isn’t guaranteed to work in Swift. ___ Cocoa-dev mailing list (Cocoa-d

Re: Translating KVO-ed property to Swift

2017-04-17 Thread Jean-Daniel
> Le 17 avr. 2017 à 10:52, Quincey Morris > a écrit : > > On Apr 17, 2017, at 01:43 , Jean-Daniel > wrote: >> >> var version: String? { > > A slight correction: this declaration actually must be: > >> dynamic var version: String? { > > > otherwise KVO isn’t gu

Re: Help Indexing

2017-04-17 Thread Jerome Krinock
> On 2017 Apr 14, at 18:17, Frank D. Engel, Jr. wrote: > > In my Help Book, my working anchors use `id` instead of `name`. I forgot why. Example: 2.3.1  Testing Syncing in Smarky >NSLog(@"help: '%@'", what); >NSString *locBookName = [[NSBundle mainBundle] objectForInfoDictionaryKe

Re: Translating KVO-ed property to Swift

2017-04-17 Thread Charles Srstka
> On Apr 17, 2017, at 3:24 AM, Rick Mann wrote: > > I have a number of properties in Objective-C written like this, > short-circuiting notifications when the value doesn't change: > > - > @synthesize version = mVersion > > - (void) > setVersion: (NSString *) inVersion > { >if (

Re: Reference to embedded view controller in IB?

2017-04-17 Thread Alex Zavatone
I wrote some stuff to find your view controller within the storyboard and/or within the view hierarchy based on the class name of the view controller. Some of it is a little new some of it is a little old. One trick (on iOS) is that you will need to check if your root controller is a nav contr

Re: Translating KVO-ed property to Swift

2017-04-17 Thread Quincey Morris
On Apr 17, 2017, at 05:40 , Jean-Daniel wrote: > This is a good practice, but I don’t think this is required for computed > property, especially if you take care of willChange/didChange manually, as > the OP does. Here is what the Swift interoperability documentation says (https://developer.a

Re: Translating KVO-ed property to Swift

2017-04-17 Thread Charles Srstka
> On Apr 17, 2017, at 1:09 PM, Quincey Morris > wrote: > > On Apr 17, 2017, at 05:40 , Jean-Daniel wrote: > >> This is a good practice, but I don’t think this is required for computed >> property, especially if you take care of willChange/didChange manually, as >> the OP does. > > Here is w

Re: Translating KVO-ed property to Swift

2017-04-17 Thread Quincey Morris
On Apr 17, 2017, at 12:03 , Charles Srstka wrote: > > You cannot guarantee that the property will be called via objc_msgSend, which > is important if you’re relying on the swizzled accessor to send the property > notifications. If you’re sending them yourself, it doesn’t matter one way or > an

Re: Translating KVO-ed property to Swift

2017-04-17 Thread Rick Mann
Thanks, Charles, that's helpful. In the end I left the class as Obj-C, because I still had to derive from it in Obj-C and you annoyingly can't do that. > On Apr 17, 2017, at 08:06 , Charles Srstka wrote: > >> On Apr 17, 2017, at 3:24 AM, Rick Mann wrote: >> >> I have a number of properties in