Creating the HypnosisView with ScrollView


#1

Could someone please explain why in creating “the HypnosisView with a frame that is twice the size of the screen” this space gives an error?

[code]bigRect.size.width * = 2.0
//with a space between the asterisk and the equal sign will give an error

bigRect.size.width *=2.0
//without a space allows the code to build and run. [/code]


#2

It shouldn’t do, and I have just tried it myself without a problem. Strange one :astonished:


#3

[quote]… with a space between the asterisk and the equal sign will give an error.
[/quote]
That’s because ‘* =’ is not a valid token! The token should be ‘*=’.

Note: A token is a sequence of one or more characters from the token character set.


#4

So this is a token like %f in an NSLog statement?

And it’s standing in for the 2.0 to size the height and width on each line?

Just making sure that I understand.
I couldn’t find clarification from Stack Overflow or the XCode organizer.

Thank you!


#5

I came across this same error when I had a space like the OP did.

Thanks for clearing it up it for us. :smiley:


#6

[quote=“Carignane”]So this is a token like %f in an NSLog statement?

And it’s standing in for the 2.0 to size the height and width on each line?

Just making sure that I understand.
I couldn’t find clarification from Stack Overflow or the XCode organizer.

Thank you![/quote]

*= is an operator that is a shorthand way of saying 'multiply the value in this variable by some number and store the result back in the same variable’
So, instead of writing

x = x * 2;

we can write

x *= 2;

There are similar shortcuts for other operations too:

x = x + 1; can be written x++;
x = x + 5; can be written x += 5;
etc.

What ibex10 is referring to is the *= operator being a token from the parser’s point of view - when your code is compiled it is parsed and split into tokens that the compiler understands. Putting a space between the * and the = causes the parser to fail to recognize it.


#7

Got it.

Thank you!