Friday, December 4, 2009

Time Machine

Pesky backups can be a real drag! Not with Apple's Time Machine!





Wednesday, December 2, 2009

eSata

So I have a MacBook Pro (which I love). It has an eSata socket (its hidden behind a silver door on the side of the MacBook Pro.

Here's what I did:

  1. borrowed an eSata connector
  2. Purchased a 1TB SATA Drive (Frys $90)
  3. Purchased a NexStar 3 External 3.5" Hard Drive Enclosure eSata & USB 2.0 Interface (SWS Electronics $48.65)
  4. Installed the new SATA drive in the new Enclosure
  5. Connected the cable from the eSata connector to the enclosure eSata connector
  6. The MacBook Pro recognized an attached device and prompted me to initialize it.
  7. Chose a 2 Partition setup (TimeMachine 500G and Funky500G)
  8. Started Time Machine and selected the TimeMachine 500G partition.
  9. Time Machine begins backing up the drive...looks like it will be a long wait.










iPhone and Radiology / PACS viewing

iPhone and Radiology / PACS viewing

Thursday, September 17, 2009

Check out CUBIQ

HERE

Great source for iPhone-related web-development

Monday, August 10, 2009

iPhone App Icons 57x57



That's right fans, icons to be presented on the launch screen should be square and there is no need to add the Reflective Gloss.

iPhone OS will automatically round the corners and add reflective gloss.

See HERE.

iPhone User Guidelines




NIB files



The are files with .xib extension. They used to be .nib, but now they are written in XML so the extension was changed to .xib.

Manipulated with the Interface Builder application

Got V (view) think IB (interface builder)
  • Used to layout components on view
  • adds controller objects
  • Also connects the controller and the UI

Views built in Interface builder
Controllers can be in Interface Builder or in Xcode

Draw arrows from instance variables in controller to components in the UI
Also drag arrows from UI components to different methods in the Controller

After the NIB has been loaded by the application all elements that have a awakeFromNib() method are invoked. From here you can do any customization you want to do as part of initialization. NOTE: these are only those objects that were created from a NIB archive.

- (void)awakeFromNib {

[super awakeFromNib];

// do my customization here.

}


Remember:
  • OUTLETS are the members of the Controller that correspond to UI elements
  • UI Elements may be connected ot actions within the Controller

The NIB has serialized version of the objects it represents. So when it is loaded into the application, objects are not actually being created/instantiated they are, instead, being brought from a serialized state to a deserialized/live/in-memory state.

MVC - Model/View/Controller


  • Model = data + state (handles storage/persistence)
  • View = what you see
  • Controller = handles interaction between model and view
When model changes, the controller notifies the view to have it update accordingly.
Controller receives events from views and then updates data in the model.

  • Controller has outlets the point to the views
  • Actions point from view back to the controller


Info.plist

What's all this info.plist stuff all about?

plist ===> Property list...a key/value list.

Well it kind of describes some basic things about your iPhone/iPodTouch app:

  • application icon
  • capabilities used: networking
  • style of status bar
  • how the screen should be presented (portrait or landscape)
  • other system requirements
While it seems info.plist files are actually xml files you can use the XCode plist editor to modify as desired.
Here is an example from one of the sample modules

CFBundleDevelopmentRegion
en
CFBundleDisplayName
SimpleTableView
CFBundleExecutable
${EXECUTABLE_NAME}
CFBundleIconFile
CFBundleIdentifier
com.yourcompany.${PRODUCT_NAME:identifier}
CFBundleInfoDictionaryVersion
6.0
CFBundleName
${PRODUCT_NAME}
CFBundlePackageType
APPL
CFBundleSignature
????
CFBundleVersion
1.8
LSRequiresIPhoneOS
NSMainNibFile
MainWindow


iPhone Application Badge

These are the little numbers that show up on an iPhone Application's launch page icon. For example, to let you know how many calls you may have missed.

[[UIApplication sharedApplication] setApplicationIconBadgeNumber:3];

How to get YOUR application?

Here's how:

UIApplication *myApp = [UIApplication sharedApplication];


Which way's up? ACCELEROMETER

Friday, August 7, 2009

iPhone/iPodTouch App Lifecycle


NOTE: iPhone/iPodTouch applications should link to UIKit/UIKit.h (not Cocoa/Cocoa.h)

Remember: Cocoa is the desktop/Mac Framework
UIKit used for iPhone and iPod touch

NIB it up

NIB files
- specify UI components and information about object relationships

Wednesday, July 15, 2009

TMUG Meeting

I am attending the Tucson Macintosh User Group (tmug) tonight. It is being held in room 5403 of University Medical Center (UMC).

  • Tonight is hosted by President Bob Wood. Bob Wood is a 50-something bear of a man with glasses and a gray beard. (Dangerous Bob - a younger Bob Wood ... during the Eisenhower administration) - the All Powerful OZ in the for sale forum (i.e. moderator) - bob@thinkbob.com 762.0447


  • Co-Hosted by VP Ridge Prevost: another 50-something also with glasses. ridgep@aol.com, 298.7165

  • Secretary: Curt Blanchard - crblanchard@cox.net, 290.3848
  • Treasurer: Mark Jaffee - mjaffee.az@gmail.com, 299.9699
  • Member Advocate: Joyce Hardin, jrhardin@mindspring.com, 624.9644
  • Volunteer Programs: Tony Ewing, tce@ieee.org, 747.8283
  • Volunteer Web Site: Jerry Cederquist, salsa@tmug.com, 529.6593

  • Volunteer Training: John Nemerovski, john.nemo@gmail.com, 575.9596
  • Volunteer Training: Mike Peterson, mikeguru@mac.com, 325.4885
  • Membership: Marv Held, m122430@cox.net, 747.8547
  • Library: Michael Prete, michaelprete@cox.net, 325.4885
  • Publicity: Zack Williams, zdw@artisancomputer.com, 977.2973
  • Newsletter: Tom McGorray, tom@xgboy.com, 297.7878

  • Computer & Accessory Donations: Sara Matton, tmugsara@gmail.com
  • Membership Cost: $30 annually
  • ~17 people attending
  • TMUG members can get their business web-sites posted.
  • Review forum on the tmug site | Members Forum | Public Forum
  • Forum powered by Gossamar Forums
  • Learned how to import US Holidays to iCal by subscribing to site. Look HERE.
  • Bob Finley showed me a neat trick for the mac: you start typing a word and when you hit F5 (or fn-F5 on macbook pro) it will provide a popup pick list of possible words to complete the word. Thank you Bob!
  • TMUG luggage tags were handed out to all TMUG members.
  • TMUG Meeting Survey was handed out.
  • Michael
  • $273.64 HOME-GUARD (part of U.A.) for full-house surge protection. Tracy 745.3333. Apparently they put a box behind the electric meter.
  • A lady renting a VHS-to-Digital system
  • Gretchen (Bob's wife) - newest game Plants vs. Zombies demo.

    She reminds me a little bit of Martha Stewart. Need beads? Great Presentation!


  • Pages Presentation: pages is word processing an page layout. She showed us some of the neat alignment features within Pages. The Inspector has lots of settings to provide more fine-grained control.
  • Gretchen: Ooh [yuck], I never use Microsoft tools on my machine.
  • Below is a picture layout done in Pages. Pages Rocks!

  • Red River Paper : Paper types, Paper Weights, Thickness

  • Excitement and Suspense as door prizes are drawn!









Tuesday, July 14, 2009

Saving State

So, how is it that when you restart a well-designed iPhone/iPodTouch application it restores to the state it was in when you left the application?

Enter the NSUserDefaults ... a Singleton in the Apple

NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];

[defaults setInteger:polygonShape.numberOfSides forKey:@"numberOfSides"];


The previous section stores a number off into the NSUserDefaults area at some point. Where this is called is up to you, the developer.

Then when you restart your application you simply see if this key exists, if it does you use it if not then use some appropriate defaults.

NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];

