[MyArray insertObject: anObject atIndex: 0];
Reply:
Equivalent of java myArray.insertObjectAtIndex (anObject, 0);
Grammatical form different.
Reply:
[MyArray insertObject: anObject atIndex: 0];
anObject myArray insert an object at that position is 0 where
In fact, a message to the object Objective C syntax from Smalltalk
This is equivalent with the java myArray [0] = anObject;
In fact, Objective C syntax has the advantage that, for you to see an example:
Draw a rectangle in the window method, if it is Objective C would be like this:
- (Void) drawRectWithX: (float) x
andY: (float) y
andWidth: (float) width
andHeight: (float) height
{
}
public void drawRect (float x, float y, float width, float height)
{
}
This seems to also do not see the benefits, then I call it two, respectively, to see the wording:
Objective C:
[Obj drawRectWithX: 10
andY: 20
andWidth: 90
andHeight: 130];
Java:
obj.drawRect (10, 20, 90, 130);
Look, java that if I do not go to method declarations, you can place calls directly from a representative of each of the parameters to see what sense? If you do not know in advance drawRect function mean, you look obj.drawRect (10, 20, 90, 130). Days know 10 What do you mean, mean what 20 is,
And it Objective C, clear, 10 is X 20 is Y 90 is the width 130 is the height I write code without comments can (provided that a meaningful name for you at a glance), you slowly think about it?
Reply:
Thank you for your patience to answer, the problem seems to be coming to solve over, but there is a problem is rather confusing.
[Obj drawRectWithX: 10
andY: 20
andWidth: 90
andHeight: 130];
Code above, the premise is already instantiated object obj, to have JAVA as new Test (). PrintTest ("test methods", false); similar wording you? Namely: Called immediately after instantiation Test methods
[Obj drawRectWithX: 10
andY: 20
andWidth: 90
andHeight: 130];
The above formulation, which andWidth method parameters are all aliases (obj = object, drawRectWithX method alias, real name is float x, I do not know right?), There is a problem out of it, namely: the way to write the four parameters, But when an incoming call 4, that the method name can not call or write the first argument and method names can be the same (can be omitted), or the first one without having to write it?
Reply:
Oh, I am also new to iOS development, just learning Objective C, see the code, not only am truly Martian, but I am truly Mercury Man.

Reply:
[MyArray insertObject: anObject atIndex: 0];
- (Void) insertString: (NSString *) aString atIndex: (NSUInteger) loc;
OC grammar, [] represents a function call, myArray two parameters, one is anObject, one is position 0.
Reply:
The index of the array into an object in front of a location.
No comments:
Post a Comment