Hey! I have been learning how to program swift because I want to write iOS apps.

For the first, I considered start with recognize my previous concepts in this new language for me, here is my “fizzbuzz” example:

for i in 1...50 {
if i%5==0 && i%3==0 {
print("Fizzbuzz 🍻 ")
}
else if i%5 == 0{
print("Buzz")
}
else if i%3==0{
print("Fizz")
}
else{
print("\(i)")
}
}
view raw fizzbuzz hosted with ❤ by GitHub

My guide to learn Swift and iOS are the follow videos and books:

  1. Swift Mastering The Core Concepts
  2. Building iOS 10 Applications with Swift
  3. iOS Programming The Big Nerd Ranch Guide 6Th Edition

My First App

First, I need to understand this:

  1. How to create a single view iOS app.
  2. How to use the story board.
  3. How to put a buttons and labels.
  4. How to connect the view and the controller.
  5. How to make an event (push a button)

With these learnings, I was be able to create a basic iOS app.

I created a simple view with many input text, labels and buttons. My first approach was make a println in console when pushed the button.

Finding a REST Library

I need find libraries for add to my iOS App, so I installed Cocoa Pods for this job.

gem install cocoapods
pod init

I will use a library for make REST request, so I found Alamofire.

The init command produces a Podfile, where I add my dependency:

platform :ios, '10.0'
target 'HomeOfficeBotApp' do
  use_frameworks!
  pod "Alamofire"
  target 'HomeOfficeBotAppTests' do
    inherit! :search_paths
  end
  target 'HomeOfficeBotAppUITests' do
    inherit! :search_paths
  end
end

Sending a message to slack

Previously I wrote a post where I describe how to send messages to slack channel, you can read again here.

For send a post request with alamofire library, I need to write this:

func sendSlackMessage(message:String, emoji:String){
let slackUrl = "http://your-slack-channel-url.com"
Alamofire.request(slackUrl,
method: .post,
parameters:
["channel": "#general",
"username": "Home Office Bot",
"text":message, "icon_emoji":emoji],
encoding: JSONEncoding.default)
.responseString{ response in
print(response)
}
}
view raw post-request hosted with ❤ by GitHub

This was my first iOS app, although I have a lot of errors, I’m so excited because I can do a simple post request.

Thanks for reading!