Wednesday, December 23, 2015

Command Line Tag Cloud ~ 12/23/2015

created at TagCrowd.com

Sunday, November 29, 2015

Command Line Tag Cloud :: 11/29/2015

created at TagCrowd.com

Friday, November 27, 2015

Introducing Command Line Tag Clouds

It's late so I'll write the introduction another time. All you get tonight is the first tag cloud of my command line history for the past 24 hours. I think it says a lot...
created at TagCrowd.com

Saturday, April 11, 2015

Programmatically Creating an iOS Swift Based UITableView and Supporting Detail View



This is a quick tutorial on how to create an iOS Swift based UITableView and supporting detail view. I will also point out mistakes I made along the way and the errors that I came across. I hope that at least one other person in this tiny world of ours finds this blog and is able to avoid the common pitfalls that come with trying to learn something new.

Part 1: Creating the UITableView controller and populating its cells with data from a webservice.

Setting up the app

  1. Create a new Single Page Application 
  2. Delete Story Board
  3. Delete ViewController.swift file 
  4. Delete Main from General 


Programmatically Create View 

  1. Create new cocoa class > File > New > Cocoa Class
    1. Change class from NSObject to UITableView 
    2. Don't select "create xib" 
    3. Make sure language is "Swift" 
    4. Name the file EventsViewController
  2. Open AppDelegate.swift and add the following lines of code:
 //  
 // AppDelegate.swift  
 // BlogPostiOSUITABLEVIEW  
 //  
 // Created by Michael Droz on 11/28/14.  
 // Copyright (c) 2014 Michael Droz. All rights reserved.  
 //  
 import UIKit  
 @UIApplicationMain  
 class AppDelegate: UIResponder, UIApplicationDelegate {  
   var window: UIWindow?  
   func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {  
     // Override point for customization after application launch.  
     window = UIWindow(frame: UIScreen.mainScreen().bounds)  
     //Create an EventsViewController  
     let evc = EventsViewController(style: .Plain)  
     //create an instance of UINavigationController  
     let navController = UINavigationController(rootViewController: evc)  
     //place nav controller's view in the window hierarchy  
     window!.rootViewController = navController  
     //can I delete these two lines?   
     window!.backgroundColor = UIColor.whiteColor()  
     window!.makeKeyAndVisible()  
     return true  
   }  
   func applicationWillResignActive(application: UIApplication) {  
     // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.  
     // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.  
   }  
   func applicationDidEnterBackground(application: UIApplication) {  
     // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.  
     // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.  
   }  
   func applicationWillEnterForeground(application: UIApplication) {  
     // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.  
   }  
   func applicationDidBecomeActive(application: UIApplication) {  
     // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.  
   }  
   func applicationWillTerminate(application: UIApplication) {  
     // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.  
   }  
 }  



How to add audio to a Swift based iOS app


Setting up the app
  • Create a new Single Page Application 
  • Open the ViewController.swift file
  • Add the AVFoundation module to your import statements
Initiate the player 
  • var audioPlayer:AVAudioPlayer!
Get a handle on the file path 
  • if var filePath = NSBundle.mainBundle().pathForResource("file_name", ofType: "mp3"){ }
Convert filepath String data type to NSURL data type 
  • var filePathUrl = NSURL.fileURLWithPath(filePath)
  • Implement playback controls 
    • audioPlayer.stop()
    • audioPlayer.rate = 0.5
    • audioPlayer.currentTime = 0.0
    • audioPlayer.play()

    The following code is a concrete working example of the AVFoundation module that I implement as part of Udacity's iOS Nanodegree program.
     //  
     // PlaySoundsViewController.swift
     // Pitch Perfect 
     //  
     // Created by Michael Droz on 4/11/15.  
     // Copyright (c) 2014 Benefakter Apps by Michael Droz. All rights reserved.  
     // 
    
    import UIKit
    import AVFoundation
    
    class PlaySoundsViewController: UIViewController {
        
        var audioPlayer:AVAudioPlayer!
        
        @IBOutlet weak var stopButton: UIButton!
        
        
        override func viewDidLoad() {
            super.viewDidLoad()
            
            stopButton.enabled = false
            //get handle on audio file
            if var filePath = NSBundle.mainBundle().pathForResource("movie_quote", ofType: "mp3"){
                var filePathUrl = NSURL.fileURLWithPath(filePath)
                audioPlayer = AVAudioPlayer(contentsOfURL: filePathUrl, error: nil)
                audioPlayer.enableRate = true
                
            }else {
                println("error retrieving file path")
            }
                }
        
        @IBAction func playSlowAudio(sender: UIButton) {
            audioPlayer.stop()
            audioPlayer.rate = 0.5
            audioPlayer.currentTime = 0.0
            audioPlayer.play()
            stopButton.enabled = true
            
        }
        
        @IBAction func playFastAudio(sender: UIButton) {
            audioPlayer.stop()
            audioPlayer.rate = 1.5
            audioPlayer.currentTime = 0.0
            audioPlayer.play()
            stopButton.enabled = true
        }
        
        @IBAction func stopPlayingAudio(sender: UIButton) {
            
            audioPlayer.stop()
            stopButton.enabled = false
        }
        
        
            }