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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T20:27:09+00:00 2026-05-28T20:27:09+00:00

i have 7 custom objects with the same properties, createDate and modifiedDate. can i

  • 0

i have 7 custom objects with the same properties, createDate and modifiedDate. can i create a method that accepts Object1 but actually takes all 7 objects?

right now, this works:

[self setCreateAndModifiedTimeWithEvent:((Object1 *) object2 
                                 WithCreateDate:[[eventsArray objectAtIndex:i] objectForKey:@"create_date"] 
                                 AndModifiedDate:[[eventsArray objectAtIndex:i] objectForKey:@"modified_date"]];

.h file

-(void) setCreateAndModifiedTimeWithEvent:(Object1 *)object 
                           WithCreateDate:(NSString *)createStamp 
                           AndModifiedDate:(NSString *)modifiedStamp;

.m file

-(void) setCreateAndModifiedTimeWithEvent:(Object1 *)object 
                           WithCreateDate:(NSString *)createStamp 
                           AndModifiedDate:(NSString *)modifiedStamp

{
    object.A = @"Hello,";
    object.B = @"World";
}

this would cut back on good chuck of lines of code.

i know you can do this sort of thing with UIView and its subclasses. say i have a

UITextField myTextField. 

i can do

((UIScrollView *)myTextField).tag = 2;

is there anything inherently bad about typecasting my objects like this or is it acceptable?

  • 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-05-28T20:27:10+00:00Added an answer on May 28, 2026 at 8:27 pm

    Like Joe said, you’d be better off with something like this:

    @interface DatedObject : NSObject
    
    @property NSDate *createDate;
    @property NSDate *modifiedDate;
    
    @end
    
    @implementation DatedObject
    
    @synthesize createDate;
    @synthesize modifiedDate;
    
    @end
    

    Then have each of the 7 classes inherit from the DatedObject base class. Inheritance is a fundamental part of Object Oriented Programming, and you should learn to use it (wisely).

    Then your method can be:

    -(void) setCreateAndModifiedTimeWithEvent:(DatedObject *)object 
                               WithCreateDate:(NSString *)createStamp 
                               AndModifiedDate:(NSString *)modifiedStamp;
    

    You could also do this with a protocol, but the nice thing about using a base class that the other classes inherit from is that you only have to implement this functionality in one place. If the 7 classes don’t all currently inherit from the same base class (which would end up being the superclass of DatedObject), a protocol is probably the way to go. In that case, you can declare your method like this:

    -(void) setCreateAndModifiedTimeWithEvent:(id<DatedObjectProtocol>)object 
                               WithCreateDate:(NSString *)createStamp 
                               AndModifiedDate:(NSString *)modifiedStamp;
    

    One of the big advantages to these two approaches over what you’ve posted in your question is that you get more help from the compiler in catching places where your code sends a message to an object that doesn’t respond to it.

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

Sidebar

Related Questions

I have a list of custom objects. These objects have 2 datetime properties on
I have a custom object that contains an array (called children) where objects of
I have a large collection of custom objects that I have retrieved from a
I have created a custom panel (MyCustomControl) that can contain other controls and be
I have an NSMutableArray that contains a few custom objects. Two of the objects
I have two lists of custom objects and want to update a field for
I have a list of custom objects List and I would like to update
I have an array of custom objects. MyCustomArr[]. I want to convert this to
I have a listView with custom objects defined by the xml-layout below. I want
I have a single NSDictionary object which contains a large number of custom objects.

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.