Networking in Swift: Building the Swift Client, Part 1

If you've been following along from the beginning of this tutorial series on networking in Swift, you're now running a local web server and have created a simple RESTful API in PHP that serves up the inventory for our hypothetical Super PHPlumbing Bros. project. In this segment of the series, we'll build the iOS Swift client to bring that content to our end user. In the present article, we'll start our Swift project from scratch and create a single view application using a table view controller that will serve as the primary interface to our inventory of plumbing tools and supplies.

In the Beginning . . . 
Download and install the latest version of Xcode, if you haven't already, and fire it up. From the Xcode menu bar (or the Welcome screen) select File->New->Project. A window will appear with various options to choose from. In the left hand panel, under iOS, choose 'Application'. And in the main panel select 'Single View Application'. Then go ahead and click 'Next' as shown below.

On the following window you will be asked to name your application. Name it what ever you like. Under the Language section select Swift from the drop down menu. Make sure that the build is for iPhone in the 'Devices' menu, and then click 'Next' again.

You'll then be prompted to choose a location to house your project and will be given the option to place the project under source control. If you know how to use git for source control, then by all means use it! Otherwise, uncheck the box if it is already checked and click 'Create' to start up the project.

Displaying the Available Services
In our Swift application, we want to present the user with all the available services that our supply shop has to offer. Our custom API provides an interface to our inventory of Plumbing Tools as well as our inventory of Copper Pipes and Fittings. To present these options to the end user we are going to use a table view. So let's jump in. In the navigator panel (the left panel) of Xcode, locate and select the file named Main.storyboard.

Once the main storyboard loads, scroll to the pre-loaded Single View Controller and select it. When properly selected its border will turn blue, as seen here:

As we are going to use a table view, we can safely discard this default view controller. Delete the single View Controller by pressing the delete key on your keyboard, while the controller is selected. In the Utilities Panel on the right side of the Xcode interface, locate the Object Library submenu. Select a Table View Controller, and drag and drop it inside the main storyboard. 

While the new controller is selected, point your mouse toward Xcode's menu bar and select: Editor->Embed In->Navigation Controller. This embeds our selected Table View Controller into, you guessed it, a Navigation Controller.



A Navigation Controller is a stack for managing the presentation order of our view controllers. Select the Table View situated inside the Table View Controller, and then select the Attributes Inspector from the Utilities Panel. Locate the 'Content' field and select 'Static Cells' from its drop down menu.


You should see three cells appear inside the Table View. We only need two such cells, as this is where the user will be presented with the option to browse either the Plumbing Tools inventory or the Copper Pipes and Fittings inventory. Delete the bottom cell by first selecting it, and then pressing the delete key on your keyboard. Now let's name our two primary interfaces. For each of the two remaining cells, select the cell, and then locate the 'Style' field in the Attributes Inspector panel. From the 'Style' drop down menu select 'Basic'.


Both table view cells should now display a label that reads 'Title'. Two clicks in rapid succession on a label will place it into edit mode. Modify the titles so that they read from top to bottom, 'Plumbing Tools' and 'Copper Pipes and Fittings', respectively.

In order for the application to run, we need to specify the initial view controller that we want to load when the application first boots up. In the main storyboard, select the Navigation Controller. Then, in the Attributes Inspector menu, locate the check box that reads, 'Is Initial View Controller' and select it as shown below:

In the top left corner of Xcode make sure that the active scheme is set, and click the play button to build and run the application. Once the iOS simulator starts up, your app should look like this:

This project can be found on GitHub.

Success! We've built the primary view that will be presented to the end user when they open our iOS application. In part two of this segment, we'll begin building our data models. You can find part two in the tutorial on building the Swift client at the link.

Index
Introduction
Introduction and Overview: From the Back End API to the End User Application

The Web API
Building a RESTful API in PHP, Part 1
Building a RESTful API in PHP, Part 2

