nsobject

Storing NSObject using NSKeyedArchiver/ NSKeyedUnarchiver

匆匆过客 提交于 2019-12-04 22:25:37
I have a class object like; BookEntity.h import <Cocoa/Cocoa.h> @interface BookEntity : NSObject<NSCoding> { NSString *name; NSString *surname; NSString *email; } @property(copy) NSString *name,*surname,*email; @end BookEntity.m #import "BookEntity.h" @implementation BookEntity @synthesize name,surname,email; - (void) encodeWithCoder: (NSCoder *)coder { [coder encodeObject: self forKey:@"appEntity"]; } - (id) initWithCoder: (NSCoder *)coder { if (self = [super init]) { self = [coder decodeObjectForKey:@"appEntity"]; } return self; } and I assign some values to this class, BookEntity *entity =

What is the significance of WaitUntilDOne in performSelectorOnMainThread?

余生颓废 提交于 2019-12-04 20:06:26
问题 What is the significance of WaitUntilDOne in performSelectorOnMainThread ? IN what way the YES or NO set to WaitUntilDone can have on the App? UPDATE: My Question should have been: In what scenarios do they make difference? Sergio's answer was the one I was expecting. 回答1: From Apple docs about waitUntilDone: A Boolean that specifies whether the current thread blocks until after the specified selector is performed on the receiver on the main thread. Specify YES to block this thread; otherwise

isKindOfClass doesn't work as expected

筅森魡賤 提交于 2019-12-04 09:25:41
问题 i'm working on a iOS5+ project (xcode 4.4.1 SDK 5.1) i have this code inside a unit test: [_appDelegate application:nil didFinishLaunchingWithOptions:nil]; UITabBarController *tabBarController = (UITabBarController*)_appDelegate.window.rootViewController; NSArray *viewControllers = [tabBarController viewControllers]; UINavigationController *nc_1 = [viewControllers objectAtIndex:0]; UIViewController *vc_1 = nc_1.topViewController; STAssertTrue([vc_1 isKindOfClass:[ScheduleViewController class]

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

╄→гoц情女王★ 提交于 2019-12-04 02:55:19
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 properly prepare an object. Here's the snippet from NSObject 's -init method which got me wondering about

Swift compile error when subclassing NSObject and using generics

瘦欲@ 提交于 2019-12-04 01:31:20
The following Swift code generates a compile error at build time: import Foundation class Wrapper<T> : NSObject { let obj : T init(x : T) { self.obj = x } } Am I doing something wrong or is this a compiler bug? If so, what could I do to work around it? The error log: CompileSwift normal i386 com.apple.xcode.tools.swift.compiler cd /Users/hermespique/workspace/HanekeSwift export PATH="/Applications/Xcode6-Beta.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin:/Applications/Xcode6-Beta.app/Contents/Developer/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin" /Applications/Xcode6

Using a typedef enum in my object Class

China☆狼群 提交于 2019-12-04 00:45:14
I have a People class which holds various bits of into about a person. I would like to be able to identify what kind of person this is, so I thought I would try using a typedef enum for this since I have seen it done before and it seems like the cleanest solution. But, I am unsure how to declare this, then make it into a property. .h typedef enum { kPersonTypeFaculty, kPersonTypeStaff, kPersonTypeSearch } personType; @interface Person : NSObject { NSString *nameFirst; NSString *nameLast; NSString *email; NSString *phone; NSString *room; NSString *status; NSString *building; NSString

Overridden == function for Equatable type not called for custom class that subclasses NSCoding and NSObject [duplicate]

↘锁芯ラ 提交于 2019-12-03 22:51:36
This question already has answers here : Closed 3 years ago . NSObject subclass in Swift: hash vs hashValue, isEqual vs == (2 answers) The FooBar class below has to override the == function of the Equatable type. However, calling contains on an array of FooBar objects does not cause a breakpoint inside the custom == function to get invoked. Is it possible another == function is overriding this custom one? Note: Because FooBar must subclass from NSCoding and NSObject, FooBar does not list Equatable as a protocol because it causes this error: Redundant conformance of 'FooBar' to protocol

self = [super init] revisited

。_饼干妹妹 提交于 2019-12-03 21:42:17
问题 I stumbled upon this post In Objective-C why should I check if self = [super init] is not nil? I can understand this syntax: - (id)initWithString:(NSString *)aString { self = [super init]; if (self) { instanceString = [aString retain]; } return self; } or this syntax: - (id)init; { if (!(self = [super init])) return nil; // other stuff return self; } but I still don't understand the "standard" template syntax - init { if((self = [super init])) { // set up instance variables and whatever else

Objective-C forwardInvocation:

六眼飞鱼酱① 提交于 2019-12-03 17:23:10
I often do something like: CoolViewController *coolViewController = [[CoolViewController alloc] init]; [self.navigationController pushViewController:coolViewController animated:YES]; [coolViewController release]; How would I, in a category of UINavigationController , override forwardInvocation: so that I could just instead do: [self.navigationController pushCoolViewControllerAnimated:YES]; Please include the relevant code in your answer, not just an explanation. Thank you! Feel free to comment on whether this is good practice. I'm also asking this for educational purposes, but it seems to me

[译]2013-10-25 NSObject: the Class and the Protocol

◇◆丶佛笑我妖孽 提交于 2019-12-03 13:22:56
原文链接: https://mikeash.com/pyblog/friday-qa-2013-10-25-nsobject-the-class-and-the-protocol.html Reader Tomas Bouda asks: what's the deal with the NSObject protocol? There are two NSObjects in Cocoa, a class and a protocol. Why both? What purpose do they serve? In today's article, I'll explore the answer to this question. 读者Tomas Bouda问我:“NSObject协议应该怎么理解呢?在Cocoa中有两处NSObject,一处是NSObject类,另一处是NSObject协议。为啥会有两个呢?他们到底有什么作用?”。在今天的文章里,我将会探讨这个问题。 Namespaces 命名空间 First, let's look at how these two entities with the same name can coexist. Classes and protocols in Objective-C inhabit entirely separate