Starting on day 2 we got right into coding and it was intense. We focused all day on basically two methods: prepareForSegue and then another IBAction method that “unwinds” the prepareForSegue method. By unwind, I mean it reverses something or takes you to a place you have already been.
I learned some really useful small tips today that will go a long ways in the future. To start, you can assign properties in the .m (implementation file) just like you can in the .h (header file). This allows you to keep your properties private. The rule at Mobile Makers is to put everything from the storyboard you assign a property to in the .m file. Another cool thing I learned is that within any action, you can call the resignFirstResponder method on a keyboard. So for instance, if you have a UITextField named myTextField you and you want it to hide when you click a button called Calculate, then within the action of the Calculate button you would put [self.myTextField resignFirstResponder]; pretty nifty!
Max told us that fizz buzz is a very popular interview question and we need to become very familiar with answering it. Basically it uses the modulo (%), which returns the remainder of two numbers divided.
So I had a variable named result and the code was like this: result % 3 == 0 && result % 5 ==0. This code was in a if statement and checked to see that the result variable number was divisible by 3 and 5. Both of those were true if the result was 0. But Max taught us that you can find a common number and just use one number so I changed by code to: result % 15 == 0. I did this because 15 incorporates a number being divisible by 3 and 5.
A very cool trick we learned today is that if you do Command-Control-E and click on a variable in your code, it highlights everywhere that variable is and you can change its name across all of your code. Very cool!
Now the hard part: The prepareForSegue method…..
Within this method you must set the destinationViewController equal to a variable. The destinationViewController is the view controller where you are sending the information in the segue. After doing this, you set each unique identifier on each segue. This is going to come in handy later. Then to access a particular segue you check to see what its segue identifier is equal to.
if ([segue.identifier isEqualToString:@”BlueStar”]) {
//code goes here….
}
the if statement above is checking to see if the segue identifier is equal to “BlueStar” and if it is, it will do the code written below it in the statements.
We also learned some cool stuff about images today. All images need to be in PNG format and we need to put all images in the images.xcassets section of Xcode. You can import images into this and then once in it, it is good practice to make sure that all images are in 2x format, which is for retina display. I learned a valuable lesson today that there is a sort of hierarchy to writing code. I had wrote code to change the background color and then under it to add an image on the same view controller, well my image wasn’t showing up. Turns out that is because my image was hidden behind the background. So I simply switched the code and the image was then on top of the background.
Naomi was my partner today and the afternoon MVP and stretch goals were very challenging. We were tasked to create an adventure game that had text in a UITextView and then users selected one of two buttons depending on what they wanted to do after reading the text. Naomi and I got a little carried away with our story but it turned out really cool. Below is a picture of it.
It is hard to see but we have 12 view controllers total, each with a different part of the story on it. The lines going to and from them are the segues that I was talking about earlier. Our story had a lot of twists and turns to it. We completed the second stretch goal by adding a riddle to a view controller and the user had to input the answer they thought was correct using a UITextField. If they got it correct, a button would appear for them to proceed to the next step in the adventure game. They user couldn’t proceed until they figured out the correct answer to the riddle! It took us awhile, but around 8pm we finally figured out how to properly implement the stretch goal. Today was fun and challenging, some people were stressed but I have decided to look at problems as a opportunities to learn more and expand my knowledge and I know I will have many more opportunities each day.
Overall, I feel pretty good about the material today. Git and github are still very challenging for me but Naomi showed me the basics on it and I already feel better. Basically you have to make sure you are in the right folder and branch and then when you are ready to commit your project to github you….
git add Adventure
//Adventure is the name of our project
git commit -a -m “This is the message to attach to the commit”
//-a stands for all
//-m stands for message
git push -u origin master
I believe these are the correct steps and then your project will be on github for all to see. I am going to really get into git tomorrow and ask a bunch of questions about gitx. I’m excited for all the “opportunities” tomorrow.
-Blake