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

  • Home
  • SEARCH
  • 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 1071201
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T20:40:46+00:00 2026-05-16T20:40:46+00:00

If you synthesize a custom class, do getters and setters get created for it?

  • 0

If you synthesize a custom class, do getters and setters get created for it?

This is the custom class I created.

//  MyClass.h
#import <Foundation/Foundation.h>


@interface MyClass : NSObject <NSCoding> {
    NSString *string1;
    NSString *string2;

}
@property (nonatomic, retain) NSString *string1;
@property (nonatomic, retain) NSString *string2;

@end

Here I declare an object of that class as a property

//  DetailViewController.h


#import <UIKit/UIKit.h>
#import "MyClass.h"


@interface DetailViewController : UIViewController {

    MyClass *myObject;
}
@property(nonatomic, retain) MyClass *myObject;

@end

Here I synthesize the object.

#import "DetailViewController.h"
#import "MyClass.h"


@implementation DetailViewController
@synthesize myObject;

So does it have getters and setters?

When I try to run this code inside RootViewController.m

DetailViewController.myObject = [theArray objectAtIndex:indexPath.row];

I get an error saying “Accessing unkown ‘setMyObject:’ class method. Object cannot be set – either readonly property or no setter found.’

  • 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-16T20:40:46+00:00Added an answer on May 16, 2026 at 8:40 pm

    Only if you declare the desired instance variables as properties, then synthesize propname;, will getters and setters be created. Now, what kind of code goes into the getters and setters depends on what property attributes you define (nonatomic/atomic, assign, retain, copy)

    EDIT to OP’s revised question: Yes a getter/setter will be created for the myObject instance variable of the DetailViewController class

    DetailViewController.myObject = [theArray objectAtIndex:indexPath.row];

    You are attempting to set a class variable that isn’t defined. DetailViewController is of type Class, not DetailViewController. Perform the same operation on an instance of DetailViewController and you should be all set.

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

Sidebar

Related Questions

If I have a custom class called Tires: #import <Foundation/Foundation.h> @interface Tires : NSObject
I made a custom class. This is the h file @interface Player : NSObject
Say I have a class like this: @interface MyAwesomeClass : NSObject { @private NSString
If I have a custom NSObject class called ProgramModel, does it get alloc/init -ed
Like I understand, @synthesize actually is generating the Getters and Setters. But what's @property
In my app , i created my custom class and i am observing one
Is it possible to somehow create a custom @synthesize to generate custome getter, setters
Got this code for a viewscroller from the apple developers site. @synthesize scrollView1, scrollView2;
I have this code: ViewController .h @property IBOutlet UITextField *field; ViewController .m @synthesize field;
NSString *statusValue; NSString *currentValue; @property(retain, nonatomic) NSString *statusValue; @property(retain, nonatomic) NSString *currentValue; @synthesize statusValue;

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.