The Swift Client App
Networking in Swift: Building the Swift Client, Part 1
Networking in Swift: Building the Swift Client, Part 2
Networking in Swift: Building the Swift Client, Part 3
Networking in Swift: Building the Swift Client, Part 4
Networking in Swift: Building the Swift Client, Part 5

This tutorial was authored by Stefan Agapie, a Senior iOS Software Engineer, and adapted for the present piece. 

Foils, Not Oil: Emission-Free "Quadrofoil" Boat To Debut In 2015

If you're already over the wintry weather and just want summer to get here again, here is some post-Halloween brain candy for you.  Check out what techplus24.com calls the "21st century's answer to the speedboat":  the Quadrofoil.

Chicks dig ecologically-conscious mariners.
(Image courtesy gizmag.com.)

Using C-shaped foils beneath the hull to create lift, the Quadrofoil appears to hover above the water.   The foils deflect the water downward, creating lift and exerting force that enables the craft to travel at 25 m.p.h.  The Quadrofoil can transport two passengers and is made of 220 pounds of lightweight composite materials.  It is nearly theft-proof, thanks to a detachable wheel that acts as its key.

Best of all, the Quadrofoil operates on an electric motor, which creates no unpleasant emissions and makes considerably less noise than conventional motorboats.  The cleanliness of the craft allows it to operate on lakes, rivers, and ecologically-protected areas that might not be happy to harbor other messier boats.  Seeking out these spots is easy, with a single charge of the battery enabling the Quadrofoil to travel for 62 miles (at a cost of about $1.30 an hour to run.)  Don't just watch the meniscus-meandering water bugs from the dock...now, you can act like one too!

Make jetskiiers jealous.
(Image courtesy diseno-art.com.)


The Quadrofoil ships in March of 2015 at a cost of $28,144.  Next summer may seem like a long time away, but this little floating fragment of future is something fun to look forward to.

We can't all have spaceships.  But lakeships?  There you go.
(Image courtesy theawesomer.com.)

Score Scorchy Selfies With New Thermal-Imaging Smartphone Camera

What new photo tool brings the real hotness for your smartphone?  Literally?  How about your own personal thermal imaging camera?

According to redferret.net, the Seek Thermal Imaging Camera is a new iPhone and Android-operable device that turns your smartphone into something like you'd spot in a cool spy movie.  Thermal imaging cameras, which use infrared technology to sense the presence of heat, make any temperature-producing item visible, regardless of lighting conditions.  Ninjas hiding in your house at night?  Not anymore, you spotted them with Seek!

Your evil black cat may resent his fresh lack of hiding skills.
(Image courtesy NASA.gov.)

The Seek can detect heat signatures at up to 1,000 feet, recognize more resolutely at 250 feet, and identify specifics at 150 feet.  As their product description explains, "Our eyes rely on light to see, Seek Thermal relies on heat."  It has a spectrum from -40 degrees to 330 degrees Celsius, so you can just as easily determine if your drink is acceptably ice-cold as you can gauge how well-done your burgers are.

Your pet penguins can be kept suitably chill thanks to infrared analysis.
(Image courtesy boingboing.net.)

For $199, the 8-ounce, micro-USB-enabled Seek can capture all the hotness (or coolness) around you.  It's the same technology that NASA uses to spot space phenomena, surely you too can come up with some interesting experiments!  Besides, wasn't that sepia filter starting to get boring anyway?


AAHHHH, FLAMETHROWER ATTACK!  Oh no, just a hairdryer in infrared.
(Image courtesy NASA.gov.)




Does Mario Dream Of Electric Sheep? Nintendo To Create Sleep-Monitoring Device

Do you wake up sometimes wondering if you're just unhappy to be headed to work, or if you're actually experiencing sleep deprivation?  Do you wonder about how your sleep cycles are affected by various activities you may be hitting up before you hit the sack?  Soon, a device made by (stop laughing) Nintendo will be able to help you determine how healthy your sleep patterns are.

