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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T21:18:16+00:00 2026-06-02T21:18:16+00:00

I’m trying to learn how to set variables for different classes using one main

  • 0

I’m trying to learn how to set variables for different classes using one main data class.

Here’s a diagram of of what I would like to do and the code from my project:
enter image description here

ClassA

#import <Foundation/Foundation.h>

@interface ClassA : NSObject {
    NSString *stringA;
    NSString *stringB;
}

@property (nonatomic, copy) NSString *stringA;
@property (nonatomic, copy) NSString *stringB;

@property (weak) IBOutlet NSTextField *textA;
@property (weak) IBOutlet NSTextField *textB;

- (IBAction)displayStrings:(id)sender;

@end

#import "ClassA.h"

@implementation ClassA

@synthesize stringA, stringB, textA, textB;

- (IBAction)displayStrings:(id)sender {
    [textA setStringValue:stringA];
    [textB setStringValue:stringB];
}

@end

Class X

#import <Foundation/Foundation.h>

@interface ClassX : NSObject {
    NSMutableString *stringX;
}

- (void)theVariables:(id)sender;

@end

#import "ClassX.h"
#import "ClassA.h"

@implementation ClassX

- (void)awakeFromNib {
    [self theVariables:self];
}

- (void)theVariables:(id)sender {
    stringX = [[NSMutableString alloc] init];

    ClassA *clssA = [[ClassA alloc] init];

    [stringX setString:@"stringX for stringA"];
    [clssA setStringA:stringX];

    [stringX setString:@"stringX for stringB"];
    [clssA setStringB:stringX];
}

@end

No errors show up in the code, but when I run the program I am receiving an error about “Invalid parameter not satisfying: aString”. It looks like the setStringValue for the IBOutlet is not working. Any suggestions?

  • 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-02T21:18:18+00:00Added an answer on June 2, 2026 at 9:18 pm

    I’m not seeing the error you mention, but as far as I can tell from your code, the main problem is this line:

    ClassA *clssA = [[ClassA alloc] init];
    

    You must have an instance of ClassA in your xib, which is connected to text fields and a button. That object in the xib is a real object, and if you just create another instance of ClassA somewhere in your code, you have an entirely different object that has no connection to the one that’s in your xib.

    You need to make sure of/change two things. First, there needs to be an instance of ClassX in your xib. Second, ClassX needs an outlet to a ClassA instance:

    @class ClassA;    // Declare ClassA so you can use it below
    
    @interface ClassX : NSObject
    
    @property (weak) IBOutlet ClassA * theClassAInstance;
    
    - (void)theVariables:(id)sender;
    
    @end
    

    Which should then be connected in the xib file. Then, in theVariables:, you just use that outlet instead of creating a new instance of ClassA: [[self theClassAInstance] setStringA:@"stringX for stringA"];


    Three points of style:

    First, you should be importing Cocoa.h: #import <Cocoa/Cocoa.h> instead of Foundation.h in any class that touches the GUI (ClassA in this case). That’s where stuff like NSTextField is defined. It works anyways because Cocoa.h is imported via your .pch file, but it’s best to be explicit.

    Second, creating a mutable string and changing its value to two different literal strings doesn’t make a whole lot of sense. Just use the literals directly: [clssA setStringA:@"stringX for stringA"];

    Third, You don’t need to declare the instance variables separately; @synthesize creates them for you, and it is now the recommended practice to not declare them:

    @interface ClassA : NSObject
    
    @property (nonatomic, copy) NSString *stringA;
    @property (nonatomic, copy) NSString *stringB;
    
    @property (weak) IBOutlet NSTextField *textA;
    @property (weak) IBOutlet NSTextField *textB;
    
    - (IBAction)displayStrings:(id)sender;
    
    @end
    

    Last (four points!), you should really be accessing the values of stringA and stringB in ClassA via the property: [textA setStringValue:[self stringA]];

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

Sidebar

Related Questions

I am reading a book about Javascript and jQuery and using one of the
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I'm making a simple page using Google Maps API 3. My first. One marker
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
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 would like to count the length of a string with PHP. The string
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function

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.