nsobject

'isMemberOfClass' returning 'NO' when custom init [duplicate]

纵然是瞬间 提交于 2019-12-02 09:22:39
Possible Duplicate: isMemberOfClass returns no when ViewController is instantiated from UIStoryboard I recently stumbled over a weird problem: I was implementing simple Testcases and using the NSObject isMemberOfClass method to check for class equality. Additionally I implemented a custom init: -(id)initWithMessage:(NSString *)message If I replace id with the right class name the isMemberOfClass will return 'YES'. Otherwise it will fail. The interesting part is: The class Method will return the right Class every time. Is this a bug? Or is it supposed to work that way? Thanks.. EDIT: Ok this

In Apple's Documentation for NSObject, what is the idea of the “receiver”?

走远了吗. 提交于 2019-12-02 05:08:07
问题 I'm researching Object-Oriented Programming in Swift and I figured a great place to start would be NSObject , since all objects inherit from this base class. In Apple's documentation for NSObject, there are areas that refer to a "receiver". Does "receiver" mean an instance of NSObject ? 回答1: It refers to Objective-c's paradigm of "sending messages" to objects. In that world, a "method" isn't REALLY a method, it's just the object saying, "Hey, if someone sends me this message (a string that

Swift: Can't insert NSObject into Array as it wants a [String] instead

爱⌒轻易说出口 提交于 2019-12-02 04:45:31
I have a model object called Hashtag. This simply contains a optional String variable called hashtagName. I fetch the data from my Firebase Database and append the hashtags to my fashionHashtags, which is a [Hashtag] . The issue I have is that I want to append that to my other categoriesArray by using the insertElementAtIndexPath function. I cannot do this as it wants an array of Strings and not an array of Hashtag. When I autocorrect it, it replaces it with fashionHashtags as! [String] but that creates another error. How do I fix this so it allows me to do so? I would like to stick to the

How to make NSURLConnection file download work?

北慕城南 提交于 2019-12-02 03:09:43
I have a ViewController declared as: @interface DownloadViewController : UIViewController <UITableViewDataSource, UITableViewDelegate> and I want to use NSURLConnection to download files. NSURLConnection simply "doesn't start", the delegate methods don't work (for example connection:didReceiveResponse is never called) . I noticed in some sample code that the class was subclassing NSObject instead of UIViewController . How do I combine it? I want to use ViewController methods but then I can't use NSURLConnection . It's not so easy to find a fully explained example how to download file with

How to convert NSObject class object into JSON in Swift?

試著忘記壹切 提交于 2019-12-01 19:08:39
问题 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 I'm having 6 values like Now i want to convert contacts into JSON how can i ? I tried var jsonData: NSData? do { jsonData = try NSJSONSerialization.dataWithJSONObject(contacts, options:NSJSONWritingOptions.PrettyPrinted) } catch { jsonData = nil } let jsonDataLength = "

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

时间秒杀一切 提交于 2019-12-01 17:38:12
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 = { badge = 7 } } To extract this number '7' out of my userInfo I would like to do the following: self.updateAppIcon(userInfo["aps"]["badge"] as? Int) But of course I get the following error : Swift : '(NSObject, AnyObject)' does not have a member named 'subscript' If I'm not wrong, it's because [] returns an AnyObject which cannot be interpreted as

iOS > “id” vs. NSObject [duplicate]

余生颓废 提交于 2019-12-01 16:58:54
This question already has an answer here: Why use id when we can just use NSObject? 4 answers Is there a difference between relating to an Object in a 'Polymorphic' way with the type id than as NSObject * ? In what way is: NSString* aString = @"Hello"; id anObj = aString; different than: NSString* aString = @"Hello"; NSObject* anObj = aString; id is a special keyword used in Objective-C to mean “some kind of object.” It does not contain isa pointer( isa , gives the object access to its class and, through the class, to all the classes it inherits from), So you lose compile-time information

iOS > “id” vs. NSObject [duplicate]

旧巷老猫 提交于 2019-12-01 15:15:33
问题 This question already has answers here : Why use id when we can just use NSObject? (4 answers) Closed 6 years ago . Is there a difference between relating to an Object in a 'Polymorphic' way with the type id than as NSObject * ? In what way is: NSString* aString = @"Hello"; id anObj = aString; different than: NSString* aString = @"Hello"; NSObject* anObj = aString; 回答1: id is a special keyword used in Objective-C to mean “some kind of object.” It does not contain isa pointer( isa , gives the

Is it possible to add “keyed-subscripting” to Class objects?

走远了吗. 提交于 2019-12-01 06:51:44
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 question as I tested it out, myself... + (id) objectForKeyedSubscript:(id)k { return [self.shared something:k]; } And alas.. it is not... id x = MyClass[@"document"]; error: unexpected interface name 'MyClass': expected expression But why, Daddy? Class ' sure get the short end of NSObject 's stick, if you ask me . Alex Gray Josh Caswell's comment pointed out the

Safe way to create singleton with init method in Objective-C

北城余情 提交于 2019-12-01 03:29:57
I would like to take the GCD approach of using shared instances to the next step so I created the following code: @implementation MyClass static id sharedInstance; #pragma mark Initialization + (instancetype)sharedInstance { static dispatch_once_t once; dispatch_once(&once, ^{ sharedInstance = [[self alloc] init]; }); return sharedInstance; } - (instancetype)init { if (sharedInstance) { return sharedInstance; } @synchronized(self) { self = [super init]; if (self) { sharedInstance = self; } return self; } } @end I assume the sharedInstance method seems to be ok but I am unsure about the init