nsobject

What is the NSObject isEqual: and hash default function?

佐手、 提交于 2019-11-27 17:25:37
问题 I have a database model class that is a NSObject . I have a set of these objects in a NSMutableArray . I use indexOfObject: to find a match. Problem is the model object's memory address changes. So I am overriding the hash method to return the model's row ID. This however does not fix it. I also have to override the isEqual: method to compare the value of the hash method. What does the isEqual: method use to determine equality by default? I'm assuming it uses the memory address. After reading

Bug with equals operator and NSObjects in Swift 2.0?

只谈情不闲聊 提交于 2019-11-27 16:18:48
问题 Ok, something strange is happening when writing your own equals operator for NSObject subclasses in Swift 2.0 like this: func ==(lhs: MyObject, rhs: MyObject) -> Bool { return lhs.identifier == rhs.identifier } For a class that looks like this: class MyObject: NSObject { let identifier: String init(identifier: String) { self.identifier = identifier } } This used to work just fine in Swift 1.2 and below. It still kind of works: let myObject1 = MyObject(identifier: "A") let myObject2 = MyObject

Swift 3: subclassing NSObject or not?

笑着哭i 提交于 2019-11-27 14:08:33
I have read some posts like this one about the difference between subclassing NSObject in Swift or just having its native base class with no subclassing. But they all are a bit old posts, and I am not clear about this topic. When should you subclass NSObject ? What is the actual difference between subclassing it and not subclassing? What is currently the recommendation in Swift? mz2 Apple's documentation about NSObject states the following as an introduction: NSObject is the root class of most Objective-C class hierarchies. Through NSObject, objects inherit a basic interface to the runtime

What is __NSArrayI and __NSArrayM? How to convert to NSArray?

£可爱£侵袭症+ 提交于 2019-11-27 12:03:50
What is __NSArrayI and __NSArrayM? __NSArrayI(or M) cause "unrecognized selector" error. How to convert to NSArray? I did test to parse json, twitter api. http://api.twitter.com/1/followers/ids.json?cursor=-1&screen_name=twitterapi ==> works fine. parsed object is NSCFDictionary class. (This dictionary contains __NSArrayM class) http://api.twitter.com/1/statuses/user_timeline.json?&screen_name=twitterapi ==> error. parsed object is __NSArrayM class. __NSArrayI is a code-word for an immutable array - that is, a "regular" NSArray which you cannot change. __NSArrayM is a code-word for a mutable

Removing Duplicates From Array of Custom Objects Swift

*爱你&永不变心* 提交于 2019-11-27 09:05:15
I have a custom class defined as follows : class DisplayMessage : NSObject { var id : String? var partner_image : UIImage? var partner_name : String? var last_message : String? var date : NSDate? } Now I have an array myChats = [DisplayMessage]? . The id field is unique for each DisplayMessage object. I need to check my array and remove all duplicates from it, essentially ensure that all objects in the array have a unique id . I have seen some solutions using NSMutableArray and Equatable however I'm not sure how to adapt them here; I also know of Array(Set(myChats)) however that doesn't seem

Access IBOutlet from other class (ObjC)

妖精的绣舞 提交于 2019-11-27 07:24:52
问题 I've googled around and found some answers but I didn't get any of them to work. I have one NSObject with the class "A" and a second class "B" without an NSObject. In class "A" are my IBOutlets defined and I can't seem to figure out how to access those outlets from class "B"... I've found answered questions like http://forums.macrumors.com/archive/index.php/t-662717.html But they're confusing. Any help would be greatly appreciated! Simplified Version of the Code: aClass.h: #import <Cocoa

iOS JSON serialization for NSObject-based classes

本秂侑毒 提交于 2019-11-27 01:07:49
问题 I'd like to JSON-serialize my own custom classes. I'm working in Objective-C / iOS5. I'd like something to do the following: Person* person = [self getPerson ]; // Any custom object, NOT based on NSDictionary NSString* jsonRepresentation = [JsonWriter stringWithObject:person ]; Person* clone = [JsonReader objectFromJson: jsonRepresentation withClass:[Person Class]]; It seems that NSJSONSerialization (and several other libraries) require the 'person' class to be based on NSDictionary etc. I

Write custom object to .plist in Cocoa

对着背影说爱祢 提交于 2019-11-26 23:11:28
问题 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 <NSCoding>{ NSNumber *key; NSString *name; NSNumber *progress; NSNumber *progressBytes; NSNumber *size; NSString *path; } @property (copy) NSNumber *key; @property (copy) NSString *name; @property (copy) NSNumber *progress; @property (copy) NSNumber *size; @property (copy) NSString *path; @property (copy) NSNumber *progressBytes; -(id)initWithKey:(NSNumber

'Set<NSObject>' does not have a member named 'anyObject." - Xcode 6.3

坚强是说给别人听的谎言 提交于 2019-11-26 22:56:51
问题 I'm checking to see if an element has been selected. func touchesBegan(touches: Set<NSObject>, withEvent event: UIEvent) { // First, see if the game is in a paused state if !gamePaused { // Declare the touched symbol and its location on the screen let touch = touches.anyObject! as? UITouch let location = touch.locationInNode(symbolsLayer) And this had previously compiled fine in Xcode 6.2 but with a 6.3 update, the line "let touch = touches.anyObject! as? UITouch" is throwing the error: 'Set'

Swift 3: subclassing NSObject or not?

你说的曾经没有我的故事 提交于 2019-11-26 18:22:45
问题 I have read some posts like this one about the difference between subclassing NSObject in Swift or just having its native base class with no subclassing. But they all are a bit old posts, and I am not clear about this topic. When should you subclass NSObject ? What is the actual difference between subclassing it and not subclassing? What is currently the recommendation in Swift? 回答1: Apple's documentation about NSObject states the following as an introduction: NSObject is the root class of