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

How to override NSObject's default comparison in Swift

I have a custom class Player that conforms to NSObject, NSCoding. A Player object is instantiated with a id: String! One of the issues I am encountering is when I perform an operation like the following: let listOfPlayers = [Player]() //populate…
daspianist
  • 5,336
  • 8
  • 50
  • 94
4
votes
4 answers

Adding context to a UI control or NSObject

It's great to be able to addTarget on a UIButton. I only wish there was some sneaky way I could attach state to the UIButton so that when the target method is invoked, I could magically pull that state (any id) from the sender. Something…
David Blevins
  • 19,178
  • 3
  • 53
  • 68
4
votes
2 answers

What are objective c runtime features?

In a blog post I have just read: 'Swift allows us to extend classes from NSObject to get Objective-C runtime features for an object. It also allows us to annotate Swift methods with @objc to allow the methods to be used by the Objective-C…
Lewis Black
  • 957
  • 2
  • 8
  • 22
4
votes
2 answers

How to config NSURLSessionConfiguration into the NSObject class?

i want to get server response from NSObject when i m getting a response,it has return to viewController.as i implement on server call into NSObject class then i called to the NSObject method but before server response my NSString have been return as…
Tamil_Arya
  • 47
  • 1
  • 6
4
votes
3 answers

How to convert NSObject class object into JSON in Swift?

I have var contacts : [ContactsModel] = [] and class ContactsModel: NSObject { var contactEmail : String? var contactName : String? var contactNumber : String? var recordId : Int32? var modifiedDate : String? } Now in contacts…
Shrikant K
  • 1,988
  • 2
  • 23
  • 34
4
votes
0 answers

Why does isKindOfClass:Nil return YES on __NSCFConstantString?

I encountered some code that might potentially use Nil as the class in an isKindOfClass: check and was curious what would happen in that case. Using Xcode 6.2, with the OS X 10.10 SDK and running on 10.9.5: for (id obj in @[ …
Isaac
  • 10,668
  • 5
  • 59
  • 68
4
votes
1 answer

nsobject vs nsmanagedobject pro and cons

I am using Core data in my project and using directly NSManagedObject in the viewControllers with the help of fetchResultController. But as per new clean code architecture or VIPER approach, it is saying use PONSO or NSOject instead of…
Pradeep Kachhawaha
  • 6,589
  • 2
  • 14
  • 13
4
votes
3 answers

Not identical to 'Self'

I want to create a Convertible-like protocol and extend NSObject subclasses to implement it. In particular: protocol DataConvertible { class func convertFromData(data:NSData) -> Self? func data() -> NSData } I thought implementing would…
hpique
  • 119,096
  • 131
  • 338
  • 476
4
votes
1 answer

Is performSelector:onThread:withObject:waitUntilDone: ordered?

I have an Objective-C class which spins up a background thread and runs an NSRunLoop on it. I would like to deliver messages to the background thread from the main thread (yes, exclusively from the main thread). To do this, I am planning to use the…
Alex Nichol
  • 7,512
  • 4
  • 32
  • 30
4
votes
3 answers

Where is 'Class Actions' in the 'Object Identity' panel in Interface Builder?

I thought I was fairly experienced at iPhone development, but I'm tripping up on the Stanford iPhone course on the very first video. (38 mins in) The teacher, drags an NSObject into the MainWindow.xib. And when he inspects the Object in the Identity…
cannyboy
  • 24,180
  • 40
  • 146
  • 252
4
votes
2 answers

iOS how can I dump multiple properties of an object into a dictionary using a predicate or KVC?

I have a class that got bloated with properties and now there's about 30 of them, most of which are integer enumerated types. My code currently uses this in a bunch of places, and I'm trying to gently move to the new dictionary representation. I'm…
Alex Stone
  • 46,408
  • 55
  • 231
  • 407
4
votes
1 answer

NSObject(NSObject) doesNotRecognizeSelector crashing app, report missing some symbolication

I have an application that has been release in the App Store. About maybe 1% - 2% of my users are reporting that the App is crashing. This isn't exactly unexpected behavior, so I have asked for the crash logs. Here is the last exception backtrace…
Kyle Begeman
  • 7,169
  • 9
  • 40
  • 58
4
votes
1 answer

Creating an object that works with NSJSONSerialization dataWithJSONObject:options:error:

At the moment in order to use this function I'm "converting" my object into a dictionary. i.e. the property names become the keys and the property values become the values. Is there a way to properly do this so that an object will work with this…
Fogmeister
  • 76,236
  • 42
  • 207
  • 306
4
votes
4 answers

How does inheriting from NSObject work?

There are a couple of things about Objective-C that are confusing to me: Firstly, in the objective-c guide, it is very clear that each class needs to call the init method of its subclass. It's a little bit unclear about whether or not a class that…
Jason Baker
  • 192,085
  • 135
  • 376
  • 510
4
votes
2 answers

What is best practice for new NSObject - alloc / init or change existing?

I would like to get some opinion about best practice in iOS5 and higher (ARC enabled). For example, I have a database with cars - image, name, max speed, etc. info. In app I have to show a car with info, then, after user interaction - next car, then…