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

Display a UIAlertView in NSObject Class

I'm building a login system within my app that will be called several times. So instead of copying and pasting the code into several spots, I'm of course making an NSObject class so I can call the class when needed, instead. The login system will…
Jack Humphries
  • 13,056
  • 14
  • 84
  • 125
5
votes
3 answers

Inherit NSObject from C++ class

I'm emotionally attached to my C++ class, but I really want it to go into a tableview. Is there a way to subclass NSObject from a standard c++ class? this is what I tried to do: class Model : NSObject { public: NSString *key; }; The compiler…
Paul Wand
  • 323
  • 5
  • 12
5
votes
2 answers

Scalar type in Managed Object only works for IPhone 5

Property 'Latitude' is a scalar type on class 'LatitudeLongitude'. Cannot generate a setter method for it. When I generated codes for my managed object, I got a message whether I want scalar properties for primitive data type. should I use it? I…
user4951
  • 32,206
  • 53
  • 172
  • 282
5
votes
3 answers

Write custom object to .plist in Cocoa

I am blocking into something and I am sure it is too big. I have a custom object that look like this @interface DownloadObject : NSObject { NSNumber *key; NSString *name; NSNumber *progress; NSNumber *progressBytes; …
Dimillian
  • 3,616
  • 4
  • 33
  • 53
5
votes
2 answers

How to add multiple line text in UIActionSheet

How to add multi line text with custom font in UIActionSheet swift.I have tried \n.but this is not working.is this possible or not. Here is the my code. alert.addAction(UIAlertAction(title: "line 1.\n %C line 2,\n %C line", style: .default ,…
Dilip Mishra
  • 1,422
  • 13
  • 17
5
votes
1 answer

Can I assume NSObject as a kind of CFType in Cocoa-touch?

I'm guessing NSObject is a kind of a CFType, but I have no sure. There is no mention about this in documentation. Can I assume it toll-free bridged?
eonil
  • 83,476
  • 81
  • 317
  • 516
5
votes
3 answers

Objective-C Is it safe to overwrite [NSObject initialize]?

Basically, I have the following code (explained here: Objective-C Constants in Protocol) // MyProtocol.m const NSString *MYPROTOCOL_SIZE; const NSString *MYPROTOCOL_BOUNDS; @implementation NSObject(initializeConstantVariables) +(void) initialize…
Richard J. Ross III
  • 55,009
  • 24
  • 135
  • 201
5
votes
1 answer

Swift4: respondstoSelector not working

Following code works perfectly in swift 3.x but not in swift 4. let selector = "managerDidDetectedStation:" let observer = let station = if observer.responds(to: Selector(selector) { …
Abid Hussain
  • 1,529
  • 1
  • 15
  • 33
5
votes
1 answer

how can I make firebase database data the data source for UICollection View?

I want to change my model object datasource to firebase. I have a file that serves as the datasource for the UICollection view, homeViewController.swift . homeViewController.swift is a vertically arranged collectionViewCell and each cell has its…
5
votes
2 answers

Cast String to NSObject in Swift

I have a method that was originally defined to take an NSString parameter but now needs to be able to take an NSString parameter or an NSAttributedString parameter. Unfortunately these do not share an inheritance hierarchy but each inherit from…
helloB
  • 3,472
  • 10
  • 40
  • 87
5
votes
1 answer

swift 3 array of structs -> cast to NSObject -> cast back => crash

The following code crashes on Swift 3, can anyone please explain why? struct S { let a:Int } let t = [S(a: 8)] let u:AnyObject = t as NSObject let v:[S] = u as! [S] Is that because in Swift 3 array of structs is NSObject (it's not in Swift 2)…
silyevsk
  • 4,021
  • 3
  • 31
  • 30
5
votes
1 answer

Low memory warning for NSObject

I have a subclass of NSObject, it is a singleton which loads a list of images into memory, either from hard drive or downloads them from the internet. I want to release the images stored in memory if the app recieves a low memory message, like in a…
Jonathan.
  • 53,997
  • 54
  • 186
  • 290
5
votes
3 answers

How to create a Swift object in Objective-C?

If you define a swift class like this @objc class Cat { } In swift you can just do var c = Cat() But how do you make a Cat instance in Objective-C ? Subclassing NSObject works because you can then "alloc-init" but can we achieve this without…
Alexis
  • 16,629
  • 17
  • 62
  • 107
5
votes
2 answers

no visible @interface for declares the selector errors

I'm getting No visible @interface for 'NSObject' declares the selector 'viewDidLoad' on the lines: [super viewDidLoad]; [_viewWeb loadRequest:requestObj]; [super didReceiveMemoryWarning]; UIViewControllerHUB.m #import…
Nihir
  • 135
  • 1
  • 1
  • 11
5
votes
2 answers

Is NSObject class a part of the Objective-C runtime library today (instead of being a Foundation component)?

Looking at the Mac OS X 10.8's version of the Objective-C runtime library source code, I noticed that it's got a NSObject.mm file. As its name suggests, it's got the NSObject class implementation, as well as built-in autorelease pool and retain…
LuisABOL
  • 2,951
  • 4
  • 25
  • 57