Saturday, July 12, 2014

Amazon iOS App Showing Android App in Search Results

Totally feels like a passive aggressive dick move and from a UX standpoint, obviously not what's wanted.

Friday, July 11, 2014

How To Have Xcode Automatically Delete an iOS Simulator Content Folder When Building Your App

Inspired by Matt ConeyBeare's post Programmatically Opening the iOS Simulator Data Directory for Your App, I've written a shell script, with Matt's script as a template, to delete an app's content folder in the iOS simulator with every build. I needed this while testing the content download startup code for an app I'm working on.

To use the script create an Xcode Run Script Build Phase for the target(s) where you want it to run and paste in the following:

Note: Yes
#!/bin/sh
is redundant, but did not want to introduce confusion about what shell.



Thursday, June 26, 2014

Why Does Apple's Swift Use Pascal's Variable Declaration Syntax?

I'm extremely excited about Swift. I’ve read The Swift Programming Language and Using Swift with Cocoa and Objective-C. Both were very well written and explained with clear examples what you can do with Swift, but left out information I'm dying to know: why?

Not why does Swift exist, I think it's pretty obvious that Apple's Objective-C, which along with AppKit dates to 1988, was showing its age. C itself is from the late 60s, early 70s. A language purportedly as fast as C with non-garbage collected but automatic memory management (mostly) and protection against common programmer mistakes has been needed for a while now. No we need the why of Swift's design.


Why was Swift Designed the Way It Is?

That's the missing link for me in both Swift books. Some might argue that explaining why Swift is designed the way it is requires a third book. I would have found it much easier to digest some syntax design if those decisions had been explained inline. Especially when that syntax is largely used from another non-C like language.

For example, Swift uses Pascal's variable declaration syntax, but not its constants declaration syntax.

Why?

Pascal Variables
var one = 1;
var two: Integer = 2;
Swift Variables
var three = 3
var four: Int = 4
Pascal Constants
const five = 5;
const six: Integer = 6;
Swift Constants
let seven = 7
let eight: Integer = 8


Why Happened To Objective-C Without the C?

If the goal was Objective-C without the C, then the up to Xcode 6 Beta 2 Swift syntax seems kind of far way from that. Chris Pietschmann has a good Basic Comparison of C# and Apple Swift Programming Language Syntax. I haven't used C# in a few years, so this was a nice refresher:

C# Variables
var legalAge = 18;
string firstName;

C# Constants
const int legalAge = 18;

Looks a lot more like Objective-C without the C. There is a rough edge there. C# didn't have a var keyword in early versions. So explicitly typed variables start with the type name, not var. Var is only for method local scope implicitly typed variables.

An important idea here is that C# looks an awful lot like C++ without the second +. C++ Intrinsic type variables and constant declaration looks identical to C# (ignoring C++ 2011 additions since it post dates core C#, and C#'s var keyword). The main difference is C# class variables have no pointers.

Here are a few possible versions of an alternative universe variable declaration syntax in Swift following C# and C++, but would sand away the C# var rough edge:

Swift Alt 1
var:String lastName = "Kirk"

//Traditional C constant keyword
const:Int rulesBroken = 4

//A new C like constant keyword whose length matches var
con:Int rulesBroken = 4
Swift Alt 2
var String lastName = "Spock"

//Traditional C constant keyword
const Int rulesBroken = 4 


//A new C like constant keyword whose length matches var
con Int rulesBroken = 4


What I like about these examples is the connection of type with the kind of variable. It makes the code more readable as a sentence to me:

//With type
variable of type String named Kirk

//Without type
variable named Kirk
Instead of Swift's current syntax: 

//With type
variable named Kirk of type String

//Without type
variable named Kirk
I introduced a new constant declaration keyword con anticipating that the use of let was due in part to wanting length matched keywords for variables and constants. I dislike let which reads weird to me in non-declaration cases (more on that in another post) and it's meaning compatible with JavaScript. Perhaps there's a compiler land reason why name:type is better, I don't know because it's not explained.

Maybe there is an across Swift consistency reason for the use of keyword(s) name:type = default


Unified Theory for Swift's Variable Declaration Syntax

Swift & LLVM lead designer Chris Lattner is obviously a C++ wizard since LLVM is written in it. He must also have seen and likely used a lot of C# since he was a Research Intern at Microsoft's Research lab. He didn't adopt C# or slightly modified C++ variable declaration syntax. Why not?
In the absence of an official explanation, I have a theory. Look at function and closure declarations in Swift:

Swift Functions and Closures
//function
func backwards(s1: String, s2: String) -> Bool {
    return s1 > s2
}

//closures
reversed = sort(names, { (s1: String, s2: String) -> Bool in
    return s1 > s2
})
By default all parameters are constants, so let is ommitted. What remains? In the majority case, name: type.