According to techlandra.com, Nintendo's president, Satoru Iwata, isn't just talking about a novelty invention.  This is a whole new means of categorizing a previously-unquantified issue that affects every human on earth.  "Since fatigue per se is not regarded as a disease in the medical world, it is said to be a field where sufficient research has yet to be conducted," Iwata said. "We have been fortunate to encounter several experts who have been conducting cutting-edge research in the science of fatigue. Together, we are now developing technology to estimate fatigue."

Optional dream-controlling hopefully to follow.
(Image courtesy uberreview.com.)

The device, as reported by Reuters, is as of yet unnamed but is planned to debut in 2015.  Developed in conjunction with the medical device company ResMed, the sleep-assessment system will be small enough to easily sit on your nightstand.  Using microwave sensors that do not come into contact with the body, the quality and length of sleep cycles are tracked and then sent to attendant apps for analysis.

This creation is part of Nintendo's new "Quality Of Life" initiative, which according to gamesindustry.biz seeks to "improve peoples' quality of life in enjoyable ways."  The new sleeping device will abide by five simple principles:  it need not be worn by the user, it need not touch the user at all, it need not be booted up by the user to begin working (it assesses things like body movement, heartbeat and breathing autonomously to determine sleep cycles), it provides data immediately, and it requires no complicated setup.

In other words, it's as easy as falling asleep!  And if you can't even do that right, Nintendo's new machine can help you.

If you get a good night's sleep, maybe you can work your way up to Player 1 status.
(Image courtesy builttoplay.ca.)

Shine On, Mine On: Solar And Wind Power Make Electricity 70% Cheaper For Mining


The clean energy revolution could stand to gain many supporters when it's proven to work effectively for big business.  Now, the mining industry is looking towards alternative energy to fuel their pursuits, with some interesting and prosperous results.

As reported by cleantechnica.com, renewable solar and wind power is up to 70% more cost-effective for the mining industry than diesel fuel - a startling revelation.  With many remote mining areas amenable to wind and unhindered sunlight,  as well as factoring in the cost of NOT having to truck fuel out to the far-flung sites, the benefits of going green begin to add up considerably.

Dig this:  it's a bright future thanks to solar power (and other renewables.)
(Image courtesy energymanagertoday.com.)

One Australian mining site uses solar power to the tune of offsetting some 600,000 gallons of diesel fuel.  Another Alabama steel mill is run mainly on solar power, and one of the world's preeminent copper mining companies is set to follow suit with a 70 MW solar array.  It's not just for hippies anymore.  If the metal crews are into it, what's to stop the rest of society?

For those who would be interested in arming their business with the might of the sun, there exists an online aggregator of clean tech called Renewables And Mining.  It contains information on "Photovoltaics, concentrated photovoltaics, concentrated solar power, solar thermal, and wind power" for comparison to assess what might work best for a particular type of industrial site.  Why spend tons when you can invest in the sun?  For those who work at removing some of the precious things the environment has to offer, why not harness a similar energy for the harvesting itself?

Even old mines can get in on the usefulness!
(Image courtesy spiegel.de.)

The Brewer Of The Future: App-Controlled Coffee Machine To Brew For You

Do you ever have one of those days when it's so hard to get out of bed you just wish Dunkin' Donuts or Starbucks would deliver coffee straight to you?  Hate getting up, even though it's the only way you'll get your delicious coffee a'roasting?  Now, a new invention may make it easier to lure you to the land of the living with the scent of freshly-brewed coffee, just the way you like it.  All it takes is this fancy new coffee machine and the attendant app!

According to engadget.com, the Bruvelo is a new high-end coffee maker currently under development with kickstarter.  Not just a simple mud-slinger, the Bruvelo operates by app to grind beans to your specs, mix them with your preferred ratio of in-machine filtered water, and deliver a beautifully-brewed cup after cooking to precisely 199 degrees Fahrenheit.  All you have to do is hit a few icons on your smartphone, presumably the ones immediately after your fifth swipe at the snooze button.

