繁体   English   中英

使用在类方法中作为参数创建的实例变量

[英]using instance variables that created as a parameter inside the class method

抱歉,我想问一些基本的问题,但是我无法弄清楚为什么我无法使用class方法中的参数。

这是我需要帮助的。 API.h

@class User;
@interface API : NSObject
@property (nonatomic,readonly,retain)NSString *StoreIdentifierForVendor;
+(NSURLSessionDataTask *)MethodForMakingTheRequestWithBlock:(void(^)(NSString *username, NSError *error))block;
@end

APILibrary.m

@implementation API
@synthesize StoreIdentifierForVendor;
+(NSURLSessionDataTask *)MethodForMakingTheRequestWithBlock:(void(^)(NSString * username, NSError *error))block
{
    id loginDict = @{"NickName": username}
}
@end

我遇到的问题是,我不明白为什么会收到“使用未声明的标识符'用户名'错误。我试图将其设置为

@property(nonatomic,copy)NSString *username;

同样,但是我无法将其作为参数。 为什么我不能在词典中使用用户名?

username变量已声明为块的参数,因此仅当您尝试在以该块为参数的方法内部尝试访问它时才可以在该块内使用。 就像尝试访问全局范围内的局部变量一样。 那里不存在

您将一个块传递给MethodForMakingTheRequestForBlock方法,该块采用NSString *类型的参数。 该参数恰好被称为username ,但这仅表示块内的内容。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM