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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T17:20:22+00:00 2026-05-11T17:20:22+00:00

REAL newbie here to Objective C and Cocoa. I have this ‘if statement’ if

  • 0

REAL newbie here to Objective C and Cocoa.

I have this ‘if statement’

if (cardCount = 2)
   UIImage *image = [UIImage imageNamed: @"Card 2.png"];

This gives me “error: syntax error before ‘*’ token”

Why? The UIImage line works fine by itself.

I’d appreciate a pointer to what I’ve done wrong.

Thanks
Paul

  • 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-11T17:20:22+00:00Added an answer on May 11, 2026 at 5:20 pm

    First of all, the condition should read cardCount == 2 but that’s not the cause of that error. The problem is, variable declaration and initialization does not count as a statement in language grammar. It’s a declaration. You cannot have a declaration as the body of if, while, etc. (by the way, a block is considered a statement, which might contain declarations, so that’s a different thing). After all, there’s no use to it as it’ll fall out of scope immediately so it’s disallowed.

    UIImage *image;
    if (cardCount == 2)
       image = [UIImage imageNamed: @"Card 2.png"];
    

    If you just need that variable in the if statement (I doubt this is what you want though):

    if (cardCount == 2) {
       UIImage* image = [UIImage imageNamed: @"Card 2.png"];
       // code to use `image`
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is a real newbie question. I have simple app that selects a picture
First off, I'm a real newbie to db and sql. However, I have to
This is a real newbie question, but I am struggling to get this to
real newbie question but why doesn't this work? I am getting use of unassigned
I have a real newbie issue. I have recently uploaded my first android app,
I'm fairly new to Javascript development so this might be a real newbie question.
I'm a real newbie regarding mod_rewrite so please don't laugh. I am using this
I know this is a real newbie question, but that's what I am! I've
Ok, I'm a real newbie at the ASP stuff... I have two related questions:
I hope someone can help me as I am a real newbie. I have

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.