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

Swift 2.0 Set not working as expected when containing NSObject subclass

After upgrading our codebase to Swift2 I've encountered unusual problem. Set is not substracting nor unioning as expected. class A: NSObject { let h: Int init(h: Int) { self.h = h } override var hashValue: Int { …
muvaaa
  • 450
  • 4
  • 12
7
votes
1 answer

'Xcode cannot find protocol declaration of "UIViewControllerAnimatedTransitioning"'

I created a vanilla Xcode (v6.2) project (Project A) that throws the error: 'Xcode cannot find protocol declaration of "UIViewControllerAnimatedTransitioning"' Here's the code: #import @interface WTF : NSObject…
Matt Miller
  • 1,421
  • 1
  • 15
  • 24
7
votes
3 answers

Get List of all native classes

I want to get all the native classes (NSString, NSNumber, int, float, NSSet, NSDictionary) that I have loaded into my iOS Project.. i.e., if I have created a custom class named "TestClass" I don't want it listed... I have already got a code but it…
Raon
  • 1,266
  • 3
  • 12
  • 25
6
votes
1 answer

How can I add a custom Object in Interface Builder?

I'm using XCode4 and using the awesome TTTAttributedLabel class. I've created an NSObject and set its class to TTTAttributedLabel. I can't seem to add this to my View. How can I do so?
Sheehan Alam
  • 60,111
  • 124
  • 355
  • 556
6
votes
1 answer

How to observe change in NSObject properties

I have subclass of NSObject having 70 properties, i need to observe change in all of them without adding each property one-by-one using following : [self addObserver: self forKeyPath: @"propertyname" options:…
AmitSri
  • 1,209
  • 1
  • 20
  • 48
6
votes
2 answers

"Value for key 'root' was unexpected class 'NSArray'" error when retrieve an array of object in UserDefault, Swift

I'm trying to retrieve an array of custom object in Swift, where i get the error "UserInfo={NSDebugDescription=value for key 'root' was of unexpected class 'NSArray'. Allowed classes are '{(MusicCloud.Playlist)}" My project is a music player, so…
hrtlkr29
  • 383
  • 1
  • 7
  • 21
6
votes
1 answer

Playing NSSound in NSObject (Mac App with Objective-C)

I'm making a game that needs to play music. To make my code more manageable, I wanted to make an NSObject that takes care of the sounds (like fading, playing sounds in a playlist, etc). I have this code: NSSound *music = [[NSSound alloc]…
Developer
  • 406
  • 1
  • 4
  • 18
6
votes
0 answers

Making a method unavailable in a protocol

Let's say I'm creating a protocol with a custom initializer in it that I want some of my model objects to conform to. @protocol SomeProtocol - (instancetype)initWithContext:(Context *)context; @end In doing this, I also want to make…
Mason
  • 6,893
  • 15
  • 71
  • 115
6
votes
2 answers

Swift : '(NSObject, AnyObject)' does not have a member named 'subscript'

I'm trying to extract the badge value out of the userInfo dictionary of a remote notification. I read many post and found a solution of my problem but I'm highly not satisfied! So here is my data structure (I removed the useless lines): { aps = {…
Kevin Delord
  • 2,498
  • 24
  • 22
6
votes
5 answers

Runtime error when using CoreFoundation objects in a swift NSObject subclass

Here's a very simple class (subclass of NSObject) that keeps a list of CGPath objects and appends one CGPath to the array on init: import Foundation class MyClass: NSObject { var list = [CGPath](); init() { …
Andrew
  • 15,357
  • 6
  • 66
  • 101
6
votes
2 answers

Retrieving property list of a class in iOS

I am trying to retrieve a list of all the properties that my class or any of its subclasses define. The following code snippet is the code that I have been using, and it has worked properly all the way until the recent iOS8 beta 4. if(!dictionary)…
rvijay007
  • 1,357
  • 12
  • 20
6
votes
1 answer

Is it possible to add "keyed-subscripting" to Class objects?

In the vein of... @implementation MyClass - (id) objectForKeyedSubscript:(id)k { return [self something:k]; } Is it also possible to "subscript" Class objects? I too, am about to find out, with you.. but thought I would post this…
Alex Gray
  • 16,007
  • 9
  • 96
  • 118
6
votes
1 answer

sorting an array of NSObject based on one value based on one value within one object

i have created an object, it looks something like this aOffice.branchname aOffice.lat aOffice.lng aOffice.distance this is then added to an mutable array (nearbranch). later on i work out the distance of each object to the current gps position and…
6
votes
4 answers

Capturing all methods/message calls on an object

How do I put a "hook" on an object so I can see what messages are being sent to it? (ie do an NSLog() every time a message is sent to an object). I think recall seeing this done before but I forget how. I am thinking it might help me track down why…
Jay
  • 19,649
  • 38
  • 121
  • 184
6
votes
2 answers

objective c constants class

I have some constants coded into a few different viewController and NSObject classes atm. One of the guys at my work said I should put them into a class of their own (i.e. a constants class) I am wondering what the pro's and con's of this type of…
C.Johns
  • 10,185
  • 20
  • 102
  • 156