开发者

notation problem

开发者 https://www.devze.com 2023-03-02 22:31 出处:网络
When i typed [lat1 = newLocation.coordinate.latitude]; its telling expected : before ] token like that. whats my fault? as i am new to this d开发者_运维百科omain., please ayone guide me.

When i typed [lat1 = newLocation.coordinate.latitude]; its telling expected : before ] token like that. whats my fault? as i am new to this d开发者_运维百科omain., please ayone guide me.

Thanks In Prior....


If you are trying to compare lat1 and newLocation.coordinate.latitude, the correct statement would be:

if (lat1 == newLocation.coordinate.latitude) {
    // do something here
}

If you are trying to assign the value of newLocation.coordinate.latitude into lat1, the correct statement is:

lat1 = newLocation.coordinate.latitude;

If you are trying to do the first thing and the compared variables are floating point numbers, then you probably want to check if they are close enough instead of equality:

if (fabs(lat1 - newLocation.coordinate.latitude) < someLittleDistance) {
    // close enough
}

…where of course you will have to define someLittleDistance.


Try the following..

Remove the [] brackets from your line it must be

lat1 = newLocation.coordinate.latitude;


When xCode behaves like this, it probably wants to say that something is the method or it thinks of something like a method. Dot-notation in Objective-C as usual is some kind of equivalent of the setter. For example

ObjectA.property1 = value;

is equivalent of

[ObjectA setProperty1:value];

And in the last case, xCode expects to see : after the setter call and a value after the column.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号