Categories
Florida Tampa Bay

Tonight at Tampa Bay Startup Week: The Star Wars / Iron Yard Hour of Code!

rey and bb-8
iron yard logo

Tonight, as part of Tampa Bay Startup Week, Anitra and I will be helping the people from the coding school The Iron Yard Tampa Bay with their Hour of Code event! It’s an hour-long training session where kids ages 8 – 12 and teens ages 13 – 17 can get a quick, fun introduction to coding with the help of Rey and BB-8 from The Force Awakens and Princess Leia and R2-D2 from the original trilogy.

Here’s a quick video intro to what the Star Wars Hour of Code’s all about, courtesy of Star Wars: The Force Awakens’ producer Kathleen Kennedy and Rachel Rose, lead engineer for Star Wars’ animation and creature development team…

The programming interface that Hour of Code participants use is delightfully simple and fun. They drag and drop “blocks”, which represent calls to functions, to move the droid characters like BB-8 and R2-D2 around, arrange them into sequences which function as programs, and then click the “Run” button to see if their code worked.

It starts off with the simple task of moving BB-8 towards a single piece of scrap metal:

star wars code 01

Click the screenshot to see it at full size.

…but about a dozen lessons later, you’re writing considerably more complex stuff that includes concepts like variables, branches, and loops, and changing droid characters:

star wars code 02

Click the screenshot to see it at full size.

tampa bay wave

If you can make it to tonight’s Hour of Code…

The event takes place tonight at Tampa Bay WaVE, 500 East Kennedy Boulevard, Suite 300 at 6:30 p.m.

If you’d like to have your kid or teen participate in tonight’s event, go to Tampa Bay Startup Week’s event schedule and sign up for the appropriate event. You’ll need to bring a fully-charged laptop (and it’ll be a good idea to bring its power cord) or tablet with working wifi and browser in order to work on the code. It can run Windows, Mac OS, Linux, iOS, or Android — as long as it’s got a relatively recent browser and can connect wireless to the internet, it’ll work for this class.

If you can’t make it to tonight’s Hour of Code…

…you can still code your way through the galaxy by visiting Code.org’s Star Wars site!

code.org star wars

Have fun, and may The Source be with you!

Categories
Florida Tampa Bay

Tampa iOS Meetup, Tuesday, January 19th: Get started with making iOS games with Sprite Kit!

Poster: Get Your Game On! / Getting started with building iOS games in Sprite Kit / Tampa iOS Meetup - Tuesday, january 19, 2016 -- A hodgepodge of iOS gaming-related imagery.

Happy new year, experienced and aspiring iOS developers in the Tampa Bay area!

If you’ve made a new year’s resolution to take up iOS, Swift, or game development in 2016, the upcoming Tampa iOS Meetup topic might be just what you need to get started. It’s called Get Your Game On: Getting Started with Sprite Kit, and it’s taking place in Tampa next Tuesday, January 19, 2016.

Tampa iOS Meetup banner with photo of Joey deVilla and Angela Don in the background.

Tampa iOS Meetup is a monthly meetup run by local mobile developer/designer Angela Don and Yours Truly. While Tampa has a couple of great iOS developer meetups — Craig Clayton’s Suncoast iOS and Chris Woodard’s Tampa Bay Cocoaheads, we figured that there was room for a third iOS meetup in the Tampa Bay area, and especially one that would stray into other areas of mobile development. So we made one.

Tampa iOS Meetup’s next meetup: Get Your Game On!

Icons of iOS games appearing to leap off the screen of an iPhone.

“Games” is the most popular category in the iOS App Store, accounting for 22.5% of active apps. They’re more than twice as popular as the next-most-popular category, business apps. Look in any place where people are waiting these days — in line at the bank or grocery, at public transit stops and airports, cafes and restaurants — and you’ll see people passing the time with a mobile game. Gaming is a basic human activity — we’ve had them since our earliest days, and we’ve had computer games for almost as long as we’ve had computers.

Despite the fact that games are the most-used type of mobile app, there are far fewer game development tutorials than there are for “standard” apps. That’s a pity, because one of the best ways to learn programming is satisfaction, and there’s nothing more satisfying than seeing a game you created in action. While games can be complex, the concepts behind them are simple, and some of the most popular games are pretty simple as well. Why not try game development as a way to learn programming, Swift, and iOS?

Animated scene showing 'Flappy Bird' gameplay.

Join us next Tuesday, January 19th at the Tampa iOS Meetup and start the new year by getting your game on!

The Details

  • What: Tampa iOS’ Meetup’s “Get Your Game On” session. Please sign up on our Meetup page so we can plan accordingly!
  • When: Tuesday, January 19, 2016, 6:30 p.m. – 9:30 p.m. We’ll have some snacks at 6:30, with the presentation beginning at 7:00.
  • Where: Energy Sense Finance, 3825 Henderson Boulevard (just west of Dale Mabry), Suite 300. See the map below.
  • What to bring: Yourself, but if you’d like to follow along, bring your Macbook and make sure it’s got Xcode 7.2.
  • What to read in advance: If you’re one of those people who likes to do some readings ahead of a presentation, check out the Sprite Kit tutorials on Ray Wenderlich’s site. We’ll be using our own tutorial material, but Ray’s stuff will come in handy.
