Optional Value In Swift

An optional provides a variable that can be assigned to contain a value, or left or assigned as nil. The pattern below creates and optional variable (note the ?), assigns it a value, then checks if that value has been assigned.

[c collapse=”False”]
//create optional
var optionalName: String?
//assign value
optionalName = "Billy"
// check for value
if let name = optionalName {
greeting = "Hello, \(name)"
}
[/c]

Recursion in Swift

Recursion is when a method or function calls itself.

[c collapse=”False”]
//depending on what number you give to N, the function will call itself that many times, subtracting 1 from the original N each time through to pass as an argument.

func thisFunctionCallsItself(thisManyTimes: Int) {

//The next few lines are to set up the proper suffix on the printed result string
var mySuffix = String()
//let’s get the last two digits from thisManyTimes
let lastTwoDigits = thisManyTimes % 100
switch lastTwoDigits {
case 10…20:
mySuffix = "th"
default:
//get the last digit
let lastDigit = thisManyTimes % 10
switch lastDigit {
case 1:
mySuffix = "st"
case 2:
mySuffix = "nd"
case 3:
mySuffix = "rd"
default:
mySuffix = "th"
}
}
//OK that it.

//below is where the function calls itself
if thisManyTimes != 0 {
thisFunctionCallsItself (thisManyTimes – 1)
print("This is the \(thisManyTimes)\(mySuffix) time that this function has called itself.")
}

}

//call the function.

thisFunctionCallsItself(10)

[/c]

Fire and Ice, documentary created with EPYX Productions

Siemens Energy Channel presents
“Fire and Ice”
(Fossil Power Documentary)

Documentary film shot in Bangkok Thailand.

I was DP on this one.

This documentary produced for Siemens is about power distribution in Thailand. The story is told by following electrical power from it’s source generated at a Siemens equiped plant, to the end users at an ice factory and fish market.

Music Videos produced in Bangkok

A couple of music videos produced with EPYX Productions. I did the photography and VFX.

Music videos produced in Bangkok, Thailand. Hong Hoon was created to support the feature horror film Hong Hoon starring Ananda Everingham. Alone was a music video for an up and coming Thai hard rock band called System Sucker.

Why we will be drooling over the new Mac Pro

It looks like something out of a science fiction movie (and apparently it looks a lot like a Japanese trash can too), but the Mac Pro will be a piece of reality in a few months.

new-mac-pro-02

People who love Apple hardware, and use computers for graphics rendering or video will be dying to get their hands on this device. Here are the top five reasons why we will want to see the new Mac Pro on our desktop:

1. The Design. What is it? A coffee grinder? It’s a bit weird for a computer, but increadibly sleek at the same time. It reminds me a bit of the SGI O2, but way cooler. This device will probably be a major iconic design in the Apple’s historical lineup. The current Mac Pro is a beautiful machine, but the new Mac Pro makes the old cheese grater look retro.

2. Power. With up to 12 cores of Xeon 5 processor and 40 GB per second PCIe bandwidth, the new Mac Pro can deliver cpu performance up to 2x the current Mac Pro.

3. Speed. The new Mac Pro will support up to 128GB of ram and feature 60GB per second memory bandwidth, 2x the current bandwidth. The storage is “Next generation PCIe flash storage” that can read/write at 1250MB per second. 20Gb per second thunderbolt expansion ports. Super fast.

3. Graphics. The new Mac Pro will have, standard, two AMD FirePro GPUs with up to 6GB of dedicated VRAM graphics. The machine supports 4k video and up to three 4k displays.

4. Size. It’s like an eighth the size of the current Mac Pro.

Gradients v2.1 is available

Gradients is a photo effects app that allows users to build their own effects with gradient images. Over 40 template effects are included. I think this is a rather unique app. Please check it out. It’s only a buck: Gradients v2.1.

flyerImage03

[button label=”Gradients On The App Store” url=”https://itunes.apple.com/us/app/gradients/id498181349?ls=1&mt=8″ color=”#f05134″ target=”_blank”]

XCode breakpoint tip

Use breakpoints to replace NSLog statements while debugging your code.

Screen Shot 2013-05-09 at 9.08.49 AM

Steps:

1. Add a break point.
2. Hold option + command and click the break point to edit it.
3. Tap the add action button.
3. Add an action or expression like below.

LLDB (debugger) action
[c collapse=”False”]
po myVar
[/c]

Expression
[c collapse=”False”]
expr (void)NSLog(@"myVar = %d", myVar)
[/c]

Select “Automatically continue after evaluating” to continue without stopping the code.

Advantages:

1. Easier to manage: e.g. you can view all the breakpoint and more in the breakpoint navigator (second button from the right in the navigator pane).

2. You can edit the actions or expressions, or add breakpoints while the code is running.

Source: 2012 WWDC video: Debugging in XCode. Much more information in this video.