int numberOfSides = [defaults integerForKey:@"numberOfSides"];

if(numberOfSides!=0) {

polygonShape.numberOfSides=numberOfSides;

numberOfSidesLabel.text = [NSString stringWithFormat:@"%d",numberOfSides];

}




Core Animation and iPhone Application Programming Guide

You know...every time I look up something produced by Apple I am rarely disappointed and almost always impressed.


iPhone App: Amazing Polygon App - update 4 images and transforms

The latest version of the application adds some features:
  • Image pull - from a resource file
  • Image rendering - both programmatically and using the Interface Builder
  • Image transformation - scale (size), rotation, and translation (position)
I am discovering just how excellent the Apple documentation is! UIKit, et al!



iPhone App: Amazing Polygon App - update 3 drawing polygon

Added drawing of polygon to application.







Monday, July 13, 2009

Quartz 2D and Core Graphics

Drawing in Cocoa is usually accomplished with the help of the Quartz 2D API which is part of the Core Graphics framework.

iPhone Blog





Sunday, July 12, 2009

iPhone App: Amazing Polygon App - update 2 simple shape

I have begun playing with some of the CG libraries available on the iPhone. It is more C-like than I had expected but still pretty straightforward.

You can see below there is a gray area at the lower portion of the screen which is actually a subclass of UIView. It has a drawRect call that is invoked by the Graphics System when the main window of the application is initialized.

