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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T10:21:58+00:00 2026-06-04T10:21:58+00:00

My Objective-C is pretty rusty or non-existent. I’m trying to figure out how this

  • 0

My Objective-C is pretty rusty or non-existent. I’m trying to figure out how this code does what it does in order to modify it and having some trouble. This code basically draws lines at a pixel position on an ipad UIView (along the width of the iPad, like a density or column plot) based on the data it has. From the data, it calculates what values to assign and then another method draws the information.

In the .h file, this ivars are declared

ushort *mapBins;
int mapBinSize;
int mapBinMin;
int mapBinMax;

Then in the .m (commented out code is what I’m trying to do)

mapBins = 1024;
mapBins = malloc(mapBinSize * sizeof(ushort));
memset(mapBins, 0, mapBinSize * sizeof(ushort));


int pixelPos = 0;
// populate bins
for (int l=0; l<[locs count]; l++) // locs is a member variable that has positions to draw where there is valid data, everything else is blank
{
    int sLoc = [[locs objectAtIndex:l] intValue];
    pixelPos = (sLoc - self.startPos) / [self basesPerPixel];
    int index = pixelPos;
    if (index > mapBinMax) {
        continue;
    }
    if (index < 0 )
    {
        continue;
    }
        //        if ([m.type rangeOfString:@"A"].location == NSNotFound) {
//            mapBins[index] = 0;
//        }
//        else {
//            mapBins[index] = 1;
//            NSLog(@"1");
//        }
//        if ([m.type rangeOfString:@"T"].location == NSNotFound) {
//            mapBins[index] = 0;            
//        }
//        else {
//            mapBins[index] = 2;
//            NSLog(@"2");
//        }

    mapBins[index] += 1;
}
return YES;
}

So with their code, in the drawing code, it basically checks

 if (mapBins[posX] == 0) {
        [blank setStroke];
    }
 else {
      [YELLOW_COLOR setStroke];
 }

for each pixel. So now I want to change the colors based on the information I have from the data. Like in the commented out code, it shows a part of what I’m trying to do.

What I don’t understand is, I set the mapBin[index] to something other than 0. I see that by the NSLog(@”1″) statement on the console. However, if I log the output at the end of the loop by doing: NSLog(@"%i", mapBins[posX]); I get 0 as the output. And when I try drawing it, I get a blankStroke instead of a colored stroke since the value is 0.

Is something going on that I do not understand in C? What I gather is they are doing this (could be wrong though):

  • set the mapBinSize to the size of one screen length or 1024 pixels
  • create memory for that array?
  • then based on the data, if there is a value at that bin, add a number so it can draw a value at that region later on.
  • 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-04T10:22:00+00:00Added an answer on June 4, 2026 at 10:22 am

    Your commented-out logic will always result in either 0 or 2. Whatever you set from the comparison to @”A” is written over unconditionally by the following if/else.

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

Sidebar

Related Questions

Having just started with Objective-C, this might be a pretty basic question. In objective-c,
This is probably a completely stupid question, but i'm pretty new at objective-C and
I'm still pretty new to Objective-C coding (as evidenced by this question) and I
I'm pretty new to objective c, and having some basic problems. I wrote a
Hi guys this will be my first post and am pretty new to Objective-C
I've got pretty simple code out here: NSArray* divisions = [[NSString stringWithFormat: @%d, system(ssh
As I'm pretty new to Objective-C and memory management, I was curious if this
another Objective-C one for you, probably pretty obvious but I have been at this
I'm pretty new to Objective C, and I'm having trouble reading values from a
I'm still pretty new to Objective -C and iPhone development and am trying 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.