My theory is that Swift uses the Pascal variable declaration syntax to make reading functions and closures with constant parameters easier for people.

At worst, the the function & closure parameter declaration syntax can expand to this keyword(s) name: type. Examples:

//keyword(s) name: type

func fullName(var middleName: String) -> String

func lastName(inout lastName: String) -> String

{ (firstName: String) -> String in return firstName.description }
Contrast with a couple functions in C#

void addReferenceType(SomeRefType refType) {
    // do something
}

void SwapStrings(ref string s1, ref string s2) {
    // The string parameter is passed by reference. 
    // Any changes on parameters will affect the original variables.

    string temp = s1;
    s1 = s2;
    s2 = temp;
    System.Console.WriteLine("Inside the method: {0} {1}", s1, s2);
}
C# can make the position of the parameter name position 2 or 3 after each comma, but can result in some method signatures that are possibly more jagged than Swift.


Why Else Would Swift Use Pascal Variable Declaration Syntax?

If the Pascal variable declaration syntax isn't for the compiler or it really doesn't make functions & closures more readable, I don't know why it was chosen. Personal taste? Just to be different than C#?

Obviously the LLVM and Swift team at Apple are brilliant people. I have immense respect for the amazing work they've been doing to modernize the platform. But it seems like there was a more familiar path from Objective-C to Swift for variable declaration and it wasn't taken. I'd love to know why.

Tuesday, April 15, 2014

Are You Hangry?

Hunger + Angry = Hangry

Nothing brings out Hangry like a vacation. Everyone's eating schedules thrown out, sleep deprived, sunburned and hungover.

Watch out!

Carnival Cruise Ship Can't Handle The Windows XPiration

I don't know why the ship map channel running Windows XP surprises me, but it did this morning:

Friday, April 04, 2014

Xcode 5.1 Expired Provisioning Profile Hidden Feature

In Xcode 5.0.x, you could not delete multiple expired provisioning profiles by multiple selecting the expired profiles. Highly annoying if a development device acquired a ton of these things over years of testing.

In Xcode 5.1, you finally can select multiple expired profiles and delete! Sometimes it really is the little things...

Friday, July 19, 2013

My Friend Jeffrey McManus Suddenly Died on July 5th

On July 5th Jeffrey McManus unexpectedly died. I learned of this devastating news on July 10th through his wife Carole's tear-jerking FAQ about this death posted to her Facebook timeline. I'll never joke again about quitting Facebook, I don't know when I would have found out about Jeff's death living in NJ.

PandoDaily has a fine public write up if you want the immediate details, though I wish they ran with a better picture.

It is literally the least I can do to honor his memory by recounting how he touched my life. I still can't believe I never get to see him again.

Vertigo Software
I met Jeffrey, whom I called Jeff, when we both worked at Vertigo Software. Jeff worked at Vertigo for 5 months in 2003 and he made a lasting impression. We didn't keep in touch much for a long time after he left the company because I wasn't ready for Jeff. He had such an outgoing personality, and at the time I was very much an introvert, that I didn't know how to handle Jeff's joviality. I mistook his playful spirit for a lack of technical seriousness, a blunder of colossal proportions that I've never admitted to anyone. I never stopped keeping tabs on what he was doing since he was always doing interesting stuff.

New York and Potential Opportunities
Jeff came to New York City in August 2006 just when he was starting Platform Associates. We had drinks at the W hotel in Times Square. I hadn't seen Jeff in a few years at that point and wasn't really sure what to expect, but we had a wonderful few hours together filled with Jeff's trademark off color humor and alcohol. Jeff tried to talk me into joining him at Platform Associates, but since I'm more cautious with my career, I had to tell him I couldn't do it. I always admired his ability to come up with new ideas and just go for it.

Twitter
Jeff was one of the people I interacted with the most on Twitter. My wife and I would specifically take a discussion to Twitter just to see what kind of response we would get out of Jeff. I don't think I missed too many opportunities to get in a snarky or slightly subversive comment on whatever Jeff was saying on Twitter. I'll greatly miss Jeff's witticisms.

Tangerine Element
Jeff was the first person I turned to when I wanted advice on launching Tangerine Element. I asked him for help on consulting engagements, search engine optimization, incorporation strategies, you name it. I'm pretty sure during some of the early consulting he gave me template contracts and invoices to look at from Platform Associates to help smooth that process out. Jeff was always giving like that, always quick to help out however he could.

WWDC 2011
Apple's WWDC 2011 was my first time attending the conference. When I mentioned to Jeff I was going, he immediately said we should hang out. I didn't hesitate to say yes.
We ate dinner at a very nice place not to far from Moscone West that I can't remember the name of, but I think that's mostly because Jeff dazzled me with Marriot's The View lounge. Jeff and I were both Star Wars fans and he knew that The View's resemblance to the Emperor's throne room from Return of the Jedi would blow me away. It did. If I'm around Moscone West and someone hasn't been to The View and I know there a Star Wars fan, I make it a point to take them to the Marriot. The views are simply stunning as well.
As usual, Jeff and I talked about his startups and if there was some way I could help out…

