Questions tagged [class-cluster]

A class cluster is an architecture that groups a number of private, concrete subclasses under a public, abstract superclass. The grouping of classes in this way provides a simplified interface to the user, who sees only the publicly visible architecture.

A class cluster is an architecture that groups a number of private, concrete subclasses under a public, abstract superclass. The grouping of classes in this way provides a simplified interface to the user, who sees only the publicly visible architecture.

Source: Cocoa Core Competencies (Class Cluster)

24 questions
94
votes
5 answers

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

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…
openfrog
  • 40,201
  • 65
  • 225
  • 373
20
votes
2 answers

NSString instance reports its class as NSCFString

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…
bloudermilk
  • 17,820
  • 15
  • 68
  • 98
15
votes
7 answers

Custom class clusters in Swift

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…
James Billingham
  • 760
  • 8
  • 32
10
votes
4 answers

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

I am trying to subclass NSNotification. Apple's docs for NSNotificationstate the following: NSNotification is a class cluster with no instance variables. As such, you must subclass NSNotification and override the primitive methods name, object,…
Undistraction
  • 42,754
  • 56
  • 195
  • 331
9
votes
2 answers

Cluster initializers with ARC

Parsing through this document on class clusters, NSNumber implements initWithChar: in roughly the following manner: - (id)initWithChar:(char)c { [self release]; return [[__NSCharNumber alloc] initWithChar:c]; } Similarly, you could use this…
Brian Nickel
  • 26,890
  • 5
  • 80
  • 110
7
votes
5 answers

Difference between these two NSString methods

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…
Jason
  • 519
  • 6
  • 14
5
votes
5 answers

Objective C - Subclassing NSArray

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…
aryaxt
  • 76,198
  • 92
  • 293
  • 442
3
votes
1 answer

Objective-C class clusters and private class initializers

Ordinarily, being a good Cocoa citizen, I write my initializers returning type id (i.e. pointer to generic object) for easier subclassing later (though 99% of time I do not need that). Now I'm creating my own class cluster (lots of private classes…
Eimantas
  • 48,927
  • 17
  • 132
  • 168
3
votes
2 answers

"out of scope" error when iterating an NSMutableArray

Why am I getting an "out of scope" error whenever I try to access the "url" variable in this loop? for(NSString *url in self.winnerImageURLs) { [mediaItemString appendFormat:@"{\"type\":\"image\",\"src\":\"%@\",\"href\":\"%@\"},", url,…
wgpubs
  • 8,131
  • 15
  • 62
  • 109
3
votes
2 answers

Creating a class cluster in objective c - methods called on abstract super class?

I'm trying to create a class cluster for a UITableViewDatasource. My interface looks like this: @interface ArrayDataSource : NSObject - (id)initWithItems:(NSArray *)items cellIdentifier:(NSString *)cellIdentifier…
Sean Danzeiser
  • 9,141
  • 12
  • 52
  • 90
3
votes
1 answer

How to get the name of the "top" class in a class cluster?

Setup: I have data coming in via JSON. Using NSJSONSerialization I convert the JSON to an object. A number value in JSON comes in Objective-C as several different possible class types: (NSNumber, NSDecimalNumber or __NSCFNumber) - all of those are…
Marin Todorov
  • 6,377
  • 9
  • 45
  • 73
2
votes
2 answers

How to create a "class cluster" (factory class with instances of concrete subclasses) in Ruby?

I would like to create an abstract class which will create concrete instances depending on initialization parameter. Example: class SomethingGeneric def self.new(type, arg) class_name = "#{type.capitalize}Something" if…
Stiivi
  • 2,077
  • 2
  • 16
  • 27
2
votes
2 answers

Using a NSString subclass in UILabel et.al

I need to encode additional data to a NSString (Long story, please don't ask why...) I've subclassed NSString using the method outlined here: When I assign one of these subclasses as a UILabel's text I would expect to get it back when asking the…
Avba
  • 14,822
  • 20
  • 92
  • 192
2
votes
1 answer

Inherit from NSNotification

I want to create a subclass of NSNotification. I don't want to create a category or anything else. As you may know NSNotification is a Class Cluster, like NSArray or NSString. I'm aware that a subclass of a cluster class needs to: Declare its own…
7ynk3r
  • 958
  • 13
  • 17
1
vote
1 answer

Class cluster initialization

My iPhone app has an abstract class WorkingView. It is a subclass of UIView. WorkingView will in turn have a bunch of concrete subclasses. Two of those will be SimplifyView and MultiplyView. I am trying to write the method that creates new…
William Jockusch
  • 26,513
  • 49
  • 182
  • 323
1
2