nsobject

Monotouch: convert an Object to NSObject

懵懂的女人 提交于 2019-11-29 09:14:44
How is it possible to convert an Object instance to NSObject one? I've created a NSDictionary from NSDictionary.FromObjectAndKey(); This method wants an NSObject but I have custom object to pass in: int key = 2341; var val = new MyClass(); NSDictionary.FromObjectAndKey(val, key); // obviously it does not work!! How to fix this? Thank you in advance. You can not convert an arbitrary object into an NSObject. The NSObject.FromObject will try to wrap common data types like numbers, strings, rectangles, points, transforms, and a handful of other .NET types into their equivalent NSObject types. In

What is the NSObject isEqual: and hash default function?

╄→гoц情女王★ 提交于 2019-11-29 02:54:50
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 the isEqual: documentation I thought it used the value from the hash method. Obviously, that is not

Bug with equals operator and NSObjects in Swift 2.0?

心已入冬 提交于 2019-11-29 01:57:57
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(identifier: "A") let result = (myObject1 == myObject2) // result is true So far so good, but what if

NSObject description and debugDescription

↘锁芯ラ 提交于 2019-11-28 20:10:56
I have seen mentioning of description and debugDescription for debugging purposes, but have yet seen precise explanations of when to use which and under what conditions they may produce different results. NSObject's documentation also doesn't have anything on debugDescription. Question: When to use which, and under what condition, should/would their output be different? Technical Note TN2124 Note: print-object actually calls the debugDescription method of the specified object. NSObject implements this method by calling through to the description method. Thus, by default, an object's debug

Runtime error when using CoreFoundation objects in a swift NSObject subclass

守給你的承諾、 提交于 2019-11-28 13:40:30
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() { list.append(CGPathCreateMutable()); } } When trying to use this class: var instance = MyClass(); println(instance.list.count); // runtime error after adding this line Yields an ugly crash: Playground execution failed: error: Execution was interrupted, reason: EXC_BAD_INSTRUCTION (code=EXC_I386_INVOP, subcode=0x0). The process has been left at the point where it was interrupted, use

Access IBOutlet from other class (ObjC)

﹥>﹥吖頭↗ 提交于 2019-11-28 13:04:37
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/Cocoa.h> @interface aClass : NSObject { IBOutlet NSTextField *textField; } @end aClass.m: #import "aClass.h

Why subclass NSObject?

廉价感情. 提交于 2019-11-28 09:40:49
What is the purpose/use of NSObject in Objective-C? I see classes that extend NSObject like this: @interface Fraction : NSObject In C++ or Java, we don't use any variables like NSObject even though we have preprocessor directives and import statements in both Objective-C and Java. Why do classes explicitly inherit from NSObject in Objective-C? What are the consequences of not declaring inheritance from NSObject? Tim We use NSObject to explicitly state what a given class inherits from. I'm not sure about C++, but in Java there's something similar - the Object class. The only difference is that

iOS JSON serialization for NSObject-based classes

纵然是瞬间 提交于 2019-11-28 05:58:00
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 want something that will serialize any custom object that I care to define (within reason). Let's imagine

Write custom object to .plist in Cocoa

◇◆丶佛笑我妖孽 提交于 2019-11-27 22:34:01
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 *)k name:(NSString *)n progress:(NSNumber *)pro size:(NSNumber *)s path:(NSString *)p progressBytes:

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

前提是你 提交于 2019-11-27 20:30:58
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' does not have a member named 'anyObject' I've read through many similar question, but I can't seem to