SWIFT – the key to the value of the value of the dictionary?

I have a dictionary in Swift as follows:

[
0: "82" ,
1: "12",
2: "3",
3: "42"
// Etc.
]

And suppose I want to swap the keys to the values ​​82 and 3, so the new dictionary looks like this:

[
0: "3",
1 : "12",
2: "82",
3: "42"
// Etc.
]

What should I do? (I didn’t find any hints and don’t know how to do it, so I haven’t tried this code)

Edit:

I did this:

var first_key = 0
var second_key = 2
var first_value = dict[first_key]!
var second_value = dict[second_key]!
dict[first_key ] = second_value
dict[second_key] = first_value

The basic idea is to create a temporary variable To save one of the values ​​when swapping them.

let tmp = dict[0]
dict[0] = dict[2]
dict[2] = tmp

Or you can use the global swap function (do the same operation internally).

var dict = [< br /> 0: "82",
1: "12",
2: "3",
3: "42"
]

swap(&dict[0], &dict[2])

I have a dictionary in Swift, as shown below:

[
0: "82",
1: "12",
2: "3",
3: "42"
// Etc.
]

And suppose I want to swap the keys to the values ​​82 and 3, so the new dictionary looks like this:

[
0: "3",
1: "12",
2: "82",
3: "42"
// Etc.< br />]

What should I do? (I didn’t find any hints and don’t know how to do it, so I haven’t tried this code)

Edit:

I did this:

var first_key = 0
var second_key = 2
var first_value = dict[first_key]!
var second_value = dict[second_key]!
dict[first_key ] = second_value
dict[second_key] = first_value

The basic idea is to create a temporary variable to save one of the values ​​when swapping them. < p>

let tmp = dict[0]
dict[0] = dict[2]
dict[2] = tmp

Or you can use the global swap function (do the same operation internally).

var dict = [
0: "82",
1: "12",
2: "3",
3: "42"
]

swap(&dict[0], &dict[2] )

WordPress database error: [Table 'yf99682.wp_s6mz6tyggq_comments' doesn't exist]
SELECT SQL_CALC_FOUND_ROWS wp_s6mz6tyggq_comments.comment_ID FROM wp_s6mz6tyggq_comments WHERE ( comment_approved = '1' ) AND comment_post_ID = 4106 ORDER BY wp_s6mz6tyggq_comments.comment_date_gmt ASC, wp_s6mz6tyggq_comments.comment_ID ASC

Leave a Comment

Your email address will not be published.