Xcode workspace + keyboard shortcuts

Here I share my Xcode workspace and some keyboard shortcuts for nice development workflow

It consist in 2 windows. One for Storyboard and the other for Code and Debug.

Window 1: Storyboard

Xcode - Storyboard window

That window contains just one tab. Then we will watch two tabs in the second window.

Included panel:
– Document outline
Hidden panels:
– Debug Area
– Navigator

Useful shortcut:
– Zoom-out storyboard: ⇧ + ⌥ + ⌘ + {

Tip: This Storyboard window can be closed when we stop using it, e.g. when there are no more modifications to interface by means of the Storyboard. Then we would have only one window for Coding and Debugging.

Window 2: Code and Debug

Useful shortcut:
– To go to the second window or to go back: ⌘ + ~
Previous one is a OS X shortcut to go to next window of same application.

Tab for Coding:

Xcode - Code tab

Included panel:
– Navigator. Showing Project Navigator view.
Hidden panel:
– Debug Area

Useful shortcuts:
– Document view, to explore properties and methods in current file: ⌃ + 6
– Quick open, to open a file with autocomplete search mode: ⌘ + ⇧ + O

Tab for Debugging:

Useful shortcut:
– To go to the second tab: ⌘ + ⇧ + }

Xcode Debugging tab + Simulator

Useful shortcuts:
– Run app in Simulator: ⌘ + R
– Return to Xcode (to stop the app): ⌘ + ⇥
(previous is a OS X shortcut)
– Stop the app: ⌘ + .
When debuggin:
– Step over Breakpoint: f6 (fn + F6)
After debugging:
– Close opened file: ⌃ + ⌘ + W
– Clean Console: ⌘ + K

Posted in iOS | Tagged , | Leave a comment

Consuming RESTful API on Rails

It’s great to consume APIs. Here we got a Rails way to do this. For this example code we will use “Week” model.

Note: If RESTful API its provided by default Rails, json.builder files and methods in controllers should be working.

RESTful_API_serving_from_Rails

1. Include ActiveResource in Gemfile

2. Execute “bundle install” in command line

3. Declare the model that inherits from ActiveResource::Base. There we need to define the uri for API consumption.

4. Create a Controller and “index” method. In this example code, we just retrieve all records.

5. Include weeks in routes.rb

6. Now we can use the Object Collection. Just render @weeks

7. Yes! It’s better to use the _week.html.erb partial to render each object in the collection

 

Posted in Ruby on Rails | Tagged , , , , , , , | Leave a comment

Dynamic and meaningful titles on our websites

Let’s work an important feature of our web apps: Page titles. These provides a better experience for the visitor.

While developing a website we use to have our broswer full crowded of tabs. The only way to know in which tab is the page we are looking for is by means of Page Title.

Meaningful_page_titles

1. Create a method that generates markup for the layout

2. Set a meaningful title using previously defined method. Neat detail is that we can use variables, so now our titles are dynamic!

3. Use title defined in the View. It’s a good practice to include a default value, “My Website” in the example code.

That’s all. The power to titles can be provided by variables defined and constructed in controllers. Use methods of your models to obtain great titles.

Posted in Uncategorized | Tagged , | Leave a comment

Access Class’ CONSTANT value from JavaScript

Let’s say coffeescript, properly.

First. Declare a CONSTANT in the model and assign a value to it:

 

Rename the js.coffee file to js.coffee.erb. First language be processed will be Ruby. Assign the constant value to a javascript variable with the classic shorthand:

Posted in Ruby on Rails | Tagged , , | Leave a comment

Turbolinks conflict with JQuery

Rails 4 incorporates Turbolinks. This “accelerates” page load, usign Ajax calls for content retrieval. Pages load pretty fast… but… JQuery doesn’t load the first time a page loads, it only works after refreshing or on reload.

To solve this, we can use jquery-turbolinks gem. Include it in Gemfile

Then, require it on Javascript application

Posted in Ruby on Rails | Tagged , | Leave a comment

Filter in Controller. Within a month, one date given

In this case we got a date as parameter. We want to show the records within the same month of the record’s date. (code modified thanks to suggestion by Bob Roberts)

 

Parameter can be sent in the following way

 

Posted in Ruby on Rails | Tagged , , , | 3 Comments

Working with Parameters in View and Controller

This is how we can send parameters from View to Controller

 

In controller we should validate the parameter and stablish a default value

 

Posted in Ruby on Rails | Tagged , , | Leave a comment