Categories
Florida Swift Kick Tampa Bay

Share your Swift tips and tricks at this week’s Tampa iOS meetup: Wednesday, November 18!

swift tips and tricks meetup

Hey, Tampa Bay iOS developers — here’s your chance to shine! At the next Tampa iOS Meetup (Wednesday, November 18th at 7:00 p.m.), a monthly gathering run by me and my friend Angela, we’re having a “Swift Tips and Tricks” night, where we’ll take turns sharing tips an tricks that we’ve either discovered on our own or found through others while programming in Swift.

Have you ever wanted to present something at an iOS meetup, but it was on a topic or technique that could easily be covered in ten or even five minutes? Well, this meetup is your chance to be an iOS rock star, as short presentations is what it’s all about! Whether you’ve been building apps since the Objective-C days or picked up Swift a couple of weeks ago, you’ve got knowledge to share with your fellow developers, who in turn have knowledge to share with you! Join us for an evening of demos, information exchange, and that buzz that you get when you’re in a room of smart, interesting people, one of whom is you!

Me and Angela at BarCamp Tampa Bay 2015.

In order to help kick off the event, I’ll start by presenting some tips and tricks that I’ve picked up while working on my own apps, and I’m sure Angela will be doing the same. After that, it’s everyone else! We invite discussions and questions throughout the meetup, as it’s the best way to learn.

Here are the event details:

  • What: Tampa iOS meetup, a new gathering in the area that complements the Suncoast iOS Meetup and Tampa Bay Cocoaheads, both worthwhile gatherings. We want to make sure that if you can’t make one local iOS event, there’ll always be another one in the near future!
  • When: Wednesday, November 18th, from 7:00 p.m. to 9:00 p.m.
  • Where: Energy Sense Finance, located at 3825 Henderson Blvd., Suite 300 (just west of South Dale Mabry)
  • If you have a tip or trick that you’d like to present, let us know! Drop us a line in the comments section at the bottom of our Meetup page or email me at joey@joeydevilla.com. We’ll provide a projector, and if you need one, a Mac to present on.
  • We’ll have provide some snacks and drinks. No idea what they’ll be, but I’ll post details as I found out.
Categories
Florida Swift Kick

Swift programming tip: How to execute a block of code after a specified delay

burning fuse
swift kick

Sometimes, you want some code to execute after a specified delay. For me, this happens often in user interfaces; there are many cases where I want some notification or other interface element to appear and then disappear after a couple of seconds. I used to use an NSTimer to make it happen, but nowadays, I call on a simple method called delay().

Consider the simple “Magic 8-Ball” app design shown below:

magic 8-ball app

The two functional interface items are the Tap me button and a label that displays a random “yes/no/maybe” answer in response to a button tap. The button should be disabled and the answer should remain onscreen for three seconds, after which the app should revert to its initial state, with the button enabled and the answer label blank.

Here’s the action method that responds to the Touch Up Inside event on the “Tap me” button:

@IBAction func buttonClicked(sender: UIButton) { 
  tapMeButton.enabled = false
  predictionLabel.text = randomAnswer()
  delay(3.0) {
    self.tapMeButton.enabled = true
    self.predictionLabel.text = ""
  }
}

Don’t worry too much about the randomAnswer() method; it simply returns a randomly-selected string from an array of possible answers. The really interesting method is delay(), which takes two parameters:

  • A number of seconds that the system should wait before executing a block of code. In this particular case, we want a 3-second delay.
  • The block of code to be executed after the delay. In our block, we want to blank the label and enable the button.

The block of code that we’re passing to delay() is a closure, which means it will be executed outside the current ViewController object, which in turns means that we’ve got to be explicit when capturing variables in the current scope. We can’t just refer to the button and label as tapMeButton and predictionLabel, but by their fully-qualified names, self.tapMeButton and self.predictionLabel.

Here’s the code for delay():

func delay(delay: Double, closure: ()->()) { 
  dispatch_after(
    dispatch_time(
      DISPATCH_TIME_NOW,
      Int64(delay * Double(NSEC_PER_SEC))
    ),
    dispatch_get_main_queue(),
    closure
  )
}

delay() is just a wrapper for dispatch_after(), one of the functions in Grand Central Dispatch, Apple’s library for running concurrent code on multicore processors on iOS and OS X. dispatch_after() takes three parameters:

  • How long the delay should be before executing the block of code should be,
  • the queue on which the block of code should be run, and
  • the block of code to run.

We could’ve simply used dispatch_after(), but it exposes a lot of complexity that we don’t need to deal with. Matt Neuburg, the author of the O’Reilly book iOS 9 Programming Fundamentals with Swift, found that he was using dispatch_after() so often that he wrote delay() as a wrapper to simplify his code. Which would you rather read — this…

