Questions tagged [class-method]

Methods that are called on a class instead of on an object.

Class methods are methods that are called on a class (compare this to class instance methods, or object methods). Its meaning may vary depending on the programming language: In some languages (e.g. C++, Java), class methods are synonymous with static methods (see section below), which are called with a known class name at compile-time. this cannot be used in static methods.

In some other languages (e.g. Smalltalk, Ruby, Objective-C), class methods are methods that are called on a class object, which can be computed at runtime, there being no difference between calling a method on a regular object or a class object; thus both instance and class methods are resolved dynamically, and there are no "static" methods. Notably, in these class methods, this refers to the class object.

Some languages have both. For example, in Python, one can create class methods and static methods using the classmethod and staticmethod decorators, respectively. The former has access to this (i.e. the instance object, conventionally known as self), while the latter does not.

904 questions
0
votes
2 answers

Call a class method for NSArray

I have this code and I want to call this class method to obtain some parameters for an imageView but I don't know how to call it, can you help me ? + (NSArray*)getRGBAsFromImage:(UIImage*)image atX:(int)xx andY:(int)yy count:(int)count
cyclingIsBetter
  • 17,447
  • 50
  • 156
  • 241
0
votes
2 answers

Incomplete implementation of class method - what is missing?

I have changed one of my instance methods to a class method so that it can be accessed from another class. The method is successfully called, but I have one warning on my code: Incomplete implementation (on the line '@implementation…
CaptainProg
  • 5,610
  • 23
  • 71
  • 116
0
votes
1 answer

No such test method / unbound error

I have overridden the unittest.TestCase class to include some additional functionality like this class TestCase(unittest.TestCase): def foo(self): return 4711 which I am going to use in the setUpClass call in a Test Case like this class…
Alex
  • 41,580
  • 88
  • 260
  • 469
0
votes
0 answers

memory management in class method in iOS

I have problems with memory in my class methods. I have created a class method which will fetch records from core data and return a NSArray. These are the problem i face: sometimes the data is returned properly, it works fine. sometimes it returns…
cancerian
  • 942
  • 1
  • 10
  • 18
0
votes
1 answer

No visible interface for AppDelegate declares the selector

AppDelegate.h: @interface AppDelegate : UIResponder + (MBProgressHUD *)showGlobalProgressHUDWithTitle:(NSString *)title; AppDelegate.m: + (MBProgressHUD *)showGlobalProgressHUDWithTitle:(NSString…
soleil
  • 12,133
  • 33
  • 112
  • 183
0
votes
1 answer

`initialize': undefined method `dirpathname=' for CheckDir:Class (NoMethod Error)

I am a new ruby guy and I tried to make a small program, but something is bugging me that I can't find solution. Please advise me. I am using Ubuntu 12.04 there would be 3 files. main.rb, create.rb and check.rb when I run this problem I got an error…
0
votes
1 answer

Tagging methods in a module for reference from mixing-classes

I have a module M which I want to tag specific methods as "special", in such a way that classes which mix in this module can check whether a given method name is special. This is what I've tried: module M def specials @specials ||= {} end …
Suan
  • 34,563
  • 13
  • 47
  • 61
0
votes
1 answer

setting a protocol's base class property to a method using a selector or a block

I am creating an interface/protocol that will be used for iOS grid views. Im trying to encapsulate as much information within the class, leaving very little info to the user of the class and its subclasses. I'm stuck at what a callback method or a…
Ælex
  • 14,432
  • 20
  • 88
  • 129
0
votes
4 answers

Using class methods of a certain objects class

Say you have class A, which classes A1, A2, and A3 inherit from. All four classes implement a class method: + (NSString *)idString; Now say you have an object A *object1; //object may be of type A1, A2, or A3 Is there any way to call the…
Randall Schmidt
  • 93
  • 1
  • 12
0
votes
1 answer

Would subclasses be able to access this method?

This is part of the code for a class method in the class BNRItem, which returns an id object. The author wrote that the key word self should be used when allocating, so that subclasses can also access this method. But wouldn't subclasses be unable…
stumped
  • 3,235
  • 7
  • 43
  • 76
0
votes
5 answers

use of class methods in iOS

I know the difference between class methods and object methods but I am not clear for why we use class methods in iOS? can anyone give me example so I can understand that..??
user7388
  • 1,741
  • 2
  • 19
  • 25
0
votes
4 answers

In PHP, is it possible to have a function within a class that's non-static, but also isn't an instance function?

In PHP, is it possible to have a function within a class that's non-static, but also isn't an instance function? For example, if I have the following: class A { public $i; function setValue($val) { $this->i = $val; } } $a1 = new…
Turgs
  • 1,729
  • 1
  • 20
  • 49
0
votes
1 answer

Adding convenience static / class methods without removing or breaking existing implementation

I am getting the hang of the OOP paradigm, and the art of making expandable and reusable code is something I want to improve at. Let's say in theory that I have a Python library of utility classes that has been widely used. I want to add some…
pk-nb
  • 2,850
  • 1
  • 18
  • 20
0
votes
3 answers

class methosd (ruby)

Can you tell me why this isn't working? The code below outputs student1 & student2 properly, but I cannot get the class method to work on student3. All I am trying to do is assign a class method .create_with_species , with the species attribute =…
Jeff H.
  • 923
  • 1
  • 7
  • 9
0
votes
2 answers

Xcode error on using class method by method of the same class

I have a class that have class method "getSimulatedPricesFrom". It will call method "projectFromPrice" from the same class during the execution. However in the line sTPlus1 line, I encounter the 2 errors: 1) Class method "projectFromPrice" not…
Tsui John
  • 107
  • 3
  • 21