CodeLesson
At the end of 2011, I taught Introduction to iOS Programming through CodeLesson.com. This was my first time teaching an actual course on anything. It meant a tremendous amount to me. I taught another session of the class starting in April 2012. Unfortunately the demands of my day job and the amount of work it takes to do an instructor lead course to my standards meant I couldn't schedule a third session.

WWDC 2012
WWDC 2012 was a truncated affair for me. I had to leave on Tuesday night of that week, but Jeff adjusted his schedule so we could still grab dinner. We went to this great place 54 Mint in a night I'll never forget. I was surprised to find us sitting next to a large table of people from Apple, including Michael Jurewitz. I'd just seen a large number of these people up on stage, and @Jury in particular I'd interacted with on Twitter a few times. I thought if I ever wanted to work at Apple, perhaps I'd say hi later.
Jeff and I got deeply into a discussion about the future of CodeLesson.com. Since I had just wrapped up the second session of my course, I was overflowing with ideas on what to do with the site and take it to mobile. Jeff had just proposed bringing me onto CodeLesson in a product advisor role in my spare time when all of a sudden he gets up, steps towards Apple's table, and makes a fake big smile and waves his hands.
Flabbergasted by what I'd just saw, Jeff sits back down and chuckles as I ask him what he'd done. This was my introduction to the photobombing. Jeff said he did it all the time and all involved got a great laugh out of it. I'd never heard let alone done that so I emailed @jury at the airport to apologize. Don't know if that email was ever read, but this was the only time Jeff and I truly disagreed on anything.
This incident epitomized Jeff. With him you never knew what you were going to get, and that's one of the reasons these outings where so exciting!

WWDC 2013
I had the pleasure of hanging out with Jeff and his wife Carole before the conference at the Pi Bar for pizza and beer. I met a few of Jeff and Carole's friends and we chatted about potential iOS work, schools in San Francisco, and places to live. I was given a mission by @missionbride,  gather intel for "Operation: Could We Possibly Move the Family Back to CA". Jeff and Carole helpfully answered all the questions I had. Mission Bride and I aren't planning for an imminent move, just feeling it out a bit.
Jeff came out the next night with my co-workers and former co-workers. We stopped at the Xamarin party held at the Press Club, then dinner at Annabelle's Bar & Bistro before heading to Marriot's The View. Jeff staged a boisterous game of "Who's Your Top 5". If you've never played, this is a game of "who would you cheat on your spouse for just one night with". Again, this was classic Jeff, taking an off color concept and truly relishing it! When Jeff and I were saying our goodbyes, I gave him a bear hug and told him how proud I was of all the weight he'd lost in the last year.
Mission Bride was coming to San Francisco a couple days later. Jeff magnanimously offered to share his Father's Day the coming Sunday and show us around neighborhoods Carole and he thought might be good for us. I had every intention of taking him up on the offer when traffic intervened and prevented us from getting back from a jaunt down to Salinas in time for our flight home. In hindsight I'm glad we missed it. Carole and the kids got Jeff to themselves as far as I know on his last Father's Day.

Conclusion
Jeff was a talented entrepreneur, great dad, great husband, and a good friend to me. It feels so cliché, but I wish I had more time with him. I'm sure we would have been great friends.

Thursday, February 21, 2013

The Still Handy C Language Cheat Sheet

I got this in college to deal with writing C game code on a Solaris box using something called World ToolKit.

How I Couldn't Recover Deleted Videos & an iMovie Project from iPhone Backups

I finally downloaded iMovie and started editing some video on my phone. I usually don't have time to sit down at my iMac for an editing session, but I do usually want to string a few clips together with titles. iMovie iOS seems to work well for that.
There is, however, a catch. Somehow I got the notion that iMovie copied clips into itself, not used them directly from the Photo roll. When I went to export to the Photo roll, I was out of space on my 16 GB iPhone. So I deleted the source video clips and boom, iMovie could no longer find the videos, prompting this:
Since the first iPhone in 2007, I've never accidentally deleted a video or photo. I've also been meticulous about backups. Since iCloud backups and Photo Stream in iOS 5, I am syncing photos and videos manually less and less frequently to the iMac. When I tweeted the above, I had no idea I would totally fail to get both the videos and iMovie project back together. Here's what happened.
Plan A
The plan seems simple, restore from backup right? iCloud makes this super easy. Here's what I had to work with:
  • iPhone 5 with iMovie project but no videos
  • iCloud backup with videos but no iMovie project
