尝试通过索引从 NSMutableArray 属性中获取枚举值,该属性填充了枚举值。
我想要的只是设置一个动态属性并在类实例中重新设置。
因此,我编写了一个暴露问题的清晰示例。
问题是这样的。示例中的 WriteByType 方法永远不会获得正确的值。它应该记录“你得到正确的箭头”,但它没有
//----------------------------------------------------------
// CCMyClass.h
#import <Foundation/Foundation.h>
typedef enum {
aLeft,
aRight
} Arrow;
@interface CCMyClass : NSObject
{
NSMutableArray *_arrowsPkg;
}
@property(nonatomic,copy) NSMutableArray *arrowsPkg;
@property (nonatomic)int nextPkgIndex;
-(void)GetItemOne;
@end
//-------------------------------------------------------------
// CCMyClass.m
#import "CCMyClass.h"
@implementation CCMyClass
@synthesize arrowsPkg=_arrowsPkg;
-(void)WriteByType:(Arrow)AArrow
{
switch (AArrow) {
case aLeft:
NSLog(@"You Get Left Arrow");
break;
case aRight:
NSLog(@"You Get Right Arrow");
break;
}
}
-(void)GetItemOne
{
Arrow a =(Arrow)[[self arrowsPkg]objectAtIndex:1];
[self WriteByType:a];
}
@end
//---------------USAGE EXAMPLE----------------------------------------------
// CCAppDelegate.m
- (IBAction)btn1Clicked:(id)sender {
CCMyClass *c1=[[CCMyClass alloc]init];
NSNumber *v1=[NSNumber numberWithInt:aLeft];
NSNumber *v2=[NSNumber numberWithInt:aRight];
NSMutableArray *arr1=[NSMutableArray arrayWithObjects:v1,v2, nil];
[c1 setArrowsPkg:arr1];
[c1 GetItemOne];
}