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
9
votes
2 answers

Generic Objective-C description method to print ivar values

In Objective-C, it's common to override -description with a method that prints the object ID and instance variable names/values. I'd like to make a generic -description method that does this through introspection, rather than manually doing this for…
jrdioko
  • 32,230
  • 28
  • 81
  • 120
9
votes
2 answers

Subclassing Swift Generic Class with NSObject inheritance

I'm running into an error where I'm not certain if it's a limitation of the Swift language, or a bug. Here's the most basic premise: class GenericClass : NSObject { var inputValue: T init(value: T) { self.inputValue = value …
erendiox
  • 91
  • 4
9
votes
5 answers

If I do nothing in -init, is it the same as just calling [MyClass alloc]?

If I have an NSObject subclass which either has no -init method or simply does nothing in -init, is there any difference between an instance created these two ways: MyClass *instance = [MyClass alloc]; MyClass *instance = [[MyClass alloc] init]; By…
nevan king
  • 112,709
  • 45
  • 203
  • 241
9
votes
3 answers

Objective-c: How can I require override and not call super?

I guess this is solved by writing a @protocol. But I'm hungry for knowledge. Is there some flag or other way to require subclasses to override specific methods and not call super? Like the opposite of NS_REQUIRES_SUPER / objc_requires_super?
hfossli
  • 22,616
  • 10
  • 116
  • 130
9
votes
3 answers

Difference Between Object And NSObject

I'm learning Objective-C and as I can see, in some tutorials they use Object(imported from objc/Object.h) and in others i see the use of NSObject(imported from Foundation/NSObject.h), but what are the main differences between they? Regards.
Nathan Campos
  • 28,769
  • 59
  • 194
  • 300
9
votes
6 answers

how to display UIViewController from a NSObject class?

There is a current view as UIViewController which call "LoginView" but I'm not in, I'm in a NSObject class and I want to call, display an other UIViewController which is call "MapView". How can I do this? The problem is like above screenshot.
emy
  • 664
  • 1
  • 9
  • 22
9
votes
3 answers

isKindOfClass doesn't work as expected

i'm working on a iOS5+ project (xcode 4.4.1 SDK 5.1) i have this code inside a unit test: [_appDelegate application:nil didFinishLaunchingWithOptions:nil]; UITabBarController *tabBarController =…
Luca Bartoletti
  • 2,435
  • 1
  • 24
  • 46
8
votes
4 answers

What is the significance of WaitUntilDOne in performSelectorOnMainThread?

What is the significance of WaitUntilDOne in performSelectorOnMainThread? IN what way the YES or NO set to WaitUntilDone can have on the App? UPDATE: My Question should have been: In what scenarios do they make difference? Sergio's answer was the…
RK-
  • 12,099
  • 23
  • 89
  • 155
8
votes
1 answer

What happens to an NSArray object when encoding?

I'm building an application that utilises NSCoding to save NSObject's to a documentPath. I'm having no issues doing this, I'm just curious about something. I have MACompany, which implements NSCoding delegate methods. - (void)…
Sebastien Peek
  • 2,528
  • 2
  • 23
  • 32
8
votes
2 answers

What is the difference between declaring a protocol @objc and having it conform to NSObjectProtocol in pure Swift?

Consider two Swift protocols: @objc protocol SomeProtocol { } protocol SomeOtherProtocol: NSObjectProtocol { } What is the difference between declaring a Swift protocol @objc or having it conform to NSObjectProtocol? I know that any protocol that…
JAL
  • 41,701
  • 23
  • 172
  • 300
8
votes
1 answer

How to observe an array of NSObjects in swift?

I am new in swift language and my problem is about how to use observable/observer pattern in swift. I want to make my array to be observable in my SocketManager class so it can be observed by my UIViewController class. I have used the Observable…
user2366997
  • 91
  • 1
  • 7
7
votes
3 answers

Using UIAlertView in an NSObject

I'm having a terrible time getting a UIAlertView to work within my custom NSObject class. In the research I've done it appears it should be possible but here's what I've run into. First, here's my code: -(void)alertView:(UIAlertView *)alertView…
rdfrahm
  • 71
  • 2
7
votes
2 answers

What do these Xcode warnings mean?

I’m getting the following warnings in Xcode when building my app (app runs just fine however): Could not associate debug note to atom l_OBJC_LABEL_PROTOCOL_$_NSObject Could not associate debug note to atom l_OBJC_PROTOCOL_REFERENCE_$_CAAction Could…
DukDuck
  • 81
  • 2
7
votes
1 answer

View outlet not available to File's Owner

I was getting the following message upon creating a new view controller. Everything was compiling a-okay in Xcode without errors, but the app was immediately quitting upon loading the new view from a RootViewController. Terminating app due to…
Old McStopher
  • 6,295
  • 10
  • 60
  • 89
7
votes
2 answers

Assigning object to weak reference in Objective-C?

According to ARC in iOS, an object must have at least one strong reference to stay in memory, when there is no strong reference (ie. reference count becomes 0), the object will be deallocated from memory and we will have no longer access to the…