If iOS had Time Machine, or even Trash of some kind, this would have been really simple and I hope iOS 7 has something more granular than full device restore. Heck, even if videos were added to Photo Stream I wouldn't have had a problem. But we aren't there yet. I thought I'd:
  1. Restore iCloud backup onto an iPhone 4
  2. Email video clips to myself to get them onto iPhone 5
  3. Sync clips to iMac just in case something else goes wrong
  4. Finished exported from iMovie
This immediately goes wrong when I restored an iPhone 5 backup onto the iPhone 4.
iOS Won't Restore Photos & Videos from an iPhone 5 backup to iPhone 4
I've done a decent number of iCloud restores to move devices around amongst family members. It works great, I've never seen it fail. So at first when I restored the iPhone 4 from iPhone 5 and there were no videos, I thought it was either just taking a while to copy all the data back or for the first time it had simply failed.
So what do you in tech do if something doesn't work the first time? Like Sisyphus you do it again, and I did. Another round through restoring the device to factory and restoring from iCloud ended with the same result. I babysat it this time, and saw an alert like some items could not be restored blah blah blah. I was too annoyed to record the entire message and had sussed out what was happening. I had thought this might be a possibility because photos and videos from iPhone 5 are much higher quality, maybe even beyond the performance capabilities of the hardware. So I had to try this from a different angle.
Plan B
The only way to get the videos back was to restore from iCloud to the iPhone 5:
  1. Backup iPhone 5 using iTunes to preserve iMovie project
  2. Restore iPhone 5 from iCloud to get the videos back
  3. Extract the videos from iCloud backup
  4. Restore iPhone 5 to iTunes backup
  5. Deposit videos on iPhone 5's photo roll
  6. Hope the iMovie project isn't busted
I only got to Step 3 before blowing it. On Step 4, iTunes offers to backup the phone before restoring it. Seems like a perfectly smart and safe decision to make with one crucial exception: this backup overwrote my good backup with the iMovie project. I hesitated on the checkbox to backup before restore, knowing I shouldn't check it, but wanting the safety net in case something went wrong.
I knew I had seen iTunes offer me the choice to restore from multiple backups of the same device before, so I trusted it would be so here. It wasn't, iTunes overwrote it's last backup ending my dreams of recovering my iMovie project.
Post-Mortem
  • I could have avoided losing the iMovie project if I had added Step 0 to Plan B and synced the project to the iMac using iTunes.
  • I could have previously imported the videos to the iMac using iPhoto and avoid either Plan A or Plan B.
  • A friend suggested undelete software. I did not consider that option until after I overwrote the iPhone in Plan B.
iCloud backups are great and probably save most people from catastrophic mistakes, but I really look forward to a more granular accidental deletion recovery mechanism, hopefully in iOS 7. Actually surprised now that I'm thinking about it that one of the original Mac's great innovations, Trash, doesn't exist in some form on iOS.

Wednesday, February 20, 2013

On Seeing Hard R 80's Movie "Lifeforce" As A Pre-Teen & the Blu-ray Release


"Lifeforce PosterLifeforce" was released June 21, 1985 in the USA. I was 10 years old that summer. My family went to the movies nearly every week, but we skipped that one. I can't be sure if it was VHS or HBO, but one Saturday my dad puts on "Lifeforce". I was 10, 11, or at the latest 12. I'll never forget the craziness that showed up on the Zenith tube TV when that flick started.

If you know "Lifeforce", you might think: "That is about as hard R rated as just about anything in the 80s, what the hell where your parents doing letting you watch that?!?"
That is my dad. My mom was always asleep when he put this kind of stuff on. I must conclude that he just didn't care about the ratings. I've asked him several times, and he just laughs. I saw "Aliens" in 1986 at the Movie City 5 theater in Woodbridge, NJ. I was 11, my brother was 8.5! I remember waiting in line and being in the theater more clearly than I usually remember today.

"Lifeforce" formed an equally monumental memory. I believe it was the first time I had seen a woman completely nude. When Mathilda May appears on screen, I remember looking at my dad shocked like I had just seen one of the secrets of the universe. He made mock big eyes, smiled, and we just kept on watching! I only now realize that she is only 10 years older than me. She was most likely 19 when they shot the film. If you told pre-teen me that she was still a teen, my puddle of jelly brain would have imploded.

I was vividly reminded of this because Roger Ebert has a long review, an essay really, of the film because it is being released on Blu-ray April 30, 2013. If none of that persuades you to take a gander at this hidden gem, then perhaps the presence of Sir Patrick Stewart in the cast will.

By the way dad, I'm glad you ignored the ratings. I love you! I'll try to closely follow your movie showing examples, but I don't know if I will let my oldest son watch this pre-teen. It will be on his must see list sooner rather than later…