关于目标C的便捷方法的定义是什么? [英] What is the definition of Convenience Method in regards to Objective C?

查看:124
本文介绍了关于目标C的便捷方法的定义是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我处理过的大多数语言中,有一种叫做便捷方法,这意味着该方法执行的一些小任务非常频繁地执行,因此使用更加方便方法.

In most languages I have dealt with, one something is called a convenience method, it means that the method does some small task that gets done very frequently, and therefore it is more convenient to use said method.

在Objective-C中,此定义是否成立?还是通常只用于描述返回预建对象的类方法?前任. [NSString stringWithContentsOfFile:...]

In Objective-C does this definition hold true? Or is it generally only used to describe class methods that return a prebuilt object? ex. [NSString stringWithContentsOfFile:...]

这只是一个优先选择,还是这些术语有明确的定义?

Is this just a preference thing, or are there some hard and fast definition for these terms?

干杯, 斯蒂芬

推荐答案

您所说的实际上更具体地讲是Objective C中的便捷构造函数".(请注意,它实际上不是C ++/Java/C#中的构造函数.从某种意义上说,它实际上是一个对象初始化器/工厂方法,但似乎是调用便捷构造器"的约定. Obj C中的便捷构造函数"是用于为采用特定参数的类创建构造函数/初始化程序/工厂方法的约定或模式.此模式还具有一些应遵循的特殊约定(例如,在构造函数中自动释放新对象),以使您的自定义类与内置类型完全匹配.

What you are talking about is actually more specifically a "convenience constructor" in Objective C. (Note that it's not really a constructor in the C++/Java/C# sense, it's actually an object initializer/factory method, but it seems to be the convention to call the "convenience constructors"). "Convenience constructors" in Obj C are a convention or pattern for creating a constructor/initializer/factory method for a class which takes specific parameters. This pattern also has some special conventions that you should follow (such as autoreleasing the new object within the constructor), so that your custom classes fit in well with the built-in types.

有关更多信息,请参见此页面(略有下降): http://macdevcenter.com/pub/a/mac/2001/07/27/cocoa.html?page=3

See this page (a little way down) for more info: http://macdevcenter.com/pub/a/mac/2001/07/27/cocoa.html?page=3

对于便利方法",此特定术语在Objective C中没有任何特殊含义.您可以在Obj C中创建任何类型的便利方法,并且对它应该做什么或不应该做什么没有期望.这只是具有特殊含义的便捷构造函数".

As for "convenience method," this specific term doesn't have any special meaning in Objective C. You can create any type of convenience method in Obj C, and there is no expectation about what it should or should not do. It's only "convenience constructor" that has a special meaning.

这篇关于关于目标C的便捷方法的定义是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