UPGRADE YOUR SKILLS: Learn advanced Swift and SwiftUI on Hacking with Swift+! >>

Got lost in app development, looking for advice

Forums > Swift

Hi guys!

Soon after finishing "Hacking With Swift" course, I decided to make my own poker chips management app (with which you manage all players' chips with no need of using physical ones). It's been almost 2 weeks now and... I'm lost. Filled with frustration from multiple bugs, millions of "ifs and elses" with (much likely) way too many "&&" and "||", I'm stuck now with an unfinished product that I don't know how to repair.

So, for the last 3 days I couldn't help but think that I've been running in circles, with no light at the end of the tunnel. Have you ever experienced something like this? How do you deal with such problems? Should I push forward or just jump to another project, taking a (most likely, ever-lasting) break from this one?

Cheers!

3      

Hello,

I think you made a right decision starting your own project even though it may not feel like it. Even though HWS tutorials will teach you a lot, following a tutorial is still very different to building your own app because suddenly you need to invent everything yourself.

I still remember when I was building my first app 3 years ago, it is quite simple but it took me so much time and lot of if was probably way more complicated than was needed.

It may be also possible that you choose too complicated app project for a start, hard to say.

I think if you were willing you could find people here (myself included) who could do you a code review of current progress but I dont know how to organize it. Since the standard way is to open a pull request in GitHub or GitLab and people can comment on new changes.

4      

Hi Filip,

Thanks for your uplifting words :) I created a new repository, I would be extremely grateful if you could take a look:

https://github.com/DorianZet/Poker-Chips-App

I don't know much about pull requests though, GitHub's explanation is a bit unclear to me.

Of course, anyone is more than welcome to look at what I cooked up and comment on that! :D

Thanks!

3      

Mateus,

You are not alone. The fact that you made it this far is proof that you're good enough.

I think everyone on here would agree they've been in this same position as the code took on a life of its own...

This is when I step away from the computer and break out the notebook. Sketch some states, write out the conditionals, regroup and refresh around your original requirements. Then rewrangle your code.

Good luck! I think you have a great concept, but be sure to add a KR safety feature to keep you from counting while you're sitting at the table. Sorry, couldn't pass up the joke.

4      

hi,

what Filip and Daniel said!

building your own app mostly consists in having an idea of where you want to go (you have that), deciding on what the data is (you have that), building a UI (that's not easy to get right and it will change as you use your app), and supporting the UI <--> data interaction (the MVC stuff).

when you get to the last part, that's when you start to do real coding, and a lot of doing that easily comes from experience. the issues you're running into now (in UIKit) are exactly where you start to lose focus: large ViewControllers (i.e., PokerTableViewController) and code that seems to go on and on (especially code that's repetitious, or put together with plenty of copy-paste for different cases).

it's part of the process; don't fear it; embrace it; and you'll learn from it. in any app that i'm happy with, i've thrown out far more code during development than appears in the final version of the app.

one general comment about your code: if you start repeating code, over and over, it's a sign you need to clean that up. too many bugs will show up because you copied code from one place to another, edited it, but forgot to edit it somewhere else. in those cases, it's usually some combination of either well-chosen functions of simple loops that will solve the probem.

one example: take a look at your TableSettingsViewController. those last 100 lines, broken out by case, are all the same code, except for the number of times you add a TextField and configure it. but you really just need to add a TextField for each player. here's a simple loop that does the same thing:

            for index in 1 ... tableData.numberOfPlayers {
                alertController.addTextField(configurationHandler: { textField in
                    textField.placeholder = "PLAYER \(index)"
                })
            }

and one other example: in PokerTableViewController, you write

    func resetPlayerPropertiesForNewHand() {
        tableData.activePlayers.forEach { $0.playerMadeAMove = false }
        tableData.activePlayers.forEach { $0.playerBetInThisState = 0 }
        tableData.activePlayers.forEach { $0.playerActiveInHand = true }
        tableData.activePlayers.forEach { $0.playerChecked = false }
        tableData.activePlayers.forEach { $0.playerBetInThisState = 0 }
        tableData.activePlayers.forEach { $0.playerWentAllIn = false }
    }

if your PlayerData had a simple function on it to reset all of these properties to the defaults (to 0, true, false), this entire method could be absorbed into:

    func resetPlayerPropertiesForNewHand() {
        tableData.activePlayers.forEach { $0.resetPropertiesForNewHand() }
    }

my recommendation: keep going. but be ready to put the brakes on every now and then and follow Filip's and Daniel's advice.

hope that helps,

DMG

4      

@MateusZ I will try to have a look at your code today or tomorrow. Also as @DMG already said anytime you have repeated code like these buttons or labels you can use loops, forEach to avoid writing repeating code. If you have a lot of same UI elements then it is best to use TableView or CollectionView to save the repetition, have cleaner code and easier time when you want to change how the elements look like, their number etc.

4      

Hacking with Swift is sponsored by Essential Developer

SPONSORED Join a FREE crash course for mid/senior iOS devs who want to achieve an expert level of technical and practical skills – it’s the fast track to being a complete senior developer! Hurry up because it'll be available only until April 28th.

Click to save your free spot now

Sponsor Hacking with Swift and reach the world's largest Swift community!

Archived topic

This topic has been closed due to inactivity, so you can't reply. Please create a new topic if you need to.

All interactions here are governed by our code of conduct.

 
Unknown user

You are not logged in

Log in or create account
 

Link copied to your pasteboard.