访问类的属性并打印它们

时间:2018-02-17 06:06:18

标签: ios objective-c theos class-extensions

我有一个像这样的头文件:

@class NSMutableDictionary, NSString;

@interface randomclassname : NSObject
{
    unsigned long long _HTTPMethod;
    NSString *_path;
    unsigned long long _apiVersion;
    NSMutableDictionary *_parameters;
    NSMutableDictionary *_defaultParameters;

    NSMutableDictionary *_headers;
    _Bool _isSigned;
}
/// methods are down here
+ (id)builderWithHTTPMethod:(unsigned long long)arg1 path:(id)arg2;

我想访问并打印NSMutableDictionary *_defaultParameters;

unsigned long long _apiVersion;

我的方法对象中的以下属性。

+ (id)builderWithHTTPMethod:(unsigned long long)arg1 format:(id)arg2 
{
    **access those properties here and print them on NSlog.**
    return %orig; 
}

如果我错了,请随时纠正我。我不完全确定@interface中的内容是否被称为属性;我正在猜测。但这就是我想要访问的内容。

1 个答案:

答案 0 :(得分:0)

首先,您需要在.h文件中添加_defaultParameters和apiVersion作为属性

@property NSMutableDictionary *defaultParameters;
@property (assign) unsigned long long _apiVersion;

之后你可以在你的方法中使用param id作为randomclassname

+ (id)builderWithHTTPMethod:(unsigned long long)arg1 format:(id)arg2 
{
    //**access those properties here and print them on NSlog.**
    randomclassname *obj = (randomclassname*)arg2;
    NSLog(@"%@",obj.defaultParameters);
    return %orig; 
}