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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T15:51:12+00:00 2026-06-12T15:51:12+00:00

Is it: For memory efficiency from not having to store all the program’s methods

  • 0

Is it:

For memory efficiency from not having to store all the program’s methods in RAM all the time? If so, is this really that common a problem? I feel like the overhead of having to load a new method would cancel out the memory savings for normal-sized programs, although I can see how it would help for something very large.

For increased flexibility? If so, could you give have an example of that? I’m finding it difficult to think of one.

I have been trying to Google out the answer to this question and only seem to find resources on how to use categories rather than why. If any of you could point me in the right direction that would be awesome.

  • 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-12T15:51:13+00:00Added an answer on June 12, 2026 at 3:51 pm

    The main reason for categories is to allow you to add methods to a class for which you don’t have the source code, or for which you don’t want to modify the source code.

    Example 1.

    I wanted a method to create an animated UIImage by loading an animated GIF. Logically this should be a UIImage class method, but I don’t have the source code for the UIKit framework (which contains UIImage). So I wrote a category for UIImage that adds a class method named animatedImageWithAnimatedGIFData:. You can find it in my uiimage-from-animated-gif repository.

    Did I have to add this method to UIImage? No. I could have made it a regular C function, or I could have made a utility class (perhaps named AnimatedGIFLoader) to hold the method. But from a design standpoint, the method logically belongs on UIImage.

    Example 2.

    Apple wanted to make it easy to draw a string into a graphics context. In a program with a GUI, it would be reasonable for NSString to have a draw method. Apple has the source code to the Foundation framework (which contains NSString), so they could add it. But the Foundation framework is designed to be used in all sorts of programs, including programs that don’t have any user interface. So the classes in Foundation don’t know anything about UIKit or AppKit or Core Graphics or any other higher-level library that can draw graphics.

    Instead, UIKit has a category that adds the drawAtPoint:withFont: method to NSString. AppKit has a category that adds the drawAtPoint:withAttributes: method to NSString.

    AppKit and UIKit have a number of other categories that add methods to Foundation classes. For example, UIKit has categories on NSObject, NSIndexPath, NSCoder, and more.

    Another reason to use a category is to split up the implementation of a class into multiple .m files. If you have a big class, you can move some of its selectors into a category and implement the category methods in a separate source file. The linker will automatically merge the category into the class when it creates the executable file, so there is no run-time penalty.

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

Sidebar

Related Questions

I have been asked to improve the memory efficiency of an application that is
(This is not exactly the problem that I have, but it's isomorphic, and I
I am trying to store a bitmap (that i have previously read from a
I have to store key value pairs in java which is more memory efficient
Memory Issues So I am writing an app that should be able to page
Fixing memory leaks is good thing, but I want to know apart from memory
I am having trouble understanding how to best use Core Data to solve this
I have a mapping of String id -> Object . Apart from merely having
I want a memory-efficient and time-efficient way of splitting up an incoming stream of
I have something that looks like this: my $report = new ReportGenerator; #custom object

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.