This machine is way more capable of complex tasks in the morning than you are.  Let it handle things.
(Image courtesy crowdfundinsider.com.)


Brew strength can be programmed into the caffeine computer, or decided from your preconfigured "flavor profiles" of Robust, Balanced, or Delicate (hahaha, that's adorable.  Hurry up with a custom Double Robust, coffee robot.)  All you need to do is remember to leave your mug under the nozzle the night before, and you can be a barista from your bed.  Voila!  Your good day is merely a stagger to the kitchen away.

Bruvelo needs $150,000 on kickstarter to make this caffeine dream a reality.  If you pledge $300, your sweet dreams could be waking up to brewed beans by as early as next June.  A little computerized coffee concierge seems like a good start to the next level of the future.

Now if only technology can get the mug to walk to your bedside...
(Image courtesy jayce-o.blogspot.com.)


Space Station Sunday: Happy Anniversary (Don't Mind The Mishap!)

Happy Anniversary, ISS!  Fourteen years ago today, Expedition 1's Commander William Shepherd and Flight Engineers Sergei Krikalev and Yuri Gidzenko docked to the space station (then only 3 modules large) after flying up in a Soyuz TM-31 spacecraft.  The crew pioneered admirably upon the first phases of the orbital lab, and returned home aboard space shuttle Discovery after nearly 141 days in space.  Nearly a decade and a half later, their early endeavors have paved the way for more superb science, after initiating operations on humanity's longest manned outpost in orbit.

Cosmonaut Yuri P. Gidzenko, astronaut William M. Shepherd and cosmonaut Sergei K. Krikalev, the first in a long line of humans to play with their food aboard the ISS.
(Image courtesy NASA.gov.)

Unfortunately, even well-wrought science has mishaps, as evidenced in the explosion of the Cygnus resupply spacecraft aboard an Antares rocket on Tuesday.  While Orbital Science Corp., the commissioned creators of the spacecraft, are still examining the cause for the malfunction, Russia Today reported that the rocket was voluntarily detonated when an anomaly-sensing self-destruct trigger went off to assure that further trouble would not ensue were it to reach a higher altitude.  The Antares had previously completed three trips as a cargo craft to the ISS.

According to techtimes.com, a variety of science experiments selected as winners from over 1500 student groups were among the items lost in the explosion, including "red worms from Oakland, houseflies from San Marino, chrysanthemum seeds from Washington, D.C., soybean seeds from Louisiana, mosquito eggs from New Jersey, and Dry Lake fairy shrimps from Kalamazoo."  Several pieces of NASA hardware, including a meteor tracker and an array of miniature satellites, were also lost.


Everything is more extreme in rocket science.
(Image courtesy facebook.com.)


Thankfully, a Russian cargo ship, Progress 57, arrived on Wednesday, ferrying up nearly 3 tons of cargo.  Although the Progress 57 mission was a great boost to the ISS supply chain, the Antares accident will not stop American spacecraft from making ISS deliveries.  According to a statement made by NASA, William Gerstenmaier, associate administrator of NASA’s Human Exploration and Operations Directorate explained, "Launching rockets is an incredibly difficult undertaking, and we learn from each success and each setback. Today's launch attempt will not deter us from our work to expand our already successful capability to launch cargo from American shores to the International Space Station.”

Speaking of cargo, some of the most important elements of the ISS are due for an update. Namely, the astronauts themselves. A fresh ISS crew will arrive on November 23rd after a launch from Baikonur, Kazahkstan. They will be replacing German astronaut Alexander Gerst, American astronaut Reid Wiseman, and Russian cosmonaut Max Suraev, who will all be heading home on November 9th. American astronaut Butch Wilmore as well as Russian cosmonauts Alexander Samokutyaev and Yelena Serova will remain aboard to continue their mission.


Wiseman (the Jack O' Lantern) and Gerst (R) have celebrated their final major holiday on the ISS.
(Image courtesy NASA.gov.)





Until next week, stay safe on the ground, air, or orbit, and watch this space!