UIView Structures


  • CGPoint (x,y)
  • CGSize (width, height)
  • CGRect (origin + size, or CGPoint + CGSize)
Note the origin point is the upper-left hand corner (0,0)
X positive goes to the right
Y positive goes down

Creating CG objects:
CGPoint point = CGPointMake(50.0,100.0);
point.x = 50.0
point.y = 100.0

CGSize size = CGSizeMake(23.0,42.0);
size.width = 23.0;
size.height = 42.0;

CGRect rect = CGRectMake( x, y, width, height);
rect.origin.x = x1;
rect.origin.y = y1;
rect.size.width = w1;
rect.size.height = h1;




iPhone UIView

Some of this is directly from the Stanford series

UIView is part of UIKit Framework which is part of Cocoa.

It represents a rectangular part of the screen. With it you can:
  • draw into the rectangular area
  • process events (since it inherits from UIResponder)
View Hierarchies:
  • every view has ONE superview (assuming the view has been put into another view)
  • every view has ZERO or MORE subviews
UIWindow is a subclass of UIView

NOTE: there is only one UIWindow for an iPhone App


Finished Lecture 3 and 4

Making some progress.

Getting the hang of Objective-C, XCode and Interface Builder.

iPhone App: Amazing Polygon App - update 1 Slider

Added a slider to facilitate incrementing/decrementing the number of sides in the polygon.



General Process:

  • Create the action method in your Controller to process events from the slider.
  • Add an Outlet to your Controller header file IBOutlet UISlider *slider;.
  • Mark this method with the (IBAction) macro.
  • Bring up your .xib in Interface Builder
  • Add a slider control (UISlider) to the View
  • Make a connection from the slider control to the Controller object...when you release it you will be prompted to select the action to be invoked.
  • Save everything and test it out.

Simple!

Cocoa App Pieces

A Cocoa application is made up of several pieces:

  • Compiled code (written code compiled + framework code/libraries)
  • Interface Files (UI Elements/Controls, Outlets, Connections, etc.)
  • Resources (sounds, text/strings, audio, etc)
  • Application Configuration (Info.plist)

Cocoa Looping a Dictionary

From the stanford course

NSMutableDictionary *dict = [NSMutableDictionary dictionary];

[dict setValue:[NSDate date] forKey:@"now"];

[dict setValue:[NSDate dateWithTimeIntervalSinceNow:-60] forKey:@"1 minutes ago"];

[dict setValue:[NSDate dateWithTimeIntervalSinceNow:60 * 30] forKey:@"30 minutes from now"];

[dict setValue:[NSDate dateWithTimeIntervalSinceNow:-60 * 60 * 24] forKey:@"24 hours ago"];

[dict setValue:[NSDate dateWithTimeIntervalSinceNow:-7 * 60 * 60 * 24] forKey:@"a week ago today"];

[dict setValue:[NSDate dateWithTimeIntervalSinceNow:365 * 60 * 60 * 24] forKey:@"a year from now"];


for (NSString *key in dict)

{

NSDate *date = [dict objectForKey:key];

NSLog([NSString stringWithFormat:@"Key: '%@' Date: '%@'", key, date]);

}



Cocoa URL's using NSUrl

#import


