Skip to content

Ich kriege hier immer einen Bad Exe Error beim Erstellen einer Hand.#10

Open
ChrisBtt wants to merge 3 commits intoiOS-Dev-Kurs:masterfrom
ChrisBtt:master
Open

Ich kriege hier immer einen Bad Exe Error beim Erstellen einer Hand.#10
ChrisBtt wants to merge 3 commits intoiOS-Dev-Kurs:masterfrom
ChrisBtt:master

Conversation

@ChrisBtt
Copy link
Copy Markdown

@ChrisBtt ChrisBtt commented May 7, 2016

Kannst du mir sagen, woran das liegt?
Ich versuche das jetzt fast seit zwei Wochen und falle bald vom Glauben ab.
Bis zur Funktion die Karten zu vergleichen bin ich erst gar nicht gekommen.

import UIKit

enum Ranks: Int, CustomStringConvertible {
case Ass = 1, König, Dame, Bube, Zehn, Neun, Acht, Sieben, Sechs, Fünf, Vier, Drei, Zwei
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Entferne einfach das = 1 hier und...

@ChrisBtt
Copy link
Copy Markdown
Author

ChrisBtt commented May 7, 2016

Relativ weit unten bei let pokerHand bekomme ich jetzt immer einen Error obwohl der Code doch eigentlich ausführbar ist

while cards.count < 5 {
print("\(cards.count)")
let newCard = Card.createCard()
if newCard != cards[cards.count] {
Copy link
Copy Markdown
Member

@nilsvu nilsvu May 7, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cards[cards.count] ist immer eine Laufzeitfehler, denn die Indizes eines Arrays sind 0..<count, d.h. maximal count-1.

Das append vor dem while brauchst du gar nicht, denke ich. Aber im while solltest du nicht nur die letzte Karte prüfen (das wäre cards[cards.count - 1]) sondern alle bereits erstellten, also z.B. mit cards.contains(newCard).

print("\(cards.count)")
let newCard = Card.createCard()
if cards.contains(newCard) {
break
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

break verlässt die while-Schleife, du brauchst hier continue.

@nilsvu
Copy link
Copy Markdown
Member

nilsvu commented May 16, 2016

2/3 Pt. erstmal, kannst du aber auch noch fertig schreiben.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants