Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8328197
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T01:21:38+00:00 2026-06-09T01:21:38+00:00

I’m going to do two something that is considered bad style, but I have

  • 0

I’m going to do two something that is considered bad style, but I have reasons, and I’m open to a Cocoa solution, I just don’t know what it is.

I want an NSArray which is type safe to a UIView, and then an NSArray which is type safe to arrays of UIViews. A 2D array of UIViews.

I’d like this because I’ve implemented a custom double UITableView which has a nested horizontal table view within a vertical table view. I would use my custom ViewsArray and Views2DArray as the data structure which other programmers easily give content to my DoubleTableView. Is that an adequate reason to want to extend NSArray?

The problem I’m having is that I’ve overridden the functionality of the method:

(NSArray *) initWithObjects:(id) firstObject ... as:

(ViewsArray *) initWithViews: (UIView *) firstView, ...

but the return value of my method is an NSArray, which does not have the other methods included in my ViewsArray, which means unrecognized selected exceptions. I’ve solved this temporarily by making a NSArray property of ViewsArray which has my views in it, but this makes for ugly code when I want to feed my content to my DoubleTableView.

Ex:

[[self.delegate content].arraysOfViews objectAtIndex:indexPath.section];

Instead of

[[self.delegate content] objectAtIndex:indexPath.section];

I know it’s a few letters, but I’m trying my best to write good code.

How can I return self in my initWithViews and have an NSArray with my added properties of greatestHeight, totalWidth, etc? (Casting?) Am I thinking about this wrong (with Java/typesafity …)? What’s the best solution for a data structure like this?

Edit:

To solve my problem in a way I deem “stylish”, I did the following:

This is my header (Notice it’s an NSObject):

@interface ViewsArray : NSObject

@property int greatestHeight;
@property int greatestWidth;
@property int totalWidth;

- (ViewsArray *) initWithViews: (UIView *) firstView, ...;
- (UIView *) getViewAtIndex: (NSInteger) index;
- (NSUInteger) viewCount;

@end

This is in my implementation:

@interface ViewsArray ()

@property (retain, nonatomic) NSArray *views;

@end

Which means I just manage a private NSArray. Allowing for pretty references.

What I learnt today: Read the damn documentation and embrace your language. I know this instance may not show that last one, but I’m closer 😉

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T01:21:40+00:00Added an answer on June 9, 2026 at 1:21 am

    Easy solution; don’t bother.

    In using and debugging Objective-C apps using the NSArray/NSDictionary APIs for 18 years, I think I have run across wrong-class-in-collection problems only a few times. In all cases, it indicated an over-arching design issue, not a programmatic error.

    Simply put, your app controls the contents of collections and, unless you stick the wrong thing in a collection, your collection will contain exactly what you expect. In a well written application, the number of places that might add something to a collection should be exceedingly small, typically only one or two spots.

    If you do feel the need to be defensive against this, then add an NSAssert([... isKindOfClass:...]) at the one or two locations that add stuff to the array. No need to add the same at the points of retrieval.

    There is, however, a common false-positive failure mode that’ll appear to be an incorrect type in a collection. If you over-release an object and an object of some other class happens to be allocated at the same location, then you’ll see failures of this mode.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a French site that I want to parse, but am running into
I have just tried to save a simple *.rtf file with some websites and
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I want to count how many characters a certain string has in PHP, but
I have a jquery bug and I've been looking for hours now, I can't
this is what i have right now Drawing an RSS feed into the php,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.