NSURL *someURL = [NSURL URLWithString:@"http://www.somesite.com:8080/path/targetpage.html"];

NSLog([NSString stringWithFormat:@"Host: '%@' Port: '%d'", [someURL host], [someURL port]]);


Host: www.somesite.com
Port: 8080

Objective-C Training





Cocoa Dictionary like Java HashMap

COCOA has a couple dictionary objects. One is changeable (mutable) and one is not.

NSDictionary and NSMutableDictionary


NSMutableDictionary *dict = [NSMutableDictionary dictionary];

[dict setValue:[NSDate date] forKey:@"now"];

[dict setValue:[NSDate dateWithTimeIntervalSinceNow:-60] forKey:@"1 minutes ago"];


Debugging session completed

Just completed the debugging session from the Stanford course. Helpful.

XCode: indent code

  • cmd-} indent right
  • cmd-{ indent left

XCode: The Great Escape (esc)

Wow! Once you know this vital piece of information your whole life will change.

Once you know the magic keystroke all your dreams will come true!

Are you ready? Huh? Are you?

OK...here it comes...you sure you are ready?

The magic keystroke is 'esc'

When in XCode and you click the 'esc' key you get amazing AUTO-COMPLETION.

Use it and enjoy life.

You're welcome.

I may have exaggerated a little bit. :-)

Saturday, July 11, 2009

iPhone App: Amazing Polygon App

Here is a little application I whipped up tonight for the iPhone. It is based on an assignment from the Stanford course.

Anyway, I call it the "Amazing Polygon App". What it does is calculate the number of degrees, radians, and description of a polygon with a specified number of sides.

There is an increase and decrease button. As you click the buttons the number of sides is incremented (or decremented) and the display is refreshed.

Simple but to the point.











Lessons learned:
  • Once you have your initial user interface put together, chances are you'll want to modify it in some ways later. You can easily rearrange the positions of the controls in the Interface Builder.
  • To add new controls is not a big problem either. Simply add the controls in Interface Builder. Then in your Controller add instance variables representing the controls and be sure to properly decorate these instance variables with the Cocoa Macros to let the Interface Builder know about them. Once this is done, the instance variables will appear as outlets in the Interface Builder for the controller. Now it is a simple matter to add a connection between the outlet and the control on your user interface!!

Friday, July 10, 2009

XCode: Go to Counterpart

Above the edit view (Southeast Panel in XCode) there is a neat little icon
that looks kind of like a standard copy to clipboard button (2 overlapping pages). If you hover over this button it says "Go to Counterpart".
If you are viewing an Objective-C header (.h) file or an Objective-C implementation (.m) file then this file will be enabled. Clicking the file swaps the contents of the current edit window with the corresponding file. In other words, if you are looking at the header file and you click the button then the contents of the edit view will show the corresponding implementation file.






NOTE: You can modestly change the behavior of this within the XCode Preferences under the General icon:



If you forget about this icon you can always use the keyboard shortcut: opt-cmd-UPARROW

XCode is flexible...even does the splits!

The XCode development environment is Apple's slick IDE (Integrated Development Environment) which is used to write Apple Applications (MACOS + iPhone).

The main project window has 3 main areas:
  • West: Groups & Files
  • North East: File Names
  • South East: Edit Views

If you look closely in the views area you'll see an itsy-bitsy icon near the right scroll bar. Float over it. It says: "click to split the editor view". When you click this icon the edit view turns into 2 panels with the same content. You can then click on either edit view followed by clicking on a file and voi-la you'll have two separate files viewable at the same time.

I find this helpful when looking at Objective-C header and implementation files.

Interface Builder


I am using Interface Builder version 3.1.2 (see image above). This kind of jives with the version of XCode I am using. See below.

Note: when developers talk about the Interface Document Window they are really describing the .xib file (or the window presenting the .xib) file. Recall, the .xib file contains the interface design document that archives the elements of your user interface. Once saved the .xib file contains the archived version of your user interface as well as any state specified at design time.


Controller objects in the context of interface building is an arbitrarily named object that has been added to the user interface document. This object has outlets (instance variables) as well as actions (what it does).

You define the object's outlets and actions using the Identity Inspector (cmd-4).







