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 8945951
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T12:23:05+00:00 2026-06-15T12:23:05+00:00

I have this snippet of code, BGBaseSnippetCode.h : static NSMutableDictionary * defaultHeightDictionary= nil; static

  • 0

I have this snippet of code, BGBaseSnippetCode.h:

static NSMutableDictionary * defaultHeightDictionary= nil;
static NSMutableDictionary * defaultBoundsDictionary =nil;

+(void)initialize
{
    BGBaseTableViewCell * typical = [[self alloc]init];

    if (defaultHeightDictionary==nil) {
        defaultHeightDictionary = [NSMutableDictionary dictionary];
        defaultBoundsDictionary = [NSMutableDictionary dictionary];
    }
    [defaultHeightDictionary setValue:@(typical.bounds.size.height) forKey:NSStringFromClass([self class])];
    CGRect bounds = typical.bounds;

    NSValue * boundsValue = [NSValue valueWithCGRect:bounds];
    [defaultHeightDictionary setValue:boundsValue forKey:NSStringFromClass([self class])];


}

+(CGFloat) defaultHeight
{
    NSNumber * result = [defaultHeightDictionary valueForKey:NSStringFromClass([self class])];
    return result.floatValue;
}

+(CGRect) defaultBounds
{
    NSValue * result = [defaultBoundsDictionary valueForKey:NSStringFromClass([self class])];
    return [result CGRectValue];
}

I want to insert this in both BGBaseOfAllUIControl.m and BGBaseTableViewCell.m. So I just did that awkwardly:

@interface BGBaseOfAllUIControl ()
@property (strong, nonatomic) IBOutlet UIView *view;
@end
@implementation BGBaseOfAllUIControl

#import "BGBaseSnippetCode.h"

-(id)initWithCoder:(NSCoder *)aDecoder
{
    self = [super initWithCoder:aDecoder];
    if (self) {
        [self BaseInitialize];
    }

@interface BGBaseTableViewCell ()
@property (strong, nonatomic) IBOutlet UITableViewCell *view;

@end
@implementation BGBaseTableViewCell

//static BOOL isDefaultHeightSet = NO;

#import "BGBaseSnippetCode.h"

-(id)initWithCoder:(NSCoder *)aDecoder
{
    self = [super initWithCoder:aDecoder];
    if (self) {
        [self BaseInitialize];
    }
    return self;

Basically both BGBaseOfAllUIControl and BGBaseTableViewCell share the same protocol and I want the exact same code implement the protocol for both side. The BGBaseTableViewCell is a subclass of UITableViewCell and BGBaseOfAllUIControl is a subclass of UIControl.

So I am using .h files to include some implementation. Codes work fine. Just awkward. What would be a better way to do this, or am I doing this right?

  • 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-15T12:23:07+00:00Added an answer on June 15, 2026 at 12:23 pm

    I would forget all the header imports and static dictionary trickery and introduce a separate class that would take care of the layout information you need. Something like:

    @interface BGTableLayoutInfo
    - (float) defaultHeightForClass: (Class) tableViewType;
    - (CGRect) defaultBoundsForClass: (Class) tableViewType;
    @end
    

    In the implementation you’d have a regular (not static) dictionary for caching the layout information for different classes. The only remaining issue is how the table view objects are going to get an instance of the layout class. One possibility is to make the layout info methods static (using a static caching dictionary), second is to keep a shared instance accessible via a +defaultLayoutInfo method.

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

Sidebar

Related Questions

I have this snippet of code: template<typename... Args> class function_helper<void(Args...)>{ public: typedef void(*generic_function)(Args...); static
let's assume I have this snippet of the code: void foo_for_foo( void some_function(int, int))
I have this snippet of code to deal with catching particular exceptions private static
Hi I have this snippet of code : protected void onPostExecute(String response) { String
I have this snippet of code: var ShopLogicOptions = {}; ShopLogicOptions.params = {orderId: '
I have this snippet of code private Templates retrieveFromCache(String name) { TemplatesWrapper t =
I have this snippet of code below. I want to pass the value of
I have this code snippet: $(function() { $('.toolbar [id^=button]').on('click', function () { $(this) .css('background-color',
I have this code snippet: <div id=div1> </div> <div id=div2> <h3>This is the content</h3>
I have this code snippet inside a function that checks if an object exists

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.