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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T21:52:59+00:00 2026-06-03T21:52:59+00:00

(first time actually asking a question here, so forgive my etiquette blunders) Base Situation

  • 0

(first time actually asking a question here, so forgive my etiquette blunders)

Base Situation: I have multiple images that can move around the screen.

Simple Solution #1:
The main loop would step over the array of objects, tell each one to move itself, then tell the view to refresh itself [self.view setNeedsDisplay]. The view would then get the array and step over it and draw the objects at their point on the screen.

Very simple sample project that puts 200 arrows in a NSArray and moves them around here.

Simple Solution #2:
I then started to experiment with having the objects have their own view as a property.

When the objects were added to the main NSArray, the views were added to the main drawing view. [self.view addSubView:newThing.view].

The main loop would step over the objects and tell them to move. Within the object class, the move would cause the view’s frame.origin to move which would result in them moving on the main view.

This also has the advantage that the objects can add subviews to their image if needed, like particle effects or related subviews.

The disadvantage is that it seems to be putting more view-like code into the model and hides some of the view effort.

Simple sample project here.
Note: Both sample projects are drawing far more things that I expect will be needed in my real simulator.

My “Question?”
Solution #2 led to much cleaner looking code, and doing some short analysis indicates there does not seem to be much performance or memory difference until I get to thousands of objects then the drawing version saves a good bit of memory overhead. But even at 400 objects it is not all that much extra memory to hold all those views.

Is there some reason I should not use Solution #2 that I am missing? Is it ok to “break” VMC a bit by having the model be a bit smarter about what it will be eventually drawing?

  • 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-03T21:53:00+00:00Added an answer on June 3, 2026 at 9:53 pm

    You can probably get around the MVC violation by adding another layer between the objects and the views, with objects that know both the model objects and the views and tell the views to move if something changes.

    Solution #2 requires vastly more memory and computing, especially if you have a lot of objects. It also gives you less control over the drawing, which may be a problem if you want to have special effects. For this reason, at least for games, it is typically not used. But in the end, if it really does make your life easier and you are happy with the performance, there is no reason not to pick it.

    Still, it may be a good idea to look at Core Animation. It allows you to implement a similar pattern (then each object has its own layer instead of a view), but is faster and more flexible for special effects.

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

Sidebar

Related Questions

It's my first time asking here (I have visited the site several times, but
First time asking a question here. Usually I can find my answer without having
First time poster here. A quick question about setting up a loop here. I
First time using this service for a question. I hope I am not asking
first time posting here. I'm using a loop to create 3 buttons, but my
first time use JTree. Just wondering is it possible to have more than one
First time Stack Overflow poster. Please bear with me! :) I have a set
Hey guys, this is my first time actually posting at stackflow but i've used
What I want is that when Activity starts first time, it first checks if
Actually, this is the first time I see a code like this: class A

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.