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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T05:05:06+00:00 2026-06-11T05:05:06+00:00

I am writing a basic text editor and need to implement a reading method.

  • 0

I am writing a basic text editor and need to implement a reading method. Since I am using NSDocument, I decide to override the method - (BOOL)readFromData:(NSData *)data ofType:(NSString *)typeName error:(NSError **)outError

Below is my code for the method:

- (BOOL)readFromData:(NSData *)data ofType:(NSString *)typeName error:(NSError **)outError
{
    BOOL readSuccess = NO;
    NSString *fileContents = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];

    if (!fileContents && outError) {
    *outError = [NSError errorWithDomain:NSCocoaErrorDomain code:NSFileReadUnknownError userInfo:nil];
    }

    if (fileContents) {
    readSuccess = YES;

    [textView setString: fileContents];
    NSLog(@"%@",[textView string]);
    }
    return YES;
}

The NSLog returns NULL. I have connected the textView object in my xib to the textView property file’s owner(which is the NSDocument subclass).
What is wrong with my code?

My source files are just the NSDocument subclass interface and implementation files(GNDocument.h and .m). I have two xib files: MainMenu.xib and GNDocument.xib(file owner is set to GNDocument). I am able to NSLog the string to the console. The only problem seems that the NSTextView is not connected to the file’s owner even though I have already done the connection(drag from file owner’s textView property to the NSTextView).

I hope someone can enlighten me as I really don’t see why it doesn’t work. PLease point me to the correct direction, or at least some hint. Thanks.

  • 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-11T05:05:07+00:00Added an answer on June 11, 2026 at 5:05 am

    I found the answer. There is nothing wrong with the connections. What happens is that after I read a file using

    - (BOOL)readFromData:(NSData *)data ofType:(NSString *)typeName error:(NSError **)outError  
    

    I should then setString: to the textView object in the

    - (void)windowControllerDidLoadNib:(NSWindowController *)aController
    

    I will need to hold the string that was read from the file in another NSString ivar so that it can be passed to the windowControllerDidLoadNib method.

    What I did wrong previously was that I setString: in the same method that opens and read the file method, which is before the windowController load the nib file. Hence the textView does not exist before that.

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

Sidebar

Related Questions

I'm writing a text editor using C#, I know i'm just reinventing the wheel
I need some help tag-related! I am writing a simple editor, supporting basic formatting.
I'm writing a basic text editor, well it's really an edit control box where
I'm writing a console application in Visual Basic 2008 Express. I added several text
I am writing a Visual Basic IDE, and I need to add lines numbers
I'm writing a basic text chat web app, and i'm trying to figure out
I am writing a fairly basic GreaseMonkey script that locates text in a specific
I am creating a text editor in C using gtk+-2.0 gtksourceview-2.0. I am having
I want to get some random text generated. I tried writing a basic Java
I am writing some data from database to the excel via visual basic.net.I need

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.