class-cluster

What exactly is a so called “Class Cluster” in Objective-C?

偶尔善良 提交于 2019-12-17 02:27:06
问题 I was reading that NSArray is just such a thing. Sounds heavy. I have 7 really fat books here on my desk about Objective-C, Cocoa and C. None of them mention Class Cluster at all, at least I can't find it in the Index at the back of the books. So what's that? 回答1: From Apple's docs.... In short it's a design pattern used in the Foundation framework, which is probably why it's not mentioned in ObjC books. A class cluster is an architecture that groups a number of private, concrete subclasses

Is subclassing NSNotification the right route if I want to add typed properties?

北城以北 提交于 2019-12-10 01:54:59
问题 I am trying to subclass NSNotification . Apple's docs for NSNotification state the following: NSNotification is a class cluster with no instance variables. As such, you must subclass NSNotification and override the primitive methods name , object , and userInfo . You can choose any designated initializer you like, but be sure that your initializer does not call NSNotification ’s implementation of init (via [super init] ). NSNotification is not meant to be instantiated directly, and its init

Objective C - Subclassing NSArray

心不动则不痛 提交于 2019-12-07 06:30:41
问题 I am trying to subclass NSArray , but it crashes the app when trying to access the count method. I know that NSArray is a class cluster . But what does this mean? Is there a work around to be able to subclass an NSArray? I know that I can simply subclass NSObject and have my array as an instance variable but I would rather subclass NSArray . EDIT: Reason: I am creating a card game, I have a class Deck which should subclass NSMutableArray to have a couple of extra methods ( -shuffle ,

Is subclassing NSNotification the right route if I want to add typed properties?

泄露秘密 提交于 2019-12-05 01:33:56
I am trying to subclass NSNotification . Apple's docs for NSNotification state the following: NSNotification is a class cluster with no instance variables. As such, you must subclass NSNotification and override the primitive methods name , object , and userInfo . You can choose any designated initializer you like, but be sure that your initializer does not call NSNotification ’s implementation of init (via [super init] ). NSNotification is not meant to be instantiated directly, and its init method raises an exception. But this isn't clear to me. Should I create an initializer like this? -(id

Difference between these two NSString methods

时间秒杀一切 提交于 2019-11-30 19:47:31
So I just got asked this at an interview today and after some googling am still unable to figure out the answer (in fact I couldn't even find any code at all which used the [NSString string] method). What is the difference between NSString *someString = [NSString string]; NSString *someString = [[NSString alloc] init]; Now my initial thoughts were that [NSString string] would return an object which would be autoreleased whereas using alloc and init would return an object which has been retained. However it seems that this answer was incorrect. I've looked at the NSString class reference in the

Difference between these two NSString methods

旧巷老猫 提交于 2019-11-30 04:45:25
问题 So I just got asked this at an interview today and after some googling am still unable to figure out the answer (in fact I couldn't even find any code at all which used the [NSString string] method). What is the difference between NSString *someString = [NSString string]; NSString *someString = [[NSString alloc] init]; Now my initial thoughts were that [NSString string] would return an object which would be autoreleased whereas using alloc and init would return an object which has been

NSString instance reports its class as NSCFString

吃可爱长大的小学妹 提交于 2019-11-27 14:20:22
My objective here is really simple -- I'm trying to set an NSString to some test data, then return the class, which should be NSString . Here's my code: NSString* stringer = [NSString stringWithFormat: @"Test"]; NSLog(@"%@", [stringer class]); The log says that the class is NSCFString , not NSString . What's going on here? NSString is really a container class for different types of string objects. Generally an NSString constructor does return an object that is actually of type NSCFString, which is a thin wrapper around the Core Foundation CFString struct. NSString is a class cluster , along

Custom class clusters in Swift

笑着哭i 提交于 2019-11-27 09:27:17
This is a relatively common design pattern: https://stackoverflow.com/a/17015041/743957 It allows you to return a subclass from your init calls. I'm trying to figure out the best method of achieving the same thing using Swift. I do know that it is very likely that there is a better method of achieving the same thing with Swift. However, my class is going to be initialized by an existing Obj-C library which I don't have control over. So it does need to work this way and be callable from Obj-C. Any pointers would be very much appreciated. I don't believe that this pattern can be directly

NSString instance reports its class as NSCFString

一世执手 提交于 2019-11-26 16:41:39
问题 My objective here is really simple -- I'm trying to set an NSString to some test data, then return the class, which should be NSString . Here's my code: NSString* stringer = [NSString stringWithFormat: @"Test"]; NSLog(@"%@", [stringer class]); The log says that the class is NSCFString , not NSString . What's going on here? 回答1: NSString is really a container class for different types of string objects. Generally an NSString constructor does return an object that is actually of type NSCFString

Custom class clusters in Swift

寵の児 提交于 2019-11-26 14:45:19
问题 This is a relatively common design pattern: https://stackoverflow.com/a/17015041/743957 It allows you to return a subclass from your init calls. I'm trying to figure out the best method of achieving the same thing using Swift. I do know that it is very likely that there is a better method of achieving the same thing with Swift. However, my class is going to be initialized by an existing Obj-C library which I don't have control over. So it does need to work this way and be callable from Obj-C.