Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Increment an integer in a Swift Dictionary

Tags:

arrays

swift

I have a dictionary in swift as seen here:

var pictures: [String:Int] = ["http://i.imgur.com/3VGLzoI.jpg":0, "http://i.imgur.com/wATPxvQ.png":0, "http://i.imgur.com/Q2XlngY.png":0]

Is there any way to increment or decrement the integer? If not, would a multidimensional array be a better option. I basically need the "vote" (integer) to stick with the link.

like image 553
user3015221 Avatar asked Dec 29 '25 01:12

user3015221


1 Answers

I think you could do:

pictures["yourKey"]? += 1
like image 90
Logan Avatar answered Dec 31 '25 17:12

Logan



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!