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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T09:32:11+00:00 2026-06-04T09:32:11+00:00

FULL CLASS CODE HERE: http://pastebin.com/rdjDGLJS EDIT: Latest code snippet taken from original posters comment

  • 0

FULL CLASS CODE HERE: http://pastebin.com/rdjDGLJS

EDIT: Latest code snippet taken from original posters comment

NSMutableString *spriteType;


- (void) pickSpriteType {

    randomSpriteNumber = arc4random() % 2+1;

    switch (randomSpriteNumber) {
        case 1:
            spriteType = [NSMutableString stringWithFormat:@"typeOne"];
            break;

        case 2:
            spriteType = [NSMutableString stringWithFormat:@"typeTwo"];
            break;
    }
}


- (void) findSpriteNumber {

    levelNumberString = [NSMutableString stringWithFormat:@"%d",levelNumber];

    NSString *path = [[NSBundle mainBundle] pathForResource:@"plist_enemies" ofType:@"plist"];
    NSDictionary *dict = [[NSDictionary alloc] initWithContentsOfFile:path];
    spriteNumber = [[[dict objectForKey:spriteType] objectForKey:levelNumberString] intValue];
}


- (void) initSprite {
    [self moveUp];
    for(int i = 0; i<spriteNumber; i++) {
        if ([spriteType isEqualToString:@"typeOne"]) {
            NSLog(@"repeat");
        }
        if ([spriteType isEqualToString:@"typeTwo"]) {
            NSLog(@"repeat");
        }
    }
}

ORIGINAL POST:

I am using an if statement with an NString using the following code:

- (void) initSprite {
    for(int i = 0; i<spriteNumber; i++) {
        if (spriteType == @"typeOne") {
            NSLog(@"repeat");
        }   
    }  
}

It should be logging “repeat” ‘spriteNumber’ amount of times, as long as the string ‘spriteType’ has the contents of ‘typeOne’, but nothing happens. It does not log “repeat”, but neither does it have any errors. The contents of the string ‘sprite type’ is definitely, ‘typeOne’, and spriteNumber > 0.

What can be done to fix this issue?

EDIT: I have now tried the code like this:

- (void) initSprite {
for(int i = 0; i<spriteNumber; i++) {
if ([spriteType isEqualToString:@"typeOne"]) {
    NSLog(@"repeat");
}}}

It returns an error, EXC_BAD_ACCESS

  • 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-04T09:32:13+00:00Added an answer on June 4, 2026 at 9:32 am

    EDIT: Re. retaining the value of spriteType.

    It looks as if you are attempting to use spriteType as a class variable BUT you do not retain it when you set it’s value.

    spriteType = [NSMutableString stringWithFormat:@"typeOne"];
    

    stringWithFormat: will return an autoreleased NSString which will not be accessible outside of the scope of the method in which it is called.

    The easiest way to get spriteType to work across the whole of your class is to declare it as a @property – In both cases you will need to declare the property in your .h file & synthesise it in your .m file.

    ARC

    @property (nonatomic, strong) NSString* spriteType;

    NON ARC – you will be responsible for releasing the value in dealloc

    @property (nonatomic, retain) NSString* spriteType;

    ORIGINAL:

    Using == on an NSString will test if the two instances of string are indeed the same (pointer equivalence).

    You need to use the NSString method isEqualToString: to test for object equivalence like this –

    if ([spriteType isEqualToString:@"typeOne"])
    

    isEqualToString: tests the contents of the string variables against each other….

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

Sidebar

Related Questions

UPDATE 1: Here is the full code behind from the downloaded example, unedited: using
I'm using the WindowsMedia library found here: http://www.ernzo.com/soundstudio.aspx The sample code had the ability
Possible Duplicate: Gesture detection and ScrollView issue EDIT: question with full code asked here
I am using an horizontal accordion from here: http://www.dynamicdrive.com/dynamicindex17/haccordion.htm I got it to display
UPDATE : The full site code is here - https://github.com/eWizardII/PeerInstruction I have the following
Microsoft shows how to create a dynamic class here: http://msdn.microsoft.com/en-us/library/system.reflection.emit.modulebuilder(v=vs.71).aspx This defines a custom
Here is the xml file of my Android widget: <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
Edit : In case someone wants to look at the actual code, here it
Here is the code: public class beautiful extends Activity { ImageView radar = (ImageView)
Hi I have converted this parallel extension c# code sample to VB.NET http://code.msdn.microsoft.com/Samples-for-Parallel-b4b76364/sourcecode?fileId=25353&pathId=215900242 using

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.