So we've created:
  • some basic user interface with some user interface components (e.g. 2 buttons and 2 labels)
  • a controller object (to be used to control how the user interface is used.

Now we want to connect the UI components to the controller. Welcome the Connections Inspector (cmd-2)

BTW, you may have observed a pattern here with regard to how you can activate the various inspectors:
  • cmd-1: Attributes Inspector
  • cmd-2: Connections Inspector
  • cmd-3: Size Inspector
  • cmd-4: Identity Inspector
The number represents a tab at the top of the Inspector window from left to right.

Controller classes are defined within the Interface Builder. Now we need to connect it to the application...by creating/generating an actual source file. NOTE: if we simply try to run the application after creating an object within the Interface Builder there will be an error as when the NIB is unarchived it will try to instantiate a Controller class...but we have not yet generated the source for it and compiled the source.

You'll get an error like the following:

2009-07-10 16:40:15.586 HelloPoly[4322:20b] Unknown class Controller in Interface Builder file.


Don't despair! In Interface Builder select the Controller object and then do a File -> write class files.


Be sure to look at UIKit Reference API


One thing to remember is that everything you can do in Interface Builder you can do programmatically.

xib ~ nib ~ Interface File

The interface file
It is kind of like the serialized (or archived) version of what you put together at design time.

When you run your application and a .xib file is loaded the objects are deserialized (unarchived) and live objects are created...and their state becomes what it was at design time.

.xib files are created and manipulated (designed) with an application called the Interface Builder.

btw, on a MAC-OSX computer the Interface Builder is located in the /Developer/Applications directory.

From the Stanford course I've learned that the Interface Builder accomplishes the following jobs:
  1. Layout and configure the user interface
  2. Define a controller class and create an instance of that class
  3. Connect the user interface and the controller
  4. Generate source files for the new controller class

From Apple's site:

Key Interface Builder Features

  • Helps you design Aqua-compliant user interfaces with the "Snap to Aqua Guidelines" feature
  • Creates both Cocoa nibs and Carbon nibs
  • A key part of the Cocoa application development process - lets you subclass, connect objects, and establish default values, helping your application require less code
  • "Test Interface" mode lets you try your UI without writing any code
  • Spell Checks your UI text as you go

Thursday, July 9, 2009

Objective-C Tutorial at CocoaDevCentral

I just finished reading the nice and brief article on learning Objective-C over at http://www.cocoadevcentral.com/d/learn_objectivec/.

Check it out!


http://www.cocoadevcentral.com/d/learn_objectivec/

Believe in your 'self' but be careful when assigning.

self in Objective-C is analogous to this in C++ and Java.

name = @"Jed"; // accesses the instance variable directly
self.name = @"Jed"; // access the setter method of the instance variable.

// again, from stanford course
@implementation Person
- (void)setAge:(int)newAge {
[self setAge:newAge]; // Infinite loop!
}
@end

Objective-C policies for properties:

From the stanford course:

Read-only vs. read-write:
@property int age; // read-write
@property (readonly) BOOL isHappy; // read-only

Memory management policies for object properties (not primitives)
@property (assign) NSString *name; // pointer assignment
@property (retain) NSString *name; // retain called
@property (copy) NSString *name; // copy called

setters/getters vs. properties

In Objective-C it is common to provide accessor (getter) and mutator (setter) methods like in the following:

@interface RunningShoe : NSObject {
// instance variables
NSString* shoeName;
}

// method declarations
-(NSString *) shoeName;
-(void) setShoeName:(NSString*) _someShoeName;

@end

and the implementation:

@implementation RunningShoe

- (void)setShoeName:(NSString *)value {
if (value != shoeName) {
[value release];
name = [value copy];
}
}

@end


This is kind of wordy after a while. Well, there is a simpler alternative called properties:


@interface RunningShoe : NSObject {
NSString* shoeName;
}

// define properties
@property (copy) shoeName;

@end

now the implementation:

@implementation RunningShoe

@synthesize shoeName;
@end

One of the cool things about properties is that they are overidable. You may be happy with the standard getter/setter functionality...but you may want to do something out of the ordinary. Perhaps you want to capitalize a username property before actually assigning it to an instance variable. By overriding the setUsername method you can do this (even though it is a @synthesize property).

Cocoa with Love

Begun reading a Matt Galagher's page called Cocoa with Love.

Good-day mate!

Objective-C 'description' like Java toString...

If you have done any programming in Java you may be aware of the method that will return a String representation of an object:

String toString() {
return "some string";
}

In Objective-C there is a similar class method on NSObject called description.

From the documentation description: "returns a string that describes the contents of the receiver."


WARNING: just because NSObject defines description does not mean the runtime will automatically recognize your override of the method UNLESS you explicitly declare it in your header (.h) file.

The header (.h) file
@interface MyObj : NSObject {
// instance variables
}
-(NSString *) description;

@end

Now the implementation (.m) file:
@implementation MyObj {
// instance variables
}
-(NSString *) description {
return @"My special override of description";
}

@end


Now you can do something like the following:

...
MyObj mo = [[MyObj alloc] init];

NSLog( @"Your object is: %@", mo );
...

Output:

Your object is: My special override of description


You say Either I say I-ther, You say AppKit I say UIKit

UIKit is the User Interface framework on the iPhone.

If you were creating a regular MAC-OSX you would use the AppKit.

Tuesday, July 7, 2009

Lecture 2 ... again!

OK, so I've been distracted from my Apple / Mac / Cocoa / iPhone programming education with this pesky thing called "A JOB" :-)

(Actually I really like my job)

Anyway, tonight I climbed back into the saddle and began refamiliarizing myself with the things I had already learned several weeks back.

Tonight I reviewed lecture 2.

Still getting used to the Objective-C syntax. It is not difficult but it feels rather wordy.

NSString *phrase = @"Mr. Javapda...but you can call me javapda :-)";
NSLog( [ NSString stringWithFormat:@"Phrase: %@", phrase ] );

Lots of learning...but sadly there are some fundamental development issues I have yet to tackle such as:
How to specify the framework(s) being used in the XCode environment.

I am still pretty excited about iPhone OS3 ...

Last week I picked up a new iPhone 3GS - so naturally I am excited about getting some software written for it.

Stay tuned :-)

