Objective-C方法,它们唯一的参数是NSError对象引用,我应该如何命名它们?

时间:2022-06-07 16:59:04

I was designing a class and I realize that I've got several methods that the only parameter they have is the output parameter for errors. The problem is how should I name this methods, because they can get very confusing. I've been reading the Apple's Code Guidelines and it saids nothing about this. Here is an example:

我正在设计一个类,我意识到我有几个方法,他们唯一的参数是错误的输出参数。问题是如何命名这种方法,因为它们会变得非常混乱。我一直在阅读Apple的Code Code Guide,它对此一无所知。这是一个例子:

-(BOOL)loginError(NSError **) anError;

-(BOOL)loginWithUsername:(NSString *)aUsername password:(NSString *)aPassword error:(NSError **) anError;

The second one is very clear but the first one seems to be very confusing to me.

第二个很清楚,但第一个似乎对我来说很困惑。

What do you think?

你怎么看?

1 个解决方案

#1


11  

Apple use names such as

Apple使用的名称如

- (BOOL) saveValuesAndReturnError:(NSError **) error;

So, perhaps:

所以,也许:

- (BOOL) loginAndReturnError:(NSError **) error;

#1


11  

Apple use names such as

Apple使用的名称如

- (BOOL) saveValuesAndReturnError:(NSError **) error;

So, perhaps:

所以,也许:

- (BOOL) loginAndReturnError:(NSError **) error;