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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T22:04:26+00:00 2026-05-11T22:04:26+00:00

Yet another C#/.NET guy trying to learn Objective-C with big dreams of making millions

  • 0

Yet another C#/.NET guy trying to learn Objective-C with big dreams of making millions with an iPhone app 🙂

Ok, I’m sure this question stems from me being so used to static typed languages, and therefore am having a tough time adjusting, but here’s my issue. Let’s assume I have a class called MyObect:

MyObject.h

@interface MyObject : NSObject
{

}

-(void)Foo;

@end

MyObject.m

#import "MyObject.h"
@implementation MyObject

-(void)Foo
{
  //do something fooey
}

@end

Now I’m trying to mess with an NSMutableArray of these objects, so in my main I fill an array of these objects something like this:

NSMutableArray *array = [[NSMutableArray alloc] init];
for(int i = 0; i<10;i++)
{
   MyObject *obj = [[MyObject alloc]init];
   [array addObject:obj];
}

Nothing fancy. Now, however, I was trying to pull out the first one of the array, and call the foo method. So, here’s where I’m getting confused. I’ve tried this:

MyObject *obj = [array objectAtIndex:1];
[obj Foo];

and while this works, I get a warning of MyObject may not respond to message. So, I figured, ok, let me cast it:

MyObject *obj = (MyObject *)[array objectAtIndex:1];
[obj Foo];

and that also gives me the warning.

I guess my question is a fundamental question as to how you store items in a collection, and how you pull them out and still retain the object’s type. Again, I’m coming from a .NET background, so maybe my thinking is fundamentally flawed, so if anyone can point me in the right direction, I’d greatly appreciate it.

EDIT: My original code did in fact have the asterisk in the cast (without it you get a compile error). It still shows the warning though…

  • 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-11T22:04:27+00:00Added an answer on May 11, 2026 at 10:04 pm

    This should not give a warning, given that you include the asterisk as you describe in a comment to another answer. In fact, I think the cast is unnecessary — even the version without the cast should not give a warning.

    Make sure that the header file MyObject.h is #imported at the start of the file where you are trying to call your method. The warning that you get is typical of cases where you have forward-declared a class with @class MyObject but not included the header with #import "MyObject.h".

    BTW, in Objective-C one usually starts method names with a lowercase letter, as in Java.

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

Sidebar

Related Questions

Yet another Lucene.net question by an extreme newbie to it. This time, I have
I apologize for yet, another beginner question. I have a .Net background and this
Yet another newbie with ASP.NET MVC! All I intend to do is for a
I've just added yet another 3rd-party component to my .net project that contains a
Yet another data structure doubt. I will get straight to it. This is what
I'm trying to produce yet another lightbox as much needed HTML/CSS/Javascript practice, but I've
Yet another reason why I hate IE for being different. I've got this code:
I'm trying to put together a plugins system with .NET, and I'm not sure
While working fine Chrome and IE7-9, firefox brings yet another surprise... http://jsfiddle.net/D3zXj/ What I'm
Yet another PHP question. I've got two arrays: one string-based and the other numeric.

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.