Questions tagged [nsobject]

NSObject is the root class of most Objective-C class hierarchies; it has no superclass. From NSObject, other classes inherit a basic interface to the runtime system for the Objective-C language, and its instances obtain their ability to behave as objects.

Although it is not strictly an abstract class, NSObject is virtually one. By itself, an NSObject instance cannot do anything useful beyond being a simple object. To add any attributes and logic specific to the program, you must create one or more classes inheriting from NSObject or from any other class derived from NSObject. NSObject adopts the NSObject protocol. The NSObject protocol allows for multiple root objects. For example, NSProxy, the other root class, does not inherit from NSObject but adopts the NSObject protocol so that it shares a common interface with other Objective-C () objects.

NSObject is the name not only of a class but of a protocol. Both are essential to the definition of an object in Cocoa (). The NSObject protocol specifies the basic programmatic interface required of all root classes in Cocoa. Thus not only the NSObject class adopts the identically named protocol, but the other Cocoa root class, NSProxy, adopts it as well. The NSObject class further specifies the basic programmatic interface for any Cocoa object that is not a proxy object.

The design of Objective-C uses a protocol such as NSObject in the overall definition of Cocoa objects (rather than making the methods of the protocol part of the class interface) to make multiple root classes possible. Each root class shares a common interface, as defined by the protocols they adopt.

More Information : NSObject Class reference

899 questions
5
votes
2 answers

How does forwardInvocation: get called?

Looking only at the Objective-C runtime library, when a message is sent to an object that doesn't respond to it, the runtime system gives the receiver another chance to handle the message. So, the receiver's forward:: method, if implemented, gets…
LuisABOL
  • 2,951
  • 4
  • 25
  • 57
5
votes
1 answer

How is retain count implemented in NSObject?

My question is how the current versions of Foundation (or of the Objective-C runtime library, since this seems to be there) implement retain count for NSObject derived objects? As I could see at NSObject.mm, there is no ivar called retain count in…
LuisABOL
  • 2,951
  • 4
  • 25
  • 57
5
votes
2 answers

respondsToSelector with different argument types in selector

Suppose we have different Object which have the same method name but with differet argument types like: getMethod:(NSNumber*)aNumber and getMethod:(NSString*)aString. How to check with respondsToSelector or through other way, if an object responds…
Oleg Danu
  • 4,149
  • 4
  • 29
  • 47
5
votes
3 answers

How do I get class from NSString?

for example, I have NSString *myClass = @"RootViewController" How do I get class from NSString?
Voloda2
  • 12,359
  • 18
  • 80
  • 130
5
votes
1 answer

Does the NSObject init method do anything?

Does it make sense to write self = [super init]; in a custom initialisation method while subclassing NSObject? I know it's necessary when subclassing any other class, because it might have a custom initialisation, but does the NSObject init method…
Tim Vermeulen
  • 12,352
  • 9
  • 44
  • 63
4
votes
2 answers

Create NSObject from NSDictionary in objective-c

I would like to assign each item from a dictionary into my object using a "for...in" loop I have a NSDictionary like that : {"user_id" : "1", "user_name" : "John"} And I have an NSObject with variable : NSString *user_id; NSString *user_name With…
alexmngn
  • 9,107
  • 19
  • 70
  • 130
4
votes
4 answers

Subclass UIViewController or create a custom NSObject when the view is not fullscreen

I need to create a class controller to manage the behavior of a custom view I created. The standard approach is to subclass UIViewController, but in my case I instead decided to subclass the NSObject essentially for three reasons: my view needs to…
ggould75
  • 880
  • 2
  • 14
  • 23
4
votes
4 answers

NSString to class instance variable

I am looking for a way to convert from NSString to a class instance variable. For sample code below, say filter is "colorFilter". I want filternameclassinstancegohere to be replaced with colorFilter. - (void)filterSelected:(NSString *)filter { …
user523234
  • 14,323
  • 10
  • 62
  • 102
4
votes
2 answers

How to get NSString variable value from NSObject to ViewController

I am trying to set up an object to control all of my data so it can set things up in the background to it appears my tableviews load faster than they do now etc. This is what I am trying to achieve. I am setting a variable in the NSObject from the…
C.Johns
  • 10,185
  • 20
  • 102
  • 156
4
votes
3 answers

What happens if i call nsobject init more than once? Does it increase retain count?

I'm pretty new to Objective-C and i have lots of troubles with memory management and still i understand a little. If i have an object, NSArray * myArray for example, and i do this myArray = [[NSArray alloc] initWithObjects:obj1,obj2,obj3,nil]; then…
Andrey Chernukha
  • 21,488
  • 17
  • 97
  • 161
4
votes
1 answer

Objective-C forwardInvocation:

I often do something like: CoolViewController *coolViewController = [[CoolViewController alloc] init]; [self.navigationController pushViewController:coolViewController animated:YES]; [coolViewController release]; How would I, in a category of…
ma11hew28
  • 121,420
  • 116
  • 450
  • 651
4
votes
1 answer

How can I access an SwiftUI environment object from an NSObject?

I'm trying to increment the variable adsWatched by 1 when an ad is dismissed by changing the environment object from a UIViewController and passing it to a SwiftUI view. I've tried putting an environment object in my NSObject class AdManager, which…
Maria
  • 51
  • 1
  • 3
4
votes
4 answers

NSObject to NSString Objective-C

Can someone help me to convert an NSObject to NSString? I'm trying to do something like this - NSString *address = [NSString stringWithFormat:ivpObj.addressStr]; But I got an warning - Format is not a string literal and no format arguments Please…
4
votes
2 answers

Why does object become NSZombie only when inherit from NSObject?

I created a new project, enabled Zombie Objects (Edit Scheme -> Diagnostics). I initialized two objects: ZombieTest and ZombieTest2(inherit from NSObject). After running the app, I opened debug memory graph and only the object that inherit from…
Hen Shabat
  • 519
  • 1
  • 6
  • 19
4
votes
2 answers

How to print/dump NSObject?

I have a Crashlytics.sharedInstance().setObjectValue(loginAccount, forKey: "loginAccount") I have access to SwiftyJSON Pod in my project, so I've tried print(JSON(loginAccount)) I got unknown What should I do to make my dict more humanly…
code-8
  • 54,650
  • 106
  • 352
  • 604