Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

39,845 questions

51,766 answers

573 users

How to create a dictionary with key type point (x, y) and value type string in Swift

1 Answer

0 votes
import Foundation

// Define Point as a struct that conforms to Hashable
struct Point: Hashable {
    let x: Int
    let y: Int
}

// Create a dictionary with Point keys and String values
let pointDict: [Point: String] = [
    Point(x: 2, y: 7): "A",
    Point(x: 3, y: 6): "B",
    Point(x: 0, y: 0): "C"
]

// Print x and y separately
for (point, value) in pointDict {
    print("x: \(point.x), y: \(point.y) => \(value)")
}



/*
run:

x: 3, y: 6 => B
x: 2, y: 7 => A
x: 0, y: 0 => C

*/

 



answered Aug 10, 2025 by avibootz
...