Warning this only works on Mac OS.
Now before you start thinking your going to make the next WordPress, let me just say we are only going to be making the MVP of a blogging site, that’s right a MVP. What is a MVP you may ask ? It stands for Minimum Viable Product, this thing we are about to build is just a web app that has CRUD functionality. What is CRUD you ask ? CRUD is Create Read Update Destroy.
Don’t be afraid of the terminal, the terminal is your friend for life 🙂 you just got to treat it right.
Up and running:
- Install Home Brew, is manages the software you need to manage all the software, your going to use to make software. Just follow the instructions on here: https://brew.sh/
- Install Bundler, it manages the specific Ruby software libraries for your application. Type the following command “gem install bundler”.
- Install Nokogiri, it gives Ruby the ability to understand HTML and CSS among other things. Type the following command “gem install nokogiri”. This is going to take awhile, chill out and take a break you have been working too hard 🙂
- Install Rails, its the thing that you build on top of, to make your web application. Ruby the language has libraries for doing different things. Rails is just a really big library for making web based applications. As you may have guess just type in “gem install rails”.
Making a Rails App:
- CD into a folder you would like to be in and run the following command “rails new <name of your app here> -T “
- Now if you look into the folder you just ran this command in, you will see a folder with the name of your app. Open this with your favorite text editor, VSCode is always a good choice.
- CD into the newly created folder, and make your database. You can do this by running “rails db:create” and then running “rails db:migrate”. What this is doing is creating a database, and then populating it with boiler plate info.
- Now run “rails s” and go to the URL is gives you. You should see your app, YAY you made your first rails app 🙂 If the URL isn’t working try using http:127.0.0.1/8080 or http:127.0.0.1/3000.
Actually making the Blog:
- Run “rails g scaffold Blog title:string body:text”. What this command will do is create a Blog object, that has a title and a body and can be stored in our database. Rails knows this since “g” is for generate, “scaffold” is for create everything for me, and the rest is specify what type of things you want there to be, in the object you are creating.
- Now you got to let the database know about this blog object you made. To do so simply run “rails db:migrate”
- Finally the moment you have been waiting for, run your app with “rails s” and ta-da you go your self a working rails app 🙂
As you an Angular component has a life cycle, much life us humans. In the beginning we are nothing, we do a bunch in the middle and then we die 🙂 However if you want to call a certain service in your “ngOnInit” to dump some values into a var that appears in your html, your going to have a bad time. Or at least angular is by throwing a lot of errors in your console, I mean it will still work.
To get rid of these errors all you have to do it the following add a “?” at the end of the end of the var that’s in the html, and ta-da errors gone. This works since the “?” tells Angular to chill out there will be a value you there “eventually”. Hmm… but why eventually you may ask ? Its because two functions before “ngOnInit” get called , the very first one being the constructor of the class and the second being the “ngOnChanges” method. So for the execution of the first two methods its asking “WTF where is this thing in the html in the .ts file ?” which makes throw errors.
When you inherit from a class you have full access to it’s variables and methods. However what do you do when you would like to use one its methods, and then add to it ? Well you would try to override the method with your definition. This can be accomplished using the “Virtual” keyword on the function you want to override on the parent class. And then using the “Override” keyword on the function in the child class. After which you would then use the “Super” keyword to call the implementation of method found in the parent class.
A real world application of this is, when you want to override and add to the “BeginPlay” method.
Here we see that the TankPlayerController inherits from the APlayerController that inherits from the Actor class. The Actor class holds the initial implementation of the “BeginPlay” method.
Java Script is not different then other languages ! It’s unique and special in its own way.
- For loops
- While loops
- Do – Then loops
- If – Else Statements
- Switch Statements
- Classes and Objects
- Dynamically Typed (most languages have this)
However it has some very weird and interesting differences:
- It has no truth, it is a truthy language
- You can stuff a function into a variable
- There are more ways then one to do the same thing
This part of the Swift language is pretty simple to explain. A “Protocol” is what is called a “Interface” in most of the other languages out there. It is basically a set of rules that your struct, class, or enum has to conform to.
You maybe asking your self “why would I ever need this weird construct ? I know whats what. I don’t need these things if I am doing it all myself. ” Well thing is that it keeps you honest, and it keeps you on track.
More importantly it opens the door to things like delegates. More on this in my next blog post.
Long story short, it helps you with the turning nothingness into somethingness, or at least simulates a sort of nothingness.
In most languages out there like C#, if a variable does not get initialized with a value or is not set to any value, it’s value is “null”. Knowing this, you can go about your life as programmer knowing that you just have to check if that variable is null before using it, and your good 😎
However with Swift that is simply not the case. That is due to the fact that the Swift language does not allow variables to be “null” (In Swift its “nil”) at runtime. It believes that every variable has to have some sort of value. To combat this Optionals came into existence. What Optionals do when Swift asks them if a variable is “nil’, is reply with a “maybe, who knows” and Swift moves on.
Literally speaking here Optionals are just a offshoot of your standard variable that may or may not contain a value. This way your never left wonder why something didn’t have a value, when you thought it would.
Heres a coding example shown below:
This might seem like a very simple and easy thing to some of you out there. However I have failed to see any clear and concise explanation of how to do it. So here it goes:
- Create a segue from from the blue controller to the red controller. You do this by hovering over the icon pictured below, and then clicking and dragging while holding the ctrl button, until your over the view controller you want to navigate to.
- You will be presented with the option below, and for this blog post just pick “show”. Then the following arrow below will be created, this is called a segue. Set the name of the segue to something descriptive, in this case I am going to be naming it “ToRed”.
- Create a button on the blue view controller, and create a IB action for that button. Then inside the method call the “performSegue(withIdentifier: “ToRed”, sender: nil)” method where the “withIdentifier” is the name of the segue you want to use to do the navigation.
- Now create a button on the red view controller and create an IB action for that button. However this time inside the method call the “dismiss(animated: true, completion: nil)”. This method allows you to go back to your previous view.
And thats all there is to it. Next time I think I am going to be getting into the topic of passing data back and forth from views, which requires an understanding of protocols and delegates.
You can find the link to the final product here.