1

I have an interface definition like this:

@interface MasterPanelsController : UIViewController {
    PanelSuperclass *panels[3];
}

I'm trying to programmatically get the count of my panels array, but [panels count] and sizeof(panels) don't work. How can I determine the size of this array?

(Note: PanelSuperclass is a subclass of UIView)

3
  • 2
    Why would you keep ObjC objects in a C array? Commented Dec 9, 2011 at 15:26
  • How about [panels length] ? (if you have to store the, this way I mean) Commented Dec 9, 2011 at 15:27
  • Why not use NSArray instead of C arrays? Commented Dec 9, 2011 at 15:27

3 Answers 3

2

Try using:

int arrayCount = sizeof(panels) / sizeof(panels[0]);
Sign up to request clarification or add additional context in comments.

Comments

2

This is a C array of PanelSuperclass pointers, to get number of items, this C array can hold call the following:

sizeof(panels)/sizeof(panels[0])

Comments

0

You shouldn't use c style arrays for objective-c objects. Use NSArray instead.

2 Comments

It didn't answer my question. If you edit and include an explanation of what the potential repercussions of this approach are, I'll undo.
well ok that's true, but i won't change it and tell you how to do something that you shouldn't do. You'll end up with really really bad code!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.