Post

Replies

Boosts

Views

Activity

Reply to How do I swap views in a single window?
I'm going to move this bit up top and start by thanking you for taking the time to answer me and help out. I really appreciate both it and your calm, respectful attitude. The problem, as I see it, is that if there's a webpage in a hidden view it may be refreshing over and over wasting power and bandwidth. If there's animation or a video it would also be playing. Sound might be heard (I don't think it would mute automatically). I figured there was an intended way to do it. I, like others, assumed that staying in one window would be the default and you'd have to explicitly open new ones, or at least have an option for which you want. These suggestions are what I was looking for, along with maybe tabless tabs. I think the splitview or tabless are the likely candidates. I think I'd learn a lot and have a comfortable foothold for my next steps in learning if I could get a grasp of both, even if they're not right. I think what I need to figure out/find/beg from kindly strangers is: What, if any, special VC or container I need for the detail view (on the split). What I need to do to make a button change the view. How to attach a segue to the view change. I'm a little confused on 1 because so much is written for iOS which works differently. I'm getting closer on 2. 3 I'm assuming needs to programmatic (i.e., not interface builder), but should be fairly straight forward once I figure out 1 and 2. I've run into that learning block where the next thing I want to do seems to demand I know ten other things which all demand each other.
Topic: Programming Languages SubTopic: Swift Tags:
Aug ’21
Reply to Using a large CONSTANT
XCode chokes on it. It sputters and slows and and beachballs and after a few minutes I put it out of it's misery. There are no warnings, alerts, or errors. struct Constants { static let PRECOMPILED_DEFINITIONS: [String:String] = ["do": "a dear", "re": "a drop of golden sun", "me": "a name I call myself"] Only it's very long, being a dictionary of the English language. I parsed Wiktionary's 5+ GB down to 46mb so far, but I've reached diminishing returns. Obviously, searching through the dictionary by hand to shrink it is nonsensical. (My first version used a combination of just about every word list I could find with definitions copied from the Apple dictionary, but I kept finding missing words and missing definitions.) The game in it's current state is quite playable except for the loading. It's not that complicated a game. That being said, I opened the file, which was ok at first, and attempted a build so that I could see where I left off. (I was rewriting it to use the const instead of reading the file, but messed up the const access.) XCode and the processes it spawned sucked up all 16GB of my RAM and built a 14 GB swap file beside. The entire system slowed to treacle. I left it for a while with no improvement. I finally had to go around force quitting things until my system could move again. So, I know that a single 46MB line was pushing it. I'm assuming that XCode was scanning it for additional code and code completion. I was hoping to avoid any memory reallocation and needless copying that might be going on in the background. Some kind of directive to not do that might solve it. The dictionary file is constructed by a Python script and imported to XCode manually, so Swift never has to deal with any of that mess. Plus, I can reformat it to whatever I need it to be. I suspect that splitting the dictionary up wouldn't resolve the problem, but would make the rest of the code slower and more complicated than it needs to be. I know it's not the amount of memory. 46 MB is big, but not that big, especially compared to some games. And, I can load the definitions manually, even on an old iPhone 6. It just takes a long time (I literally have to keep waking it up) and it forgets them as soon as I leave the app. (An earlier version with a weaker dictionary didn't clear the memory immediately and the game could usually be resumed without reloading the definitions.) I know loading the lines is still too slow on more recent phones, iPads, and the simulator. (The file code was a very simple get the next line, add it to the dictionary keyed to the next word, loop.) I know it's the definition file. At first I assumed it was building the trie, but I did my homework and it turns out tries are fairly fast, the best structure for that part of the game, and the code was simple and straightforward. Profiling didn't narrow it down, so I put in some print statements and saw that reading the definition file into the dictionary was taking up all that time. I haven't tried using a sorted array yet. I figured it would be the same problem in XCode. It might be more efficient than a dictionary on loading, but I doubt it would be efficient enough. I suspect that it's the size of the file that's the problem, a couple of word lists load almost instantly, so preallocating space for the dictionary wouldn't solve it. I looked at using a plist but initial research suggested it would still need to be loaded and the Python script would need to be retooled to create the correct XML, making the file even larger. I glanced at core data, but it seemed overkill for a big look up table. Finally, it really should be a const. It's used through out the game and is never modified.
Topic: Programming Languages SubTopic: Swift Tags:
Mar ’22