Ich habe eine Reihe von Posts beim Durchlaufen eines Wörterbuchs gesehen, aber sie sind meiner Meinung nach anders und einfacher als das, was ich hier erreichen möchte. Ich habe folgende Felder:Wie kann ich einen bestimmten CGPoint aus einem Wörterverzeichnis entfernen?
pt1.array = [0:[pt2.point],
1:[pt8.point, pt12.point, pt4.point],
2:[pt20.point, pt14.point, pt3.point],
3:[pt7.point, pt8.point, pt9.point]]
pt2.array = [0:[pt5.point],
1:[pt8.point, pt11.point, pt1.point],
2:[pt10.point, pt9.point, pt3.point],
3:[pt6.point, pt1.point, pt4.point]]
pt3.array = [0:[pt13.point],
1:[pt1.point, pt15.point, pt7.point],
2:[pt19.point, pt14.point, pt2.point],
3:[pt10.point, pt11.point, pt12.point]]
pt4.array = [0:[pt8.point],
1:[pt9.point, pt11.point, pt13.point],
2:[pt14.point, pt15.point, pt6.point],
3:[pt3.point, pt2.point, pt1.point]]
pt5.array = [0:[pt18.point],
1:[pt8.point, pt6.point, pt1.point],
2:[pt3.point, pt17.point, pt4.point],
3:[pt16.point, pt15.point, pt14.point]]
allPoints = [pt1, pt2, pt3, pt4, pt5]
Wie kann ich iterieren pt3.point
zu entfernen, die eine CGPoint aus allen Int
-[CGPoint]
Wörterbücher der allPoints
Array?
versuchte ich folgendes:
for pt in allPoints {
for ptArrIndex in pt.arrays {
for (key, value) in ptArrIndex {
//remove point from dict here
}
}
}
aber ich habe den Fehler:
Type '(key: Int, value:[CGPoint])' (aka'(key: Int, value: Array<CGPoint>)') does not conform to protocol 'Sequence'
an der Linie:
for (key, value) in ptArrIndex {
EDIT
Die Struktur, die jeden der Punkte erstellt unter:
struct Point {
var point: CGPoint
var arrays: [Int: [CGPoint]]
}
AKTUALISIERT FRAGE
Basierend auf Rob Napier Vorschlag ich die Frage aktualisiert haben:
Ich habe eine Struktur unter:
struct Location {
var point: CGPoint
var changedLoc: [Int: [CGPoint]]
}
wo point
ein CGPoint
fürdarstelltund changedLoc
repräsentiert alle möglichen Gruppen von CGPoints Location
können geändert werden. Ich berechne das zufällig.
Ich habe folgende Standorte
var location1 = Location(point: initialBallPosition, changedLoc: [0: [CGPoint(x: 421.0, y: 43.0), CGPoint(x: 202.0, y: 69.0)], 1: [CGPoint(x: 121.0, y: 198.0)]])
var location2 = Location(point: initialBallPosition, changedLoc: [0: [CGPoint(x: 421.0, y: 43.0), CGPoint(x: 123.0, y: 254.0)], 1: [CGPoint(x: 90.0, y: 104.0)]])
var allLocations = [location1, location2]
Von allLocations
wie kann ich den Punkt entfernen CGPoint(x: 421.0, y: 43.0)
die sowohl location1
und location2
changedLoc
ist?
Die Wörterbücher sehen nicht wie '[Int: CGPoint]' aus, sondern '[Int: [CGPoint]]'. –
@ IvensDenner Ich aktualisierte die Frage mit dem, was ich ausprobiert habe – OnlyCodeMatters
kann mir jemand helfen :) – OnlyCodeMatters