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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T00:04:38+00:00 2026-06-04T00:04:38+00:00

I have 2 classes, ClassA and ClassB ClassA has one BOOL variable set to

  • 0

I have 2 classes, ClassA and ClassB

ClassA has one BOOL variable set to No.

I am trying to set this variable to Yes from ClassB, but can’t seem to figure out how to.

Below is the code I am using which doesn’t work, it is simply what I would’ve thought would work, I have stripped out the unnecessary information:

Class A:

ClassA.h

@interface AppDelegate : NSObject <NSApplicationDelegate> {
    BOOL boolean;
}

- (id) init;

ClassA.m

- (id) init {
    boolean = NO;
}

Class B:

ClassB.h

#import "ClassA.h"

- (IBAction) setBoolean: (id)sender;

ClassB.m

- (id) init {
    ClassA * theClassA = [[ClassA alloc] init];
    return self;
}

- (IBAction) setBoolean: (id)sender {
    [theClassA boolean] = YES;
}

I hope this makes sense. I simply want to set the BOOL boolean in ClassA to YES from ClassB.

  • 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-04T00:04:39+00:00Added an answer on June 4, 2026 at 12:04 am

    You can’t assign a property like that ([object property] = value). The proper syntax is [object setProperty:value] or object.property = value.

    I wouldn’t call a variable boolean. Might be misleading. Even though it’s not the keyword for a boolean variable in Objective-C it is in a lot of other languages.

    And you have to return the initialized object (self) in your init method (you have an id return type, not void):

    - (id) init {
        self = [super init];
        if (self) {
            boolean = NO;
        }
        return self;
    }
    

    Also, you didn’t specify an instance variable for theClassA in your ClassB implementation. You just create a local object and then leak it (you don’t release it). Instead, declare it in your ClassB.h:

    @class ClassA;
    @interface ClassB : NSObject {
        ClassA *theClassA;
    }
    - (IBAction)setBoolean:(id)sender;
    @end
    

    Then initialize it like this:

    - (id) init {
        self = [super init];
        if (self) {
             theClassA = [[ClassA alloc] init];
        }
        return self;
    }
    

    And don’t forget to release it in dealloc:

    - (void)dealloc {
        [theClassA release];
        [super dealloc];
    }
    

    And one last thing. Having a method - (IBAction) setBoolean: (id)sender in your ClassB implies that ClassB has a property called boolean, which is not the case. I recommend renaming that method and/or rethinking your class designs.

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

Sidebar

Related Questions

I have two classes namely classA and classB which both inherit from class1 .
I have three classes: ClassA , ClassB , ClassC . ClassC extends ClassB which
I have two classes that I am testing (let's call them ClassA and ClassB).
I have two classes, ClassA and ClassB , as well as a many to
I'm sure this question has already been asked in one form or another, but
I have two classes ClassA and ClassB. ClassA always needs an template file name,
In one of my classes, I have an integer that stores a set of
Assume I have classes A1 and A2 and a class B that has elements
I have two classes that extend the activity class. Each class has it's own
Assume I have two base classes, Container and Gizmo . Class Container has an

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.