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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T10:51:16+00:00 2026-05-27T10:51:16+00:00

This is my first question here. I have a notepad app that you can

  • 0

This is my first question here. I have a notepad app that you can draw on, change pen size, change colors, etc.

The drawing is done in core-graphics code in the view’s drawRect: method after detecting the touches. Now I want to be able to save this drawing to Core Data or a text file doesn’t matter and be able to load it again and keep drawing. Can I save it as NSDATA with imagePngRepresentation? It is bitmap then and I can’t keep drawing again.

Please help me what is the best way to do this, to save the drawing and then be able to load it up again to be able to continue drawing?

Thanks a lot!!

  • 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-27T10:51:16+00:00Added an answer on May 27, 2026 at 10:51 am

    I know this is late, but I spent the past few hours figuring this out myself. So here goes:

    In nib/xib files (and now, storyboards), you can ‘freeze dry’ your views in a file by constructing your interface in Interface Builder. Essentially, what it is doing here is archiving these objects and storing them in a file. Wouldn’t it be great if users could do this to views in your app? Well, they can!

    Apple’s guide on archiving really helped. I read it from front to back.

    For each UIView subclass you have, implement encodeWithCoder:

    - (void)encodeWithCoder:(NSCoder *)aCoder
    {
        [super encodeWithCoder:aCoder];
    
        // Encode any objects you want to load later. 
        // For example: [aCoder encodeObject:colors forKey:@"colors"];
        // Make sure they conform to the NSCoder protocol!
    }
    

    Just a note about this: some objects do not conform to the NSCoder protocol. For instance, I use UIGestureRecognizer objects in some of my UIView subclasses. Since they don’t conform to the protocol, I just recreate them when the view is unarchived with initWithCoder:. So make sure you have a way of retrieving objects that you can’t archive!

    In initWithCoder:

    - (void)initWithCoder:(NSCoder *)aDecoder
    {
        self = [super initWithCoder:aDecoder];
        if (self) {
            // Initialize your view
            // Restore any objects that you encoded
            // For example: self.colors = [aDecoder decodeObjectForKey:@"colors"];
        }
        return self;
    }
    

    To save the view:

    - (NSString *)applicationDocumentsDirectory {
        return [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject];
    }
    
    - (IBAction)tapSave:(id)sender {
        NSString *directory = [self applicationDocumentsDirectory];
        NSString *archivePath = [directory stringByAppendingPathComponent:@"<filename>.archive"];
        BOOL result = [NSKeyedArchiver archiveRootObject:<your root view> toFile:archivePath];
    }
    

    Finally, to load the view and its subviews:

    - (IBAction)tapLoad:(id)sender {
        NSString *directory = [self applicationDocumentsDirectory];
        NSString *archivePath = [NSTemporaryDirectory() stringByAppendingPathComponent:@"<filename>.archive"];
        unarchivedView = [NSKeyedUnarchiver unarchiveObjectWithFile:archivePath];
    }
    

    Hope this helps!

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

Sidebar

Related Questions

Greetings to all! This is my first question here on stackoverflow. I have a
this is my first question.. so, here we go. i have a site, 100%
Sorry, this's my first time to ask a question here. So, I don't have
this is my first time posting here, I have a question which I have
this is my first question here so I hope I can articulate it well
this is my first question here :) I know that I should not check
This is my first question here :) I have an array with a number
Hey stackoverflow - This is my first question here. I have 2 tables in
This is my first question here, so I hope that I am providing enough
this my first question on here. I hope someone can help. It is to

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.