简体   繁体   English

什么时候在iPhone中使用同时具有静态方法和实例方法的Class

[英]When to use a Class having both static methods and instance methods in IPhone

I have created a class which contain only static method in iPhone. 我创建了一个仅在iPhone中包含静态方法的类。 The class was mainly to do my core data operations. 该课主要是做我的核心数据操作。 But suddenly, I had a need to make a method call in a view controller, when an insertion of data in to a table got completed. 但是突然之间,当数据到表的插入完成时,我需要在视图控制器中进行方法调用。

At first, I decided to send an NSNotification , once the loop finishes iteration. 最初,我决定在循环完成迭代后发送NSNotification But then, since I need to use this only for single time, I decided not to go for NSNotificationCenter , instead to use delegation. 但是,由于我只需要使用一次,所以我决定不使用NSNotificationCenter ,而是使用委托。

Now I have many static method, and two instance methods: 现在,我有许多静态方法和两个实例方法:

//1
-(id)initWithDelegate:(id)delegate;

//2
-(void)insertContentsInToTheTableFromArray:(NSArray *)contentArray;

Is this a good design pattern, to have both instance methods and class methods in this class. 在此类中同时包含实例方法和类方法,这是一个好的设计模式吗? Please share your thoughts. 请分享您的想法。

We can use both method in one class. 我们可以在一个类中同时使用这两种方法。 We know that instance methods use an instance of a class, whereas a static method can be used with just the class name. 我们知道实例方法使用类的实例,而静态方法可以仅与类名一起使用。 But the static method is a convenience method that use on many foundation classes. 但是静态方法是在许多基础类上使用的便捷方法。

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

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