I haven’t had a chance to post in a bit, most times I have a time crunch working on this before my job. Anyways ive still been working on the 100 days of code challenge, I started this from the very beginning of Treehouse’s Beginner iOS Development course. Even though I was working on Enums, but I chose to go back and refresh my memory especially on creating functions and objects.
I’m working on Struct’s and going through this example again im able to wrap my head around the code a little better. I can write out some simple functions with stored properties easily, I know they are blueprints that are highly useful. For this part of the video we create a function inside the struct we created to get a range of points we need. This is the code it will build on.
The struct has two stored properties constants x and y of type Int. Below it to get a range of values on a graph for characters we eventually create there is a few functions. The first function points has one parameter inRange of type int that equals 1 and returns an array of the struct Point.
Below it is a few constants to create a range of points where x and y are added and subtracted from the range. The range were calling from is the local name we gave to the points function. Once those ranges are created we create for loops to cycle through all these coordinate points. The x coordinate is selected then it cycles through all the y values and goes back to the next x coordinate once it gets the values. In the body of the second loop it creates a constant coordinatePoint which is an instance of Point with the values we just obtained. After we get coordinatePoint and append it to the results array which is the empty array we created in the points function. Lastly it returns this results array that now contains the values.