dispatch_after(
  dispatch_time(
    DISPATCH_TIME_NOW,
    Int64(3.0 * Double(NSEC_PER_SEC))
  ),
  dispatch_get_main_queue(),
  {
    self.tapMeButton.enabled = true
    self.predictionLabel.text = ""
  }
)

…or this?

delay(3.0) {
  self.tapMeButton.enabled = true
  self.predictionLabel.text = ""
}

Here’s the code for the example “Magic 8-Ball” app, which I’ve put entirely in the view controller for simplicity’s sake:

//
// ViewController.swift
//

import UIKit


class ViewController: UIViewController {

  @IBOutlet weak var tapMeButton: UIButton!
  @IBOutlet weak var predictionLabel: UILabel!
  
  let predictions = [
    "Yes.",
    "Sure thing.",
    "But of course!",
    "I'd bet on it.",
    "AWWW YISSS!",
    "No.",
    "Nuh-uh.",
    "Absolutely not!",
    "I wouldn't bet on it.",
    "HELL NO.",
    "Maybe.",
    "Possibly...",
    "Ask again later.",
    "I can't be certain.",
    "Reply hazy. Try again later."
  ]
  
  override func viewDidLoad() {
    super.viewDidLoad()
    predictionLabel.text = ""
  }

  override func didReceiveMemoryWarning() {
    super.didReceiveMemoryWarning()
    // Dispose of any resources that can be recreated.
  }

  @IBAction func buttonClicked(sender: UIButton) {
    
    // When the "Tap me" button tapped,
    // we want to:
    // 1. Disable the button
    // 2. Display a random magic 8-ball answer
    // 3. Wait 3 seconds, and then:
    //    a) Enable the button
    //    b) Clear the displayed answer
    
    tapMeButton.enabled = false
    predictionLabel.text = randomAnswer()
    delay(3.0) {
      self.tapMeButton.enabled = true
      self.predictionLabel.text = ""
    }
  }
  
  func randomAnswer() -> String {
    return predictions[randomIntUpToButNotIncluding(predictions.count)]
  }
  
}


// MARK: Utility functions

func delay(delay: Double, closure: ()->()) {
  
  // A handy bit of code created by Matt Neuburg, author of a lot of books including
  // iOS Programming Fundamentals with Swift (O'Reilly 2015).
  // See his reply in Stack Overflow for details:
  // http://stackoverflow.com/questions/24034544/dispatch-after-gcd-in-swift/24318861#24318861
  //
  // The secret sauce is Grand Central Dispatch's (GCD) dispatch_after() function.
  // Ray Wenderlich has a good tutorial on GCD at:
  // http://www.raywenderlich.com/79149/grand-central-dispatch-tutorial-swift-part-1
  
  dispatch_after(
    dispatch_time(
      DISPATCH_TIME_NOW,
      Int64(delay * Double(NSEC_PER_SEC))
    ),
    dispatch_get_main_queue(),
    closure
  )
}

func randomIntUpToButNotIncluding(count: Int) -> Int {
  return Int(arc4random_uniform(UInt32(count)))
}

Resources

zip file iconYou can see this code in action by downloading the zipped project files for the demo project, DelayDemo [220K Xcode 7 / Swift 2 project and associated files, zipped].

If you’d like to learn more about coding for concurrency with Grand Central Dispatch, a good starting place is the tutorial on Ray Wenderlich’s site. It’s a two parter; here’s part 1, and here’s part 2.

I found Matt Neuburg’s delay() method in his answer to this Stack Overflow question.

Categories
Florida Tampa Bay

Tampa’s OpenHack Ybor meetup: Tonight at Brass Tap!

openhack ybor - new world

OpenHack Ybor’s August gathering at New World Brewery.
Click the photo to see it at full size.

If you’re in the Tampa area tonight and would like to get to know your fellow developers, show off your current passion project, find out what their passion projects are, and enjoy some pizza and beer (or whatever beverage you like) in a friendly, convivial atmosphere, you might want to come to tonight’s OpenHack Ybor meetup!

openhack ybor - new world 2

Another scene from the meetup at New World Brewery.

OpenHack Ybor, held once a month at one of Ybor City’s many beer-dispensing hangouts, is run by local Ruby developer Tony Winn for software developers of all stripes who want to get to know other local developers, see what they’re up to, and enjoy some free pizza. We’ve already had two OpenHack Ybor meetups — the first at the new pub at Coppertail Brewing, and the second at New World Brewery. Tonight’s meetup, which starts at 6:30, takes place at the Brass Tap in Centro Ybor.

centro ybor

Tonight’s meetup location: Brass Tap in Centro Ybor.

If you’d like to attend, RSVP on OpenHack Ybor’s meetup page (there’s no admission, the pizza is free, you’ll have to buy your own beer) so that Tony’s got an idea of how many will be there and can order pizza accordingly. It’s fun, it’s friendly, and it’s one of my go-to geek events. I’ll be there, and I hope to see you there too!

The article also appears in my personal blog, The Adventures of Accordion Guy in the 21st Century.