Note that there are some explanatory texts on larger screens.

plurals
  1. POInherited Properties not working
    text
    copied!<p>I am having issues getting something to work in objective c. I have the following protocol:</p> <pre><code>@protocol PFItem &lt;NSObject&gt; - (NSNumber *)weight; - (NSNumber *)cost; @end </code></pre> <p>This protocol is implemented in the following class:</p> <pre><code>@interface PFItemObject : NSObject &lt;NSCoding, PFItem&gt; { NSString *name; NSNumber *weight; NSNumber *cost; } @property (retain, nonatomic) NSString *name; @property (retain, nonatomic) NSNumber *weight; @property (retain, nonatomic) NSNumber *cost; @property (readonly) NSString *className; + (id)itemWithString:(NSString *)string; @end </code></pre> <p>Now, this works well for me, except when I use the PFItemObject as a superclass like so:</p> <pre><code>@interface PFWeaponObject : PFItemObject &lt;NSCoding, PFItem&gt; { NSString *damage; NSString *critical; NSString *range; NSNumber *attackBonus; NSNumber *damageBonus; WeaponTypes type; BOOL isTwoHanded; } @property (retain, nonatomic) NSString *damage; @property (retain, nonatomic) NSString *critical; @property (retain, nonatomic) NSString *range; @property (retain, nonatomic) NSNumber *attackBonus; @property (retain, nonatomic) NSNumber *damageBonus; @property WeaponTypes type; @property BOOL isTwoHanded; + (PFWeaponObject *)unarmedWeapon; @end </code></pre> <p>The <code>+itemWithString:</code> method, in the <code>PFWeaponObject</code> works like this:</p> <pre><code>+ (id)itemWithString:(NSString *)string { NSArray *components = [string componentsSeparatedByString:@";"]; PFWeaponObject *weapon = [[PFWeaponObject alloc] init]; [weapon setName:[components objectAtIndex:0]]; [weapon setWeight:[NSNumber numberWithFloat:[[components objectAtIndex:1] floatValue]]]; [weapon setCost:[NSNumber numberWithInt:[[components objectAtIndex:2] intValue]]]; [weapon setDamage:[components objectAtIndex:3]]; [weapon setCritical:[components objectAtIndex:4]]; [weapon setRange:[components objectAtIndex:5]]; [weapon setType:[[components objectAtIndex:6] integerValue]]; [weapon setAttackBonus:[NSNumber numberWithInt:[[components objectAtIndex:7] intValue]]]; [weapon setDamageBonus:[NSNumber numberWithInt:[[components objectAtIndex:8] intValue]]]; [weapon setIsTwoHanded:[[components objectAtIndex:9] boolValue]]; return [weapon autorelease]; } </code></pre> <p>I assumed that, because I have inherited from the PFItemObject, I should be able to assign values to the superclass' properties without problem. But when I do the following:</p> <pre><code>- (void)testItemCreationStrings { NSString *weaponString = @"+1 Greatsword;25;2500;2d6;x3;Melee;5;1;1;YES"; PFWeaponObject *sampleWeapon = [PFWeaponObject itemWithString:weaponString]; } </code></pre> <p>All properties from the superclass (<code>PFItemObject</code>) all return <code>@"+1 Greatsword"</code>. Did I miss something somewhere that I should have done?</p> <p>Thanks for any help you can provide, and please, feel free to ask for more information if you need it.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload