|
Last July, I posted about searching for a way to conveniently restructure a JSON file (such as adding a new key/parameter to every object currently in the file if I thought of another piece of data I wanted to add to all the entries) rather than using a complex Find/Replace in a text editor. I only got one notification that there were updates to the topic, so I never checked after my second post until this year, when I was looking to add to it again on Tuesday rather than create a new topic on the forum. Many thanks to @Obelix for all the effort undertaken to provide help! As I don't know Javascript and am rather uncomfortable with CLIs, it would take weeks longer to implement one of the possible solutions than the few hours of using Regular Expressions in TextEdit to restructure the data. The only suggested solution I'm currently capable of attempting is using Swift itself to restructure the data. So in this instance, my goal is to add 2 new parameters and place the old
into this
I've omitted the data here for the last two states to try to reduce the scroll length of this post. Given all that, here's my attempt:
And the following is the function I've attempted to create to produce the change (prior to somehow rewriting the JSON file itself), but I get an error on the first line of the outer "No exact matches in reference to static method 'buildExpression'"
Based on what I was able to find on the internet (I found 5 cases of this error), the There's apparently another issue with the |
|
Exactly so.
I don't understand why you have this as a closure. You just need to loop through |
|
Here is a quick and dirty example I whipped up to show you one way you could do it. I use (You can essentially ignore everything except the
Another way to do it would be to create an initializer on
This is how I would do it. The Although, I do feel it somewhat important to point out that the function Heck, you may not even need the function at all, depending on the rest of your code:
Something to think about... |
|
Wow--that's gonna take me a while to work through; thank you! Although I'm stumped--where are the |
|
I wrote that code in a playground, so code that is not contained within a function is executed from top to bottom. It is purely an example of how to write the |
TAKE YOUR SKILLS TO THE NEXT LEVEL If you like Hacking with Swift, you'll love Hacking with Swift+ – it's my premium service where you can learn advanced Swift and SwiftUI, functional programming, algorithms, and more. Plus it comes with stacks of benefits, including monthly live streams, downloadable projects, a 20% discount on all books, and free gifts!
Sponsor Hacking with Swift and reach the world's largest Swift community!
You need to create an account or log in to reply.
All interactions here are governed by our code of conduct.
Link copied to your pasteboard.