Going from Apple to Raspberry Pi

I got a new toy this week at work:  A Raspberry Pi.

Raspi

It’s a small computer the size of a mint tin that costs about $35. I comes just as a board, but I invested in a nice case for it. Instead of a hard drive you  use a SD card for storage of the operating system and you main drive.  My aim is to use it as a controller for other devices.  As you can see on the upper left of the board in the photo, there is a set of pins called the GPIO, (General Purpose Input/output) which you can connect directly to and control or sense stuff from. The programming language directly controls these pins. You can then programmatically  make the pins either input or output.

I got it up and running on Friday, and Monday I’ll start to do some stuff with it. However, the  primary programming language is far from Xcode. Instead, it’s Python.

Python is different. It’s dynamically typed so no declaring variables. It’s also interpreted, so no compiling and building. It’s also a lot more universal.  I even have it running on my iPad.

And looking at some books I bought on Python and Raspberry Pi, there is some things I need to wrap my head around between Raspberry Pi and Xcode.

I’ll post some of those this week.

 

Keeping things short.

I have a problem. I write too much. 

It’s not a new problem. In graduate school the words “This is not a dissertation” was found next to the grade on any paper I wrote.  While professors might dread reading 100 page papers, I usually ended up with A’s since I was immensely complete and still compact with my writing. My problem is  I plan big projects,  and want to finish the project before I present it.

I just finished Show Your Work!: 10 Ways to Share Your Creativity and Get Discovered by Austin Kleon and it got me thinking about this problem. Kleon’s Tip #3 was “share something small every day,” which I neither share small or everyday.  He points to my problem of not posting with this encouragement:

We’re all terrified of being revealed as amateurs, but in fact today it is the amateur the enthusiast who pursues her work in the spirit of love(in french the word means “lover”), regardless of the potential for fame, money, or career — who often has the advantage over the professional.

I write for grad school or a finished read-to publish book.  When I was writing Shlomo’s Drash in its heyday, it was almost always over 1100 words. It’s just a blog post.  Blogs are short, small sharings. If they are more human, even better.

So I’m giving myself a 300-word limit. but I will post content every day. I have two projects on the burners, and both are very easily posted here.

Time to start the adventure. Time to keep it going.

(Word count: 258)

 

The Making App Pie Tutorial: The Adventure Begins

I’ve been at Xcode and cocoa Touch for over a year. I’ve had over  1,400 downloads of my apps from the app store and learned a lot about programming in Xcode.

I’ve realized something during this time: Programming in OOP is not like programming in C or Basic. When you have a graphic environment like Xcode, with storyboards to help you, the entire game if different, and it’s more about the rules you unlearn than learn as a programmer.

So I asked myself a question: What if someone who knows enough to handle Microsoft Word  or Pages would be taught Xcode from the ground up?

So we begin an adventure the Making App Pie tutorials will be regularly posted tutorials on how to make apps for the iPhone at first , and eventually the iPad as well.

You will need the following to play along at home:

  • The latest version of Xcode
  • A Macintosh computer ( since Xcode only runs on a mac)
  • A Developer’s license. There are two varieties of these, the free one and the $99/yr one. The big difference is the paid license lets you put your apps on a real phone, the free one restricts you to the simulator. I strongly suggest getting the paid developer’s license, but it will be months before we will do anything the requires you to upload an app to a phone. You can begin the registration process here: https://developer.apple.com/register/index.action

What we will do over the course is create an adventure game. The idea of this game is to learn Xcode, not to write games. Those of you interested in productivity apps will learn the fundamentals for those types of apps as well. Some of the parts of this adventure will be components for many types of non-game apps. I’m just making a conceptual framework that will help everyone think correctly about Object Oriented Programming.

Hope you join me in a great adventure.

 

 

 

 

How to get a string with the Date and time in XCode / Cocoa Touch

There are times  you look for something simple, and get very frustrated. One of those for me was getting a freaking time stamp on my app.

After a bit of chasing around, I did find this in Apple’s documentation, in case you are looking for it.

// code to get the date and time  in a string.
    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
    [dateFormatter setDateStyle:NSDateFormatterMediumStyle];
    [dateFormatter setTimeStyle:NSDateFormatterMediumStyle];
    NSDate *date = [NSDate date];
    NSString *formattedDateString = [dateFormatter stringFromDate:date];

Note there are other constant you can use besides NSDateMediumStyle.

Check out the NSDateFormatter Class Reference for the whole story

And Another thing: Zero Parameters

So I keep forgetting how to convert from NSString to values. there is a series of methods defined in the NSstring class to do this, such as intValue and floatValue. I keep thinking this backwards, getting confused on a case where there is no parameters in a message. the data is already part of the object.

I keep thinking of something long the lines of

int intensityValue = sender.titleLabel.text.intValue();

when it really is:

int intensityValue = [sender.titleLabel.text intValue];

No colon or indication of parameter, even empty parameter.

Gotta remember this.

Hello world!

Like everything in the programming community, It’s important to start with a “hello World”  program, or in this case a post.

So here I go, Posting stuff.

This is not you normal advice blog for app developers.  There is a lot of more knowledgeable ones, like Stackoverflow.com for that.

I started programming with a brand spanking new TRS-80 with a whopping 4K of memory,  and have learned many programming languages in the time since then. I’m bewildered by this wonderful thing called app development, even though it’s dream programming to me.

So I’m learning the Xcode 4 thing with iOS 5.1.  Though blundering along is more like it.

I’m learning a lot like I make pies, I find a pie shell, stick some ingredients in and see what happens. Sometimes I get delicious pie. Sometime pie on my face.

You find the same thing here, as I problem solve my way to creating apps.

Bass ackwards with Objective C.

It drives me nuts, thinking backwards.

in Java or C++ or C, functions and methods are simple. They’re close to what I did in Pascal a quarter century ago:

public int sampleMethod(int y){
//statements go here
return y;
}

and then the call would be

a=sampleMethod(5);

No biggie. If sampleMethod was in a an object I was calling,

a= theObject.samplemethod(5);

But Objective C turned things around. Definitions are simple enough for single parameters:

- (int) SampleMethod:(int) y {
//statements go here
}

but the sending a message looks so different:

a=[theObject samplemethod: 5];

I get confused.  when you have something with multiple parameters in it like

-(void) fillCircleAtPoint:(CGPoint)p withRadius:(CGFloat)radius inContext:(CGContextRef) context{ //stuff here

}

and sending a message to

[self   fillCircleAtPoint:p withRadius:radius*0.5 inContext:context];

it just seems wrong. The withRadius: and inContext: just seem wrong.

They aren’t of course, and it does add to readability.

I get stuck with remembering which object I’m sending a message to, and those funky multiple parameter methods with the extra bits.

I’m silly I’m sure, but it is a paradigm change for me, And I’m guessing someone who will eventually read this.

See you are not the only silly person out there.

Adventures in Swift and iOS App Development