我想要一个看起来像这个player.type.property的结果,一个例子是UILabel,self.label.text。 .text是两个类的属性。两类的属性
我有一个建议是,做这样的事情:
player.type = [[MyCustomObject alloc] init];
player.type.property = @"value";
虽然我不太清楚究竟如何去正确地这样做,每次我都试过的方法是行不通的。
这是我曾尝试:
Marketplace.h
#import "Item.h"
@interface Marketplace : NSObject
@property (nonatomic, assign) Item *market;
Item.h
@interface Item : NSObject
@property (nonatomic, assign) int price;
Starter.m
#import "Marketplace.h"
#import "Item.h"
@implementation MainGameDisplay
{
Marketplace *market;
Item *itemName;
}
-(void) executedMethod {
market.itemName = [[market alloc] init];
//2 errors: "Property 'itemName not found on object of type 'MarketPlace'" and "No visible @interface for 'MarketPlace' declares the selector alloc"
market.itemName.price = 5; //"Property 'itemName' not found on object of type 'Marketplace*'"
}
@VitalyS。我不知道如何定义属性类型并初始化它。而通过MyCustomObject,它指的是哪个对象,玩家还是类型? – PappaSmalls 2013-04-04 10:48:04
你究竟想要什么?你尝试过什么方法?请详细说明你的问题。 – HAS 2013-04-04 10:59:39
@VitalyS。我编辑了我的问题来展示我所做的。 – PappaSmalls 2013-04-04 11:11:14