To answer my own question, changing the enum to an NSInteger backed NS_Enum 
resulted in no more bad access exceptions from other chunks of code attempting 
to change the APP_State property.

typedef NS_ENUM(NSInteger, APP_State) {
    APP_State_Normal = 0,
    APP_State_Expired = 1,
    APP_State_Waiting = 2
};

Changing the atomicity of the exposed property had no effect on whether the 
exception was issued or not.

Hope this helps someone.

Alex Zavatone



On Apr 7, 2015, at 10:04 AM, Alex Zavatone wrote:

> I've read Apple's docs on assuring KVO/KVC compliance, but in this particular 
> situation, I'd appreciate someone explaining what I'm not getting here if 
> it's anything obvious.
> 
> I think what I'm asking is how to convert code that has a state exposed as a 
> (nonatomic, readwrite) property of a typedef-ed enum so that it can be 
> observed by KVO.
> 
> The code that I've inherited has an enum (not an NSEnum) that represents the 
> app's connected state, 0, 1 or 2.
> 
> This enum is then typedef-ed and then exposed as a property through @property 
> (nonatomic, readwrite) 
> 
> This property is within the AppDelegate and is referred to and set throughout 
> the app.
> 
> 
> enum APP_State {
>    APP_State_Normal = 0,
>    APP_State_Expired = 1,
>    APP_State_Waiting = 2
> };
> typedef enum APP_State APP_State;
> 
> @property (nonatomic, readwrite) APP_State app_idle_state;
> 
> 
> So, I want to set up an approach to monitor this state and set a readout 
> graphic based upon the state's value. I had assumed that KVO would be the 
> path of least overhead and allow a rather self contained little class to 
> handle this without any nasty polling.  
> 
> Within a new class, I added an observer to the APP_State property on the 
> appDelegate and this operates as expected, but adding the KVO will trigger an 
> EXC_BAD_ACCESS when attempting to change the app_idle_state enum property 
> within another class that accesses that property in the delegate.
> 
> Specifically, this:
> 
> delegate.app_idle_state = APP_State_Waiting;
> 
> Results in this:
> Thread1: EXC_BAD_ACCESS (code=1,address = 0x003f8f3)
> 
> 
> First of all, I've never seen enum being attempted to be exposed like this 
> (would making this an NS_ENUM help?).
> 
> Also, I certainly was expecting *something* to go wrong here, but not causing 
> bad access exceptions elsewhere when code in another class attempts to set 
> the value of the property (since its property was set to readwrite).
> 
> Changing the property declaration to atomic seems to be more correct in that 
> we don't want any other operation to happen on it, but that doesn't doesn't 
> affect whether or not an EXC_BAD_ACCESS.
> 
> Or I could be walking down the wrong path entirely and should just poll for 
> the value or have a notification of a state change be sent to the monitoring 
> class.
> 
> 
> Thoughts?
> 
> Thanks in advance, 
> Alex Zavatone
> _______________________________________________
> 
> Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)
> 
> Please do not post admin requests or moderator comments to the list.
> Contact the moderators at cocoa-dev-admins(at)lists.apple.com
> 
> Help/Unsubscribe/Update your Subscription:
> https://lists.apple.com/mailman/options/cocoa-dev/zav%40mac.com
> 
> This email sent to z...@mac.com


_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to