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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T09:51:14+00:00 2026-06-17T09:51:14+00:00

Here is the question, hopefully easy to answer. I’m making a class in which

  • 0

Here is the question, hopefully easy to answer.

I’m making a class in which you give it an array of views and it saves all the elements inside it and is able to read them back. I got the saving working by using NSArchiver class, but not the reading part.

@interface preferences : NSObject

- (void)savePreferences;
- (void)readPreferences;

@property (strong) NSMutableArray *theViews;

@end
 #import "preferences.h"

@implementation preferences
- (id)init {
    self = [super init];
    if (self) {
        _theViews = [[NSMutableArray alloc]init];
    }
    return self;
}

- (void)savePreferences{
    NSLog(@"Saving Preferences...");
    [NSKeyedArchiver archiveRootObject:_theViews toFile:@"preferences.xml"];
}

- (void)readPreferences{
    NSLog(@"Reading Preferences...");
    _theViews = [NSKeyedUnarchiver unarchiveObjectWithFile:@"preferences.xml"];
}

@end

The idea is I want an easy way to save preferences and recall them later. I’m aware of NS_UserDefaults, and doing it manually by creating connections from interface builder to my code, but I have literally thousands of preferences that I would have to make connections for and save.

So my goal is to create a class where I say something like…

[preferences savePreferencesForViews:ArrayOfViews];//For Saving
[preferences readPreferencesForViews:ArrayOfViews];//For Reading

My plan was to set the identifier attribute in interface builder for every element. Then to get a value out of it I would have a function cycle through every subview in the views until it found one who’s identifier matched what I requested and I would inspect it’s classtype to create a temporary variable of that and use that temporary variable of the class tpye to get the value out of it.

For example, lets say the object inside of my NSView was an NSTextView with the stringValue of “hello world”

Using the NSViews method subViews I return an array of all it’s subviews, which would include the NSTextView mentioned above.

I can use the function from NSObject className to return the classname as @”NSTextView”.

Then I should be able to say… one of two things

   [subView setString:@"hey"];//compile error

or…

 NSTextView *temp = subView;
    [temp setString:@"test"];

That compiles but I get a warning (Incompatible pointer types initializing ‘NSTextView *__strong’ with an expression of type ‘NSView *const __strong’)

When I run the program and attempt to run my routine it crashes and says -[NSTextField setString:]:unrecognized selector sent to an instance 0X101a0cfe0

I have no idea what to do, help would be appreciated!

Hi there guys. Here is the question, hopefully easy to answer.

I’m making a class in which you give it an array of views and it saves all the elements inside it and is able to read them back. I got the saving working by using NSArchiver class, but not the reading part.

@interface preferences : NSObject

- (void)savePreferences;
- (void)readPreferences;

@property (strong) NSMutableArray *theViews;

@end
 #import "preferences.h"

@implementation preferences
- (id)init {
    self = [super init];
    if (self) {
        _theViews = [[NSMutableArray alloc]init];
    }
    return self;
}

- (void)savePreferences{
    NSLog(@"Saving Preferences...");
    [NSKeyedArchiver archiveRootObject:_theViews toFile:@"preferences.xml"];
}

- (void)readPreferences{
    NSLog(@"Reading Preferences...");
    _theViews = [NSKeyedUnarchiver unarchiveObjectWithFile:@"preferences.xml"];
}

@end

The idea is I want an easy way to save preferences and recall them later. I’m aware of NS_UserDefaults, and doing it manually by creating connections from interface builder to my code, but I have literally thousands of preferences that I would have to make connections for and save.

So my goal is to create a class where I say something like…

[preferences savePreferencesForViews:ArrayOfViews];//For Saving
[preferences readPreferencesForViews:ArrayOfViews];//For Reading

My plan was to set the identifier attribute in interface builder for every element. Then to get a value out of it I would have a function cycle through every subview in the views until it found one who’s identifier matched what I requested and I would inspect it’s classtype to create a temporary variable of that and use that temporary variable of the class tpye to get the value out of it.

For example, lets say the object inside of my NSView was an NSTextView with the stringValue of “hello world”

Using the NSViews method subViews I return an array of all it’s subviews, which would include the NSTextView mentioned above.

I can use the function from NSObject className to return the classname as @”NSTextView”.

Then I should be able to say… one of two things

   [subView setString:@"hey"];//compile error

or…

 NSTextView *temp = subView;
    [temp setString:@"test"];

That compiles but I get a warning (Incompatible pointer types initializing ‘NSTextView *__strong’ with an expression of type ‘NSView *const __strong’)

When I run the program and attempt to run my routine it crashes and says -[NSTextField setString:]:unrecognized selector sent to an instance 0X101a0cfe0

I have no idea what to do, help would be appreciated!

My implementation of the interface is below

@implementation appController

- (IBAction)savePreferences:(id)sender {
    NSLog(@"Save Button Pressed");

    //Create an instance of the preference class.
    preferences *PreferencesObject = [[preferences alloc]init];

    //Add the views we want to sve to the PreferenceObject.
    [[PreferencesObject theViews]addObject:_preferenceView];

    //Save the actual preferences now.
    [PreferencesObject savePreferences];

}
- (IBAction)loadPreferences:(id)sender {

    //Create an instance of the preference class.
    preferences __strong *PreferencesObject = [[preferences alloc]init];

    //Read the preferences into it's internal array.
    [PreferencesObject readPreferences];

    for(NSView __strong *view in [PreferencesObject theViews]){
        if([[view identifier]isEqualTo:[_preferenceView identifier]]){
            NSLog(@"View Match Found For PreferenceView, Setting...");


            for(NSView *subView in [_preferenceView subviews]){
                if([[subView identifier]isEqualTo:@"name"]){
                    NSLog(@"Attempting to set value of name control");
                    NSTextView *temp = subView;
                    [temp setString:@"test"];
                }
            }


        }
    }


}
@end
  • 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-17T09:51:15+00:00Added an answer on June 17, 2026 at 9:51 am

    It seems like your views array contains text fields, not text views, maybe you made a binding error in IB.

    A text field responds to setStringValue: , not to setString: .

    Some tips

    • You can test the class belonging of an object;
    • Provided that you are sure that a pointer points to an object of a certain class, you can cast the pointer. In your case you would do a downcasting (from base class to subclass).

    So you would do something like:

    if ([ subview isKindOfClass: [NSTextView class]]) // until you fix that binding error or whatever, it will return NO
    {
        NSTextView* temp= (NSTextView*) subview;
        [ temp setString: @"temp" ];
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

first question here, so hopefully you'll all go gently on me! I've been reading
Hopefully this is an easy question to answer! I am trying to use GtkEntryCompletion
hopefully a quick question here, have not been able to find out the answer
Hopefully this question has an easy answer. It's probably something stupid I'm doing! In
Quick question hopefully someone can help out here. I'm trying to copy and paste
im struggling with syntax here: hopefully this question is v simple, im just miising
Hopefully the last NN question you'll get from me this weekend, but here goes
I have what I think is a tricky question, but hopefully someone on here
I just started WPF this morning so this is (hopefully) an easy question to
a bit of a softball CSS question here (hopefully). I'm looking for some CSS

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.