++ Operator

Good Afternoon All


I'm having a problem ++Operator in loops after updating the Xcode 7.3.

I have tried it in all three ways and non e of them worked after this update. those three ways are;

1. x++

2. x += 1

3. x = x + 1

None of the above three work in the loops and is giving error everytime but the third of them was working before the update. Can someone assist me please.


Many thanks

Replies

It will be easier for someone to help you if you post some code and say what the errors are.

Please, don't post the sme question on multiple forums like the Swift one.

All three are correct. There is a saying in debugging - the problem is never where you are looking. Add "NSLog(@"I am here");" lines to your code and you will discover you are not looping as you think you are. If you need more help, post some code.

Please note that the ++ and -- operators are deprecated in Swift 3.0:


https://swift.org/blog/swift-3-0-preview-1-released/

https://github.com/apple/swift-evolution/blob/master/proposals/0004-remove-pre-post-inc-decrement.md

  • Such a standard format being deprecated is very frustrating. I use it in several languages, there was no reason to get this deprecated.

Add a Comment

I can tell you aren't a Swift developer yet 😝. None of them are correct. 1 is wrong because Swift doesn't have ++ operators. They were removed months ago, which is decades ago in Swift time (Swift totally changes every Monday). 2 and 3 are wrong because for loops no longer go off variables like that. For example


for int x = 0, x < 10, x++ {do stuff} // not Swift code


The correct way is


for x in 0..<10 {do stuff}


I would recommend download the Swift manual and having a read through.

I am not a Swift programmer and this post is not in the Swift Forum and no where in your post, up until now, did you say you were programming in Swift. Good luck!

That's why I'll NEVER switch to Swift unless they totally discontinue Objective-C support.

Oh come on now. Who doesn't enjoy the thrill of having 250 errors to fix every Monday? And you gotta appreciate the clever distractors they throw in there. This week, for example, Swift told be to make all my prepareForSegue methods private, but the real solution was to change AnyObject to Any. It's like a treasure hunt! And when they make you change NSPredicate to Predicate and then back to NSPredicate two weeks later? Priceless!

The ++ and -- operator removal is about as childish of a choice as one might find in language design. There are countless examples of how these operators are priceless.

		let elems = pkt.split(separator: ",");
		//$GPRMC,024613,V,3609.9338,N,09556.3937,W,000.0,000.0,160204,004.6,E*7E
		if( gpsDataType == "GPRMC," ) {
			let time = elems[0]
			let warn_V_A = elems[1]
			let lat = elems[2]
			let latdir = elems[3]
			let lon = elems[4]
			let londir = elems[5]
			let speed = elems[6]
			let course = elems[7]
			let date = elems[8]
			let magvar = elems[9]
			let dirs = elems[10].split(separator: "*")
			let vardir = dirs[0]
			let check = dirs[1]
			let latitude = parseLat( String(lat), dir: String(latdir) )
			let longitude = parseLon( String(lon), dir: String(londir))
			self.latitude = latitude
			self.longitude = longitude
			self.heading = Int(Double(course)!)
			self.speed = Int(Double(speed)!)
       }

Why do I have code all these stupid indexes with constants? Why can I not use [idx++] on every index so that I don't have to worry about what line it is, and then for other GPS data, like $GPGGA, I can just copy the lines above that I need to use for that statement and not care at all what the indexes are.