Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.
You, the OP, don't understand the difference between the class name machineArray and a variable named machineArray.

And besides, from what I understand of their issue, they don't even need a class named machineArray. They need a Machine class, instances of which will be stored into an array.
 
Ok, i will do this, but someone can say me how to crate an array only if not exist?
I'm doing it in this way.
What i do in worg way?

Code:
#import "ViewController.h"
@implementation ViewController

#import <UIKit/UIKit.h>
@interface ViewController : UIViewController{
	NSNumber *value;        
}

-(IBAction)addNumber:(id)sender;
@end




//###################################################################
#import "ViewController.h"
@implementation ViewController

-(IBAction)addNumberToNumbersArray:(id)sender{
    NSMutableArray *numbersArray;
    numbersArray = [[NSMutableArray alloc] init];
    
	if (! [numbersArray count] ){
        
	}

 	numbersArray[0]=1;
    
}
@end
 
Have you tried this code ? Did it compile ? Did it give warnings ? Do you know what a ViewController is ? What UIViewController is ?

You're trying things at random it seems. I'll add to what dejo and chown are saying, go back to your book, go do the exercises, learn what classes, class instances, variables, types, etc.. are before you get into trying to write out code.
 
From what I see, you want to give me a good life lesson.
I thinked that the forums would serve to learn and not to criticize what one does know or not know.
My thread is becoming almost an interrogation in which all insist on giving me lessons on what to do and no one answers my question of "how to create a simple array that consists of numbers (just in case this does not already exist)."
Can anyone help me on this?
What is wrong in this code?
Code:
-(IBAction)addNumberToNumbersArray:(id)sender{
	if (! [numbersArray count] ){
            NSMutableArray *numbersArray;
            numbersArray = [[NSMutableArray alloc] init];      
	}
 	numbersArray[0]=1;
}
Thank you.
 
Look, the answer to your question is simple : What is wrong with your code ? The fact you have no idea how to write code in the first place. That is what is wrong.

Now, if you want specifics :

Code:
-(IBAction)addNumberToNumbersArray:(id)sender{
	if (! [B][COLOR="red"][numbersArray count][/COLOR][/B]/* numbersArray is undefined in this scope. */ ){
            NSMutableArray *numbersArray;
            numbersArray = [[NSMutableArray alloc] init];      
	}
 	[B][COLOR="Red"]numbersArray[0]=1;[/COLOR][/B] 
              // 1. numbersArray is undefined in this scope.
              /* 2. Your pointer, if it was even defined in this scope, 
                 is to 1 NSMutableArray.  Luckily, you're telling the computer you want to access 
                 the content of memory at the current address so it won't have any ill effect.  
                 However, you've just replaced your instance of NSMutableArray with the value 1.  
                 Again, if it was even defined in this scope to begin with.*/



[B][COLOR="red"]}[/COLOR][/B] 

/* Your "array", if you even managed to define it, 
has just gone *poof*.  Yes, it's gone, it's empty, it's not even 
there anymore.  All those numbers you assigned into it ?  Gone 
too.  Scoping, Scoping, Scoping. */

Bear in mind that the goal of the forum here is not to write code for you, or teach you the fundamentals of programming. We're here to assist you in learning. Obviously, you will have to learn things outside of this forum. If you get stuck on a particular concept, we can explain it.

However, you have shown here that you fail to understand the basic concepts that follow :

- Typing
- Instancing
- Class definitions
- Block/method/global level scopes

Without knowledge of these things, you are just copy/pasting code, and frankly, not even trying to compile it and run it in the IDE (we know, because the code you posted does not even compile ! The compiler would tell you what's wrong if you even tried).
 
Actually, KnightWRX, the "array" is gone even before this line runs:
Code:
numbersArray[0]=1;
because it is local to the if-block that precedes it.
 
- Typing
- Instancing
- Class definitions
- Block/method/global level scopes

I'm talking about an "int". It isn't a difficult type!
In the last code i do not look classes or instance.

Anyhow if you want to help me is good, otherwise I prefer you keep quiet.
However I think here can be only 2 reasons why you're not answering me
1) You do not understand what I do (I have expressed over and over) *
2) You do not know how to do it (I do not think that it is so difficult to write two lines of code, because it is two lines that is)


* If you want I can repeat it:
Create a simple array of numbers only behave and only if does not already exist.



If someone wants to help me I'm here.
THANK YOU.



EDIT:
Actually, KnightWRX, the "array" is gone even before this line runs:
Code:
numbersArray[0]=1;
because it is local to the if-block that precedes it.
I do not know how to check if a vector exists or not, because if there can I not count and I can not add anything.
That's why I can not understand how to do the job.
 
Actually, KnightWRX, the "array" is gone even before this line runs:
Code:
numbersArray[0]=1;
because it is local to the if-block that precedes it.

I know, I made mention of this ;)

Code:
// 1. numbersArray is undefined in this scope.

So yes, technically, the last comment should have been before, since his array is not even method scoped, it's block level scoped in his if block.
 
However I think here can be only 2 reasons why you're not answering me
1) You do not understand what I do (I have expressed over and over) *
2) You do not know how to do it (I do not think that it is so difficult to write two lines of code, because it is two lines that is)

I think you missed one.
3) We don't feel like giving you code which you will just copy-and-paste without understanding how it works.
 
Create a simple array of numbers only behave and only if does not already exist.

Do you mean a C array? Or do you mean an Objective-C NSArray?

Because a C array isn't dynamic without extra code you need to write, and you can't store the plain int type in an NSArray.

So your question is unclear how to answer correctly, or impossible to answer as given, or you are confusing C arrays (which are not dynamic) from NSArray objects (which are).


For reference, do you already know C or not? If you do know C, then do you know about the C functions malloc() and calloc()?

If you don't know C, then what other programming languages do you know?
 
I'm talking about an "int". It isn't a difficult type!
In the last code i do not look classes or instance.

NSMutableArray is a class. Your numbersArray is an instance of a class. See what we're saying ? You don't know about these to the point you don't even see you're using classes and instances of such.

Anyhow if you want to help me is good, otherwise I prefer you keep quiet.
However I think here can be only 2 reasons why you're not answering me
1) You do not understand what I do (I have expressed over and over) *
2) You do not know how to do it (I do not think that it is so difficult to write two lines of code, because it is two lines that is)

I have answered you. Learn about scopes. That will get you on the way.

You obviously don't like the answer to your question and just want the easy way out. You're asking us to write the code for you.

Again, have you tried compiling your code ? Running it ? You're not even answering our questions, why do you expect us to answer yours ?

To answer your question directly :

Create a simple array of numbers only behave and only if does not already exist.

Check using if if the variable holding your array is initialized, if it isn't, initialize it and add your numbers to it.

Yes, that's the answer to your question. That's what you're "basically" doing already. It's just you don't understand the concepts and as such, you're doing it very wrong.
 
Do you mean a C array? Or do you mean an Objective-C NSArray?

Because a C array isn't dynamic without extra code you need to write, and you can't store the plain int type in an NSArray.

So your question is unclear how to answer correctly, or impossible to answer as given, or you are confusing C arrays (which are not dynamic) from NSArray objects (which are).


For reference, do you already know C or not? If you do know C, then do you know about the C functions malloc() and calloc()?

If you don't know C, then what other programming languages do you know?



I want to create an instance of the class NSMutableArray only if doesen't exist and then assing to this an element "int".

I know of php (I make complex dynamic sites for thousands of years) and had good knowledge of Java (I did a test to college a few years ago) but now I remember very little.

EDIT
Ok, KnightWRX I prefer you to leave me alone. This your air of superiority in the long worn inside.
 
I want to create an instance of the class NSMutableArray only if doesen't exist and then assing to this an element "int".

I know of php

Ah, that explains why you would have problems with scoping and declarations. Objective-C requires all variables to be defined in a proper scope you want to use. Again, you really need to read up on scoping.

What you're doing is basically ok, it's just not properly scoped.

Here's a good read to get you started :

http://publib.boulder.ibm.com/infoc...m.ibm.xlcpp8l.doc/language/ref/zexscope_c.htm
 
Ah, that explains why you would have problems with scoping and declarations. Objective-C requires all variables to be defined in a proper scope you want to use. Again, you really need to read up on scoping.

What you're doing is basically ok, it's just not properly scoped.

Here's a good read to get you started :

http://publib.boulder.ibm.com/infoc...m.ibm.xlcpp8l.doc/language/ref/zexscope_c.htm

I don't know very well english and for this reason i didn't know what scope means.
But i know what rapresents (i have worked in java).
I don't know how to create an instance of NSMutableArray only if it doesen't exists. Someone that can help me?
 
I want to create an instance of the class NSMutableArray only if doesen't exist and then assing to this an element "int".

I already stated: you can't store plain ints in an NSMutableArray.

On the question of "if it doesn't exist", you need to look at the fundamentals of the Objective-C language, and learn about the value nil and what it means for an object variable to be nil.

Java has a similar concept, only it's called null.


PHP is nothing like C or Objective-C. At least not in any meaningful way. You need to study the fundamentals:

http://developer.apple.com/library/ios/#documentation/Cocoa/Conceptual/OOP_ObjC/Articles/ooOOP.html
http://developer.apple.com/library/.../ObjectiveC/Introduction/introObjectiveC.html

And you need to go back to your book and do the exercises. The fact that you keep confusing C-array subscripting with Objective-C message sending tells me you don't understand the difference between a C array and an NSArray (or NSMutableArray) object. And the Objective-C type is nothing at all like the Java array type, either.

If you don't understand the difference between the types, you can't possibly write the code yourself. And that's really the point of all these posts: if you understood the fundamentals, you would be able to write the code yourself. You keep trying to avoid studying the fundamentals, but it's not working.
 
ok, thanks for your help and for your useless endless criticism.
Pigliatevelo ner bucio der culen frociazzi
KnightWRX <3 you! ;)
 
Give a man a fish...

...and he'll eat for a day.

Teach a man to fish, he'll eat for the rest of his life.

superkappa, these people don't want give you a fish; they want to help you learn to fish. That's inconvenient now, but it's better in the long run.

I, for one, found Knight's posts to be very informative because they give words and terminology to some of the behaviors I've observed from XCode while trying to write code myself.

Language barriers are challenging aren't they?
 
Ok, KnightWRX, undestand.
Però quanno lo piji nder buscio è sempre tardi.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.