Sunday, July 5, 2009

Java has Method Reflection, Cocoa has Introspection and dynamic messaging with Selectors....

Cocoa supports something call Selectors

// SEL is a type
// Here we create an instance of sell representing 'someMethod'
SEL sel = @selector(someMethod:)

// See if some object responds to this
if ( [obj respondsToSelector:sel] ) {
// Now invoke the selector (the method, if you will)
[obj performSelector:sel withObject:self]
}

Applet Tablet in early 2010?


Applet Tablet?

Objective C has Dynamic Typing

Commonly:

NSString *charlieBrownAuthor = @"Charles Schultz";
NSLog(charlieBrownAuthor);



But Dynamically:

id nm = @"Funky Chicken";
NSLog(nm);


Apparently all type checking is done at compile time. (not run time)

Friday, July 3, 2009

XCode


Learning about the XCode development environment for Mac OS X has been an interesting process.

I currently have XCode Version 3.1.2

There is a lot to learn. Tons of configuration capabilities that give the environment a lot of power...and a lot of complexity.

Coming from the Eclipse/Java world it is clear that we're not in Kansas any more :-)

One thing that I find interesting is the search mechanism in XCode. It is tightly bound to Mac OS X's Spotlight feature. So if you need to search for something it must be on a drive that has been indexed by Spotlight. If it is on a mounted drive you'll want to let Spotlight know about it by using the mdutil utility:


> sudo mdutil -i on /Volumes/<volume_name>

Thursday, July 2, 2009

Tethering your iPhone







http://www.gadgetreview.com/2009/06/gadget-how-to-iphone-tethering-without-jailbreaking.html

NOTE: THIS POST POSTED BY TETHERED iPhone!

From the Apple Byte podcast, Brian Tong says:
  • http://help.benm.at/help.php
  • Scroll down to tethering and internet settings
  • Press on the Download link
  • Select your country (U.S.A.)
  • Select your carrier (at&t)
  • You'll come to a page with an Install button
  • Then go to the home screen
  • Go to Settings
  • Go to General
  • Go to Network
  • Now you'll see an Internet Tethering Option
  • To activate - turn it on (either Bluetooth or USB)
  • Connect USB between iPhone and Mac
  • Network will automatically be detected