nsobject

Object filter crashes if no results can be found

瘦欲@ 提交于 2019-12-11 09:45:03
问题 I have written some code to find a user's favourites out of an array of custom objects. It works absolutely fine unless that object does not exist, in which case it just crashes. I was considering completely rewriting the code a different way, but I imagine there is probably a way to fix it... I just can't figure out how. Here is my code: override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell { let cell = tableView

What is an instance of an NSObject

冷暖自知 提交于 2019-12-11 08:19:37
问题 I am a newbie, and I am wondering what an instance of NSObject is. I am working on Xcode 3.2 and want to know what the instance is. I've heard this term often and am confused by it. 回答1: From Wikipedia on Objects in OOP Objects in "object-oriented programming" basically are data structures combined with the associated processing routines. For instance, a file is an object: a collection of data and the associated read and write routines. Objects are considered instantiations of classes. In

how to store custom objects in NSMutableDictionary?

China☆狼群 提交于 2019-12-11 08:10:18
问题 I'm new to iOS. I have a class derived from NSObject and I want to store its reference into NSMutableDictionary . How can I? e.g. @interface CustomClass : NSObject { } I want to store reference (*customClass) of this CustomClass into NSMutableDictionary . Please give me the simple way to store and retrieve it. 回答1: For that purpose, you need to use NSKeyedArchiver and NSCoder classes, as following: In your CustomClass.m file, implement the following two encoding and decoding methods : - (void

Check if an array of custom objects contains an object with a certain date

↘锁芯ラ 提交于 2019-12-11 03:43:12
问题 I have an array of event objects . The object has several attributes. One of the attributes is an NSDate eve_date . Now I want to check if that array of objects contains a certain NSDate d I'm doing the following if([[matches valueForKey:@"eve_date"] containsObject:d]){ NSLog(@"contains object"); }else{ NSLog(@"does not contains object"); } But this is not working. Can anyone help me ? Kind regards EDIT Okay let me be more clear. I'm making a calendar app. I fetched all the events inside the

Custom class NSObject not key value coding compliant [duplicate]

守給你的承諾、 提交于 2019-12-11 02:23:49
问题 This question already has answers here : Closed 6 years ago . Possible Duplicate: Why is my object not key value coding-compliant? I'm having a dictionary and I want to add keys/values to a custom class, but i always get the error, that the class is not KVC compliant, but the Apple documents state that it should be. My code: ContactObject.h: @interface ContactObject : NSObject + (ContactObject *)testAdding; @end ContactObject.m: @implementation ContactObject - (id)init { self = [super init];

Is object that calls performSelector:withObject:afterDelay get retained by the NSRunLoop?

亡梦爱人 提交于 2019-12-11 01:06:11
问题 I have a certain object that perform a "Refresh" every X seconds. ("The Updater") The way I'm doing this repetitive update is by calling performSelector:withObject:afterDelay and in my selector I'm re-scheduling as necessary. Of course I have a method to stop these invokations by calling cancelPreviousPerformRequests . The problem is that this "Updater" is never being deallocated. There is only one other object that retaining the Updater (AFAIK), and the retaining object is being deallocated

Create NSObject from NSDictionary in objective-c

夙愿已清 提交于 2019-12-10 16:53:53
问题 I would like to assign each item from a dictionary into my object using a "for...in" loop I have a NSDictionary like that : {"user_id" : "1", "user_name" : "John"} And I have an NSObject with variable : NSString *user_id; NSString *user_name With a for in loop, I want to assign each item from my NSDictionary in my NSObject for (NSString *param in userDictionary) { } How I can do that ? Thanks, 回答1: Have a look at the NSObject class method: - (void)setValue:(id)value forKey:(NSString *)key;

no visible @interface for declares the selector errors

房东的猫 提交于 2019-12-10 15:24:49
问题 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 "UIViewControllerHUB.h" @interface UIViewControllerHUB () @property (strong, nonatomic) NSMutableArray *subItems; @end @implementation UIViewControllerHUB - (void)viewDidLoad { [super viewDidLoad]; NSString *fullURL = @"http://conecode.com"; NSURL *url = [NSURL URLWithString

If I do nothing in -init, is it the same as just calling [MyClass alloc]?

孤者浪人 提交于 2019-12-09 15:36:30
问题 If I have an NSObject subclass which either has no -init method or simply does nothing in -init , is there any difference between an instance created these two ways: MyClass *instance = [MyClass alloc]; MyClass *instance = [[MyClass alloc] init]; By "does nothing in -init " I mean - (id)init { self = [super init]; if (self) { } return self; } Since NSObject 's -init method itself does nothing, I can't see there being any difference, but of course the advice is that you must call -init to

How Do I Initialize Two Instances of NSObject in the same ViewController - Swift

不想你离开。 提交于 2019-12-09 00:42:37
Please bear with me. I'm new to programming and new to StackOverflow. I hope that my question will grant me a warm response for entering the programming community. An acquaintance, whose opinion I trust, told me to post this email to him on StackOverflow. What do I have to do to get two instances of NSObject to work in the same ViewController? I've initialized an NSObject subclass called SideBar and RightSideBar. They both draw from NSObject. The cells in the menu are called created by a TableViewController I created programatically. I followed a tutorial that did everything programmatically