|
// TODO: comments not working in Xcode 4 |
Wednesday, April 27, 2011 11:56 AM |
Seems // TODO and other special comments are not showing up in the method navigator in Xcode 4. hmmmm.
IPhone
|
|
|
iPhone StopWatch Sample (part 3) |
Sunday, January 02, 2011 9:21 PM |
|
The first function is called when the startButton is pressed. If the text of the button
is Start, then we want to disable the resetButton, change the startButton's text to Stop
mark the startTime, and instantiate the timer callback. If the text of the startButton is
not Start, then we want to enable the resetButton, disable the startButton, and invalidate
the timer callback funtion.
The second function handles the resetButton. If the resetButton's been pressed, the timeLabel
is reset to 00:00:00.0, the startButton text is set to Start and enabled, and the resetButton
is disabled.
Finally, we have a function to handle the timer callback. This method is called when
the timer fires - in this case, every 0.1 seconds.
- (void) updateStopWatchLabel { nowTime = [NSDate timeIntervalSinceReferenceDate]; NSTimeInterval interval = nowTime - startTime; int seconds = (int)interval; int tenths = (int)((interval - seconds) * 10); [timeLabel setText:[NSString stringWithFormat:@"%02d:%02d:%02d.%1d",(seconds/3600)%24,(seconds/60)%60, seconds%60, tenths]]; }
In the simulator and on the iPhone, the application looks like this:
Lessons learned
In many of the sample code I ran across on the web, people would use an integer to keep track of the elapsed time.
Don't. NSTimeInterval is a quick way to grab the elapsed time in milliseconds from a fixed reference point. It's
fast, neat, and works well. It would be easy to only have one function handle all the button UI. I kept it in two
functions just to make it clearer, I hope. Enjoy.
IPhone
|
|
|
iPhone StopWatch Sample (part 2) |
Sunday, January 02, 2011 9:18 PM |
|
In interface builder, we'll want to hook the UI elements to these variables so we can work with them.
From Xcode's project window, open StopWatchViewController.xib. This will allow you to place the elements
which will comprise the StopWatch application. Place a label and two buttons on the viewcontroller's window
and initialize them with appropriate values. We'll tie the label and buttons to the variables timeLabel, startButton, and
resetButton in StopWatchViewController by Control dragging from the File's Owner to each element. When you release the
mouse, Interface Builder will prompt you for the appropriate variable. We'll also want to tie our two functions,
startButtonPressed and resetButtonPressed to each of our buttons by Control dragging from the buttons to
the StopWatchViewController. Be sure to save your work before switching back to Xcode.
With the buttons and label in place, let's go back to Xcode and modify the implementation file,
StopWatchViewController.m, to put the whole thing together. First, we can add the two functions
to handle each of the button presses:
- (IBAction)startButtonPressed:(id)sender { if ([startButton.titleLabel.text isEqualToString:@"Start"]) { // If the startButton is equal to start when it is pressed we want to // disable the resetButton, change the text of the startButton to Pause, and // start keeping track of the time [resetButton setEnabled:false]; [startButton setTitle:@"Stop" forState:UIControlStateNormal]; startTime = [NSDate timeIntervalSinceReferenceDate]; stopwatchTimer = [NSTimer scheduledTimerWithTimeInterval:0.1 target:self selector:@selector(updateStopWatchLabel) userInfo:nil repeats:YES]; } else { // startButton says Stop [resetButton setEnabled:true]; [startButton setEnabled:false]; [stopwatchTimer invalidate]; } }
- (IBAction)resetButtonPressed:(id)sender { [timeLabel setText:@"00:00:00.0"]; [startButton setTitle:@"Start" forState:UIControlStateNormal]; [startButton setEnabled:true]; [resetButton setEnabled:FALSE]; }
IPhone
|
|
|
iPhone StopWatch Sample (part 1) |
Sunday, January 02, 2011 9:16 PM |
iPhone Stop Watch
In this article, I explain the ins and outs of creating a stop watch application similar
to the one in the iPhone's Clock application. As a refresher, let's take a look at the start
screen for the iPhone StopWatch. There's the Start and Reset buttons and a label indicating the time
in tenths of seconds. This sample won't do anything too complicated like keeping laps.
Xcode Project
First of all, let's start up Xcode and create a view-based project and call it StopWatch.
Once the project has been created, Xcode will have the following project window.
Next, let's setup our variables. We know we need a label to hold the stopwatch's elapsed time. We will probably also
need a couple of buttons. We'll also need some variables to figure out the elapsed time. So, open StopWatchViewController.h
in xCode and add the following lines.
#import <UIKit/UIKit.h>
@interface StopWatchViewController : UIViewController { IBOutlet UILabel *timeLabel; IBOutlet UIButton *startButton; IBOutlet UIButton *resetButton; NSTimeInterval startTime; NSTimeInterval nowTime; NSTimer *stopwatchTimer; }
@property (retain, nonatomic) UIButton *startButton; @property (retain, nonatomic) UIButton *resetButton; @property (retain, nonatomic) UILabel *timeLabel;
- (IBAction) startButtonPressed:(id)sender; - (IBAction) resetButtonPressed:(id)sender;
@end
IPhone
|
|
|
Hello World from the iPhone (part 2) |
Monday, October 18, 2010 4:38 PM |
Hello World from the iPhone (part 2)
We continue our exploration of iPhone development. In part 1, we downloaded the latest version of Apple's development tools. In part 2, we'll create a simple iPhone application which displays the message "Hello World!".
Creating the Project
Let's start Xcode. We get the intro screen to xCode which looks like this: 
Choose Create New Xcode Project: 
On the left pane, you will have the choice of creating either iOS or Mac OS X applications or libraries (among other types of projects). Under the iOS selection, make sure the Application selection is chosen. For this project, we're going to choose a Window-based application. It will keep things very simple.
On the New Project screen, name the new project Hello World: 
When the Hello World project has been created and the files saved, you'll be presented with the main Xcode window. In the left pane of the window, you'll see the Groups & Files which comprise the project. In the main pane of the window, you'll see a list of items which go into the building of the application. Take a minute and explore the items which comprise your project. 
As a side note, I prefer the All-In-One view found under Xcode>Preferences. In later blog entries, I'll switch to this way of looking at things. Because I have a background using Visual Studio, I prefer one window to access project resources.
Building the Interface
Once we've created our project, we want to tell the World Hello! The development tools make this very easy to do. In the main project window, find the file named MainWindow.xib and double click on it. This will start the Interface Builder application. Interface Builder allows you to graphically design your application without having to wire up all the elements in your source code. For our Hello World project, Interface Builder would look like this: 
Now select the Label item and move it to the window labeled Window. When you double click on the label item, you can change the text to "Hello World!". Let's do that and save the file and go back to Xcode.
Building the Project
We can now build the application by choosing Build and Run at the top of Xcode's main window (be sure the build target in the upper left hand corner of Xcode's main screen is set to Simulator). Xcode will automatically start up the iPhone simulator and launch your Hello World! application. Pretty easy: 
IPhone
|
|
|
iPhone Development - Hello World (part 1) |
Tuesday, October 05, 2010 10:32 AM |
Hello World from the iPhone (part 1)
For the majority of my professional career, I've developed software using Microsoft's platform and tools. Over the last year or so, I've started writing iPhone applications using Apple's tools running on a iMac. I thought I would share some of my experiences here on the blog.
Getting Ready/Getting Xcode
Before proceeding, you'll need to get a Mac - iPhone development can only be done on the Mac. There's no cross platform story here.
When I was at Microsoft in the late 90's, Java was perceived as the big threat because it allowed for cross-platform development. It's interesting to me that iPhone (and Mac) development is all about specifically targeting a single platform - the Apple platform. There doesn't seem to be much of a story for either Open Source or Cross Platform. This specific targeting of a single platform seems to have worked well for Apple.
So, you get the tools you need by going to Apple's development center. If you search for Xcode, it will take you to the download page. The download is free and requires you to join the Apple Development Program, which is also free (if you want to publish your iPhone application, you will have to pony up $99 to Apple to become part of their professional development program.)
In its current incarnation, Xcode reminds me a bit of where Visual Studio was back a couple of years ago. It is comprised of different applications which work together to build your code. These applications consist of:
- Xcode - Apple's IDE
- Interface Builder - application designer
- iPhone Simulator - for running iPhone applications on the desktop
XCode's IDE provides a wrapper around a powerful debugger - GDB. The IDE's wrapper buffers you from GDB's command interface which can be nice at times and can be frustrating at times.
Back in the Day - In some ways, the debugging environment reminds me a little of Windows development done in the early days when we used CodeView. Or if you use the general debugger under Windows now - windbg.
More in part 2
IPhone
|
|
|
iPhone Navigation Controls |
Sunday, April 18, 2010 5:01 PM |
|
|
iPhone Core Data Services - Web Services, JSON, Notifications, and User Defaults |
Monday, April 05, 2010 6:12 PM |
• Web Services ? Your application and the Cloud ? Store and access remote data ? May be under your control or someone else's ? Services exposed via RESTful interfaces with XML or JSON • XML ? Options for parsing ? libxml2 ? NSXMLParser ? Event driven API: simpler but less powerful • JSON ? JavaScript Object Notation ? More lightweight than XML ? Looks like a property list ? Open source JSON-framework wrapper for Objective C • Apple Push Notification ? Show badges, alerts, and play sounds without app running ? Minimal server infrastructure needed ? Preserves battery life: 1 versus n TCP/IP connections ? Uses JSON underneath ? Using the Service ? Create the web service ? Get a certificate from Apple for the server ? Register with the service (sounds, badges, alerts) ? Send token to your server ? Send notifications ? Receive notification • NSUser Defaults ? Convenient way to store settings and lightweight state ? Arrays, dictionaries, strings, numbers, dates, raw data ? Settings bundles can be created so that user defaults can be set from settings app ? Internally stored as property lists
IPhone
|
|
|
iPhone Core Data Service - Objects, SQLite, Core Data |
Monday, April 05, 2010 6:10 PM |
• Archiving Objects ? Next step up from property lists ? Include arbitrary classes ? Complex object graphs ? Used by Interface Builder for NIBs • SQLite (ess-q-lite) ? Complete SQL database in an ordinary file ? Simple, compact, fast, reliable ? No separate server ? When not to use SQLite ? Multi-gigabyte databases ? High concurrency requirements ? Client/server applications ? SQLite C API Basics ? Open the database ? Execute SQL Statement ? Close the database ? There is no provided SQLite GUI manager • Core Data - an abstraction over SQLite ? Object-graph management and persistence framework ? Makes it easy to save and load model objects ? Properties and relationships ? Available on Mac OS X and iPhone OS3.0 ? Two classes you should know about ? NSPredicate - used to define logical conditions used to constrain a search either for a fetch or for in-memory filtering. ? NSEntity - used for inserting a new object into a Core Data Managed Object
IPhone
|
|
|
iPhone Core Data - File System |
Monday, April 05, 2010 6:09 PM |
• iPhone's File System ? Applications are in their own sandbox ? Security Privacy and Cleanup after deleting an app ? Each app has its own set of directories ? <Application Home> ? MyApp ? MainWindow.nib ? SomeImage.png ? Documents ? Library ? Caches, preferences ? Applications only read and write within their own home directory ? Can't write to app directory due to security/code signing ? Backed up by iTunes during sync (mostly) ? File paths in your application ? Use NSSearchPathForDirectoriesInDomain ? Including writable files with your app ? Applications are code signed ? So, you have to copy over the starter file and then you can write to it.
IPhone
|
|
|
iPhone Core Data - Property Lists |
Monday, April 05, 2010 6:08 PM |
• iPhone Core Data - Property Lists ? Convenient way to store small amount of data ? Uses Cocoa types ? Uses XML or a binary format ? When not to use property lists ? More than a few hundred KB of data ? Complex object graphs ? Custom object types ? Multiple writers (e.g. not ACID) ? Reading and writing property lists ? NSArray and NSDictionary convenience methods ? // Writing ? - (BOOL)writeToFile:(NSString *)aPath atomically:(BOOL)flag; ? - (BOOL)writeToURL:(NSURL *)aURL atomically:(BOOL)flag; ? // Reading ? - (id)initWithContentsOfFile:(NSString *)aPath; ? - (id)initWithContentsOfURL:(NSURL *)aURL; ? NSPropertyListSerialization ? Allows finer-grained control ? File format ? More descriptive errors ? Mutability
IPhone
|
|
|
UITableView Appearance and Behavior and TableViewCells |
Monday, March 22, 2010 6:07 PM |
UITableView Appearance and Behavior + Customize appearance and behavior + Keep application logic separate from view + Often the same object as datasource + Customize appearance of table view cell + tableView willDisplayCell forRowAtIndexPath, etc. + Row selection in TableViews - In iPhone applications rows rarely stay selected - Selecting a row usually triggers some event UITableViewController + Convenient starting point for view controller with a TableView - Table view is automatically created - Controller is tableviews delegate and datasource + Takes care of some default behavior - Calls -reloadData the first time it appears - Deselects rows when user navigates back - Flashes scroll indicator TableView Cells + Designated Initializer - initWithStyle (initWithFrame has been deprecated) + Basic properties include an imageView and two text labels + Customizing the content view for cases where a simple image + text doesn't suffice - Add additional views to the content view
IPhone
|
|
|
TableViews |
Monday, March 22, 2010 5:52 PM |
TableViews + Display lists of content - Single column, multiple rows - Vertical scrolling - Large data sets +Powerful and ubiquitous in iPhone applications + TableView styles - UITableViewStylePlain - UITableViewStyleGrouped + TableView Anatomy - Table headers and footers - Section headers and footers - TableCells + How to implement - a naive solution - Table views display a list of data so use and array - Issues with this approach All data is loaded upfront All data stays in memory + A better approach - the data source protocol Another object provides data to the data view Not all at once Just as it's needed for display + Like a delegate but purely data oriented Provide number of sections and rows Provide cells for table view as needed + NSIndexPath - Path to a specific node in a tree of nested arrays + NSIndexPath and TableViews - Cell location described with an index path - Category on NSIndexPath with helper methods + Single Section Table View - Return the number of rows - Provide a cell when requested + Cell Reuse - queue and dequeue ReusableCellWithIdentifier + Triggering Updates - when is the datasource asked for its data? - When a row becomes visible - When and update is explicitly requested by calling -reloadData
IPhone
|
|
|
Cool iPhone Animation stuff |
Monday, March 22, 2010 11:24 AM |
I was working on a sample to position buttons and ran across UIView.beginAnimations and UIView.commitAnimations which were cool enough. But when you add setAnimationCurve and setAnimationDuration it becomes even cooler!
-(void)willAnimateSecondHalfOfRotationFromInterfaceOrientation:(UIInterfaceOrientation)<br/> fromInterfaceOrientation duration:(NSTimeInterval)duration { UIInterfaceOrientation toOrientation = self.interfaceOrientation; [UIView beginAnimations:@"move buttons" context:nil]; [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut]; [UIView setAnimationDuration:2.0f]; if (toOrientation == UIInterfaceOrientationPortrait || toOrientation == UIInterfaceOrientationPortraitUpsideDown) { // position elements } else { // position elements } [UIView commitAnimations]; }
IPhone
|
|
|
iPhone Tab Bar Controllers |
Wednesday, March 17, 2010 1:37 PM |
Tab Bar Controllers + Array of view controllers + How it fits together - Selected view controller's view - All view controllers' titles + Tab bar appearance - View controllers can define their appearance in the tab bar - UITabBarItem - includes title and/or image (system item) + More view controllers - What happens when a tab bar controller has too many items? - Shows the … More button
IPhone
|
|
|
iPhone Navigation |
Wednesday, March 17, 2010 1:36 PM |
Navigation Controllers UINavigationController + Stack of view controllers + Navigation bar is the topmost bar How it fits together + Top view controller's view + Top view controller's title + Previous view controller's title + Top view controller's toolbar items (iPhone OS 3.0) Modifying the Navigation Stack + Push to add a view controller + Pop to remove a view controller + Set to change the entire stack of view controllers Pushing your first view controller + during the applicationDidFinishLaunching delegate + or in Response to some user action in (void)someAction:(id)sender {…} + Almost never call pop directly because it's automatically invoked by the back button Connecting View Controllers + In the real world multiple view controllers may need to share data - Watch for added, removed, or edited data - Other interesting events + How not to share data - Global variables or singletons using your application delegate - Direct dependencies make your code less reusable - And more difficult to debug and test + Best Practices for Data Flow - Figure out what exactly needs to be communicated - Define input parameters for your view controller - For communicating back up the hierarchy, use loose coupling by defining a generic interface for observers Customizing Navigation + Buttons or custom controls + Interact with the entire screen + UINavigationItem - Describes the appearance of the navigation bar - Title string, left/right bar buttons - Every view controller has a navigation item for customizing - Left & right buttons - System Bar Button Item - Edit/Done Button - Custom title view - Back button
IPhone
|
|
|
CS193P Notes - Model-View-Controller Architecture - View Controllers |
Monday, March 15, 2010 11:28 AM |
View Controllers (Part 2) View
Controllers > Problem: Managing a Screenful +
Controller manages views, data, and application logic + Apps
are made up of many of these + Is a great starting point
> Problem: Building Typical Apps + Navigation-based
+ Tab bar-based + Combination of the two +
Typically plug individual screens together to build an app >
UIViewController + Basic building block + Manages a
screenful of content + Subclass to add your own application
logic > Your View Controller Subclass > The "View"
in "ViewController" + UIViewController superclass has a view
property + It loads lazily - On demand when
requested - Can be purged on demand as well +
Sizing and positioning the view - Depends on where it's
being used - Don't make assumptions, be flexible
> When do you call -loadView? + Don't do it - step away
from the loadView. + Cocoa tends to embrace a lazy philosophy
- Call -release instead of dealloc - Call
-setNeedsDisplay instead of -drawRect + Allows for work to be
deferred or coalesced > Creating Your View in Code
+ Override -loadView + Create your views + Set
the view property + Create view controller with -init
> Creating your view with Interface Builder + Layout a
view in Interface builder + File's owner is view controller
class + Hook up view outlet + Create view
controller with -initWithNibName:bundle: > View Controller
Lifecycle + -(id)initWithNibName:(NSString *)nibName
bundle:(NSBundle *)bundle + -(void)viewDidLoad{} +
-(void)viewWillAppear:(BOOL)animated{} +-(void)viewDidAppear
+-(void)viewWillDisappear:(BOOL)animated{}
+-(void)viewDidDisappear > Loading and Saving Data
+ NSUserDefaults + Property lists + CoreData
+ SQLite + Web services > More view
controller hooks + Low memory warnings + Interface
Rotation
IPhone
|
|
|
CS193P Notes - Model-View-Controller Architecture - View Controllers |
Monday, March 15, 2010 11:26 AM |
Model-View-Controller Architecture - View Controllers (part 1)
Designing iPhone Applications > 320x480 resolution prohibits busy screens and non-essential info > Maximize the data > Show one thing at a time Patterns for organizing content > Navigation bar + hierarchy of content + Drill down into greater detail > Tab bar - different views of the same information + Self-contained modes - think about the clock app Apps show screenfuls of data > Slices of your application > Views, data, and logic Model-View-Controller > Clear responsibility > Write less code > Funny, they don't mention testing; either unit or TDD How do the Model/View/Controllers communicate with each other? > Model - typically the most reusable + Not aware of views or controller + Key-value observing + Notifications - custom messages > View - tends to be reusable + Not aware of controllers but may be aware of relevant model objects + Communicates with controller using - Target action - Delegation > Controller - knows about model and views objects + Brains of the operation + Typically app-specific - least reusable of the three layers (?).
IPhone
|
|
|
Basic iPhone Dev notes - Cocoa and Objective C |
Sunday, March 14, 2010 4:33 PM |
Cocoa Touch is the basic framework for iPhone applications. This framework was designed around a Model-View-Controller (MVC) architecture. The View is the user-interface portion of the application. The Model is where the application data is handled. The Controller is the portion of the application which binds the View and the Model together. The View and the Controller can talk back and forth. The Model and the Controller can talk back and forth. But the Model and the View shouldn't speak to each other. This separation of concerns is one of the attractive aspects of this architecture.
(As a side note, the MVC architecture is also used as an alternative architecture to WebForms in the latest ASP.NET releases.)
Outlets are instance variable that are declared using the keyword IBOutlet. You can think of an Outlet as a pointer that points to an object within the NIB. It is through these outlets that your controller class talks to your user interface objects in the NIB file (or View).
Actions are methods in the controller class. They can be thought of as ways which objects in your NIB file (view) can talk with your controller class (Controller).
Cocoa also makes extensive use of Delegates (a familiar concept from .NET), which are classes that take responsibility for doing certain things on behalf of another class/object/type.
One more intro tidbit is that Objective C uses angle brackets to indicate that a class conforms to a certain protocol. A protocol is a group of methods.
Interface Builder is more than UI layout control. Also, it will create instances of any other classes you specify.
IPhone
|
|
|
CS193 Lecture 5 (part 2) |
Wednesday, March 10, 2010 1:42 PM |
Graphics Contexts All drawing is done into an opaque graphics context Draws to screen, bitmap buffer, printer, PDF, etc. Do not cache a CGContext! CG Wrappers Some CG functionality wrapped by UIKit UIColor - easily sets the fill and/or stroke UIFont - Get font by name Drawing more complex shapes Get current graphics context define a paths Set a color Stroke or fill path Repeat, if necessary More Drawing Information UIView Class Reference CGContext Reference Quartz 2D Programming Guide Images and Text UIImage - represents an image Text, Images and UIKit views Use UILabel -font -textColor -shadow (offset and color) -textAlignment UIImageView UIView that draws UIImages Properties -image -animatedImages -animatedDuration -animatedRepeatCount UIView - contentMode property to align and scale image with regards to bounds UIControl UIView with Target-Action event handling Properties include: -enabled -selected -highlighted UIButton UITextField Animating Views UIView supports frame, bounds, center, alpha, transform animations Additional animation options include -delay before starting -start at a specific time -curve (how fast the ease in/out occurs) -repeat count -autoreverses Use delegates to determine when the animation starts and stops Core Animation Hardware accelerated rendering engine UIViews are backed by "layers" What's drawn is then composited by a separate process Property animations are done automatically by manipulating layers View Transforms Every view has a transform property CGAffineTransform structure is used to represent transform Use CG functions to create/modify transforms For more animation information iPhone OS Programming guide -Modifying Views at Runtime Core Animation Programming Guide Hints for assignment 3 NSUserDefaults to read and write preferences and state -Singleton object -Includes methods for storing and fetching common types
IPhone
|
|
|
CS193 Lecture 5 (part 1) |
Wednesday, March 10, 2010 1:41 PM |
Views, Drawing, and Animation
View Fundamentals Rectangular area on screen Responsible for drawing Responsible for handling events Subclass of UIResponder (event handling class) Views are arranged hierarchically -every view has one superview -every view has zero or more subviews View Hierarchy - UIWindow View live inside of a window UIWindow is actually just a view There is one UIWindow for an iPhonef application -contains the entire view hierarchy -setup by default in Xcode template project View Hierarchy - Manipulation Add/remove views in IB or using UIView methods -(void)addSubview:(UIView *)view; -(void)removeFromSuperview - a subView removes itself manipulate the view hierarchy manually -insertSubview -exchangeSubviewAtIndex View Hierarchy - Ownership Superviews retain their subviews Views can be temporarily hidden -theView.hidden = YES; View-related Structures (CG == Core Graphics) -CGPoint - location in space: {x, y} -CGSize - dimensions: {width, height} -CGRect - location and dimension: {origin, size} View-related Structures Convenience macros - CGPointMake, CGSizeMake, CGRectMake UIView Coordinate system Origin is in the top left - y goes down Location and Size Frame is in the superview's coordinate system Bounds is in the local coordinate system Frame is computed Center point is stored and from that along with the bounds to get the frame Transform Rotation, translation, and scale Frame and bounds - which to use? If you are using a view, typically use the frame If you are implementing a view, typically use bounds Creating Views Commonly use Interface Builder Manually creating views -Initialized using -initWithFrame CGRect frame - CGRectMake(0, 0, 200, 150); UIView *myView = [[UIView alloc] initWithFrame: frame]; [window addSubview:label]; [label setText:@"Number of Sides:"]; [label release]; // label is now retained by the window Drawing - (void) drawRect:(CGRect)rect Override - drawRect: to draw a custom view rect argument is area to draw Be Lazy drawRect: is invoked automatically being lazy is good for performance When a view needs to be redrawn, use: -(void) setNeedsDisplay; Example: -(void) setNumberOfSides: (int)sides { numberOfSides = sides; [polygonView setNeedsDisplay]; }
IPhone
|
|
|
CS193 Lecture 4 |
Tuesday, March 09, 2010 3:19 PM |
Anatomy of an App, MVC, Nib files, controls & Target-Action
Memory Management Alloc/Init Alloc/Init - alloc assigns memory; -init sets pup the object Override -init, not -alloc Retain/Release Increment and decrement retainCount When retainCount is 0, object is deallocated Don't call dealloc Autorelease Object is released when run loop completes
Setters and Getters Setter and Getters have a standard format: -(int)age; -(void)setAge:(int)age; Properties allow access to setters and getters through dot syntax: @property age; int theAge = person.age; person.Age = 21; Anatomy of an Application Compiled code Nib files - UI elements - Details about the object relationships Resources Info.plist file (application configuration)
UIKit Framework Provides standard interface elements - Don't fight the framework - Understand the designs
UIKit Framework Starts your application Every application has a single instance of UIApplication -Singleton design pattern @interface UIApplication - Orchestrates the lifecycle of an application - Dispatches events - Manages status bar - Rarely subclassed - use delegation instead
Delegation Control passed to delegate objects to perform application specific behavior Avoids need to subclass complex objects Many UIKit classes use delegates -UIApplication - UITableView - UITextField
UIApplicationDelegate XCode project templates have one set up by default Object you provide that participates in application lifecycle Can implement various methods which UIApplication will call
Info.plist file Property List (XML) describing your application - Icon appearance - Status bar style - Orientation, uses WiFi, system requirements Can edit most properties in XCode
Model View Controller Controller is the intermediary between the Model and View View - UI Model - where the data is stored Outlets and actions are how the Controller, Model, and View communicate with each other
Nib Files - design time Helps you design the View add controller objects
HelloPolly Designed to help us understand the MVC application architecture
IPhone
|
|
|
Mac OS Getters and Setters and what you're used to |
Tuesday, March 09, 2010 2:02 PM |
I ran into a bit of a problem the other day with using setters and getters. I figured I would use the Object C syntax to set a property. Something like this:
[someThing someProperty:10];
The compiler kept giving me some vague error message and I kept on looking at it. Eventually, I ran across a blog entry which clued me in. If I wanted to something like this, I had to use:
[someThing setsomeProperty:10];
The blog entry was interesting because it was actually talking about using dot notation for setting properties in Objective C. It suggested that instead of using what it called the obvious:
someThing.setsomeProperty = 10;
That you should use the less obvious:
someThing.someProperty = 10;
Coming from .NET programming, the second way to use the dot notation is what I would have thought was pretty obvious. The inclusion of "set" in the property name was not very obvious to me. I guess it's all in where you're coming from.
IPhone
|
|
|
My First IPhone application |
Thursday, March 04, 2010 8:27 PM |
I downloaded the IPhone SDK and associated tools and built my first IPhone application. It doesn't do anything much besides display some text and show a picture. So far, it reminds me a bit of Visual Basic.
IPhone
|
|
|
IPhone Development |
Thursday, March 04, 2010 7:19 PM |
IPhone development
- Tools - XCode and Interface Builder
- Foundation and UIKit
- Objective C (runtime?)
Mac OS X consists of
- Foundation
- Media
- Core Services
- Core OS
The IPhone OS is comprised of the same elements, except Cocoa Touch.
IPhone
|
|
|
Remember to add IPhone dev to website |
Friday, February 26, 2010 10:41 PM |
As I come up to speed on IPhone and all things Mac, I'll have to be sure to rework that information into this website. I've kinda sorta started to by adding the Mac and IPhone blog categories.
IPhone
|
|
|
Stanford Course |
Friday, February 26, 2010 10:40 PM |
To come up to speed on IPhone development, I will work my way through the Stanford IPhone development course CS193P. The syllabus looks like this:
Week 1: 1/5 & 1/7 1/5: Intro to Mac OS X and Cocoa Touch, Objective-C and Tools 1/7: Using Objective-C, Foundation objects Assignment: Hello Stanford and Command Line Tool I (due 1/13) Week 2: 1/12 & 1/14 1/12: Custom classes, Memory Management, ObjC Properties 1/14: MVC, Interface Builder, Controls & target-action Assignment: Command Line Tool II and HelloPoly I (due 1/20) Week 3: 1/19 & 1/21 1/19: Views, Animation, Open GL 1/21: View Controllers Assignment: HelloPoly II (due 1/27) Week 4: 1/26 & 1/28 1/26: Navigation Controllers, Tab Bar Controllers, Searching 1/28: TableViews Assignment: Flickr 1 (due 2/3) Week 5: 2/2 & 2/4 2/2: Dealing with Data: User Defaults, SQLite, Web Services 2/4: Threading, Notifications, KVC Assignment: Flickr 2 (due 2/10), Final project proposals Week 6: 2/9 & 2/11 2/9: Text, Responders, Modal Views 2/11: Address Book Assignment: Flickr 3 (due 2/17) Week 7: 2/16 & 2/18 2/16: WebViews, MapKit 2/18: Multitouch, Gestures Assignment: Flickr 4 (due 2/24) Week 8: 2/23 & 2/25 2/23: Device APIs: Location, Accelerometer, Compass, Battery Life 2/25: Audio playback, Video playback, Image/Video Picker, iPod Media Access Assignment: Final project (due 3/17) Week 9: 3/2 & 3/4 3/2: Bonjour, streams, networking, GameKit 3/9: Unit testing, Objective-C fun, localization Assignment: Final project (due 3/17) Week 10: 3/9 & 3/11 3/9: TBD 3/11: TBD Assignment: Final project (due 3/17) CS193P Handout #1 Winter 2010 Cannistraro/Shaffer
While I was on vacation I watched the first three classes or so. Looks like it's going to be fun!
IPhone
|
|
|
I ordered the new Mac |
Friday, February 26, 2010 2:15 PM |
|
I just ordered a new IMac from B&H Photo (free shipping - oh, not quite $15 and tax - significant here in WA - about $200). The specs are: - Quad-Core 2.66GHz Intel Core i5
- 8GB (4x2GB) RAM
- 1TB Hard Drive
- 8x SuperDrive DVD Burner, SD Card Slot
- ATI Radeon HD 4850 Graphics
- 27" LED Backlit 16:9 Widescreen Display
- iSight Camera, Bluetooth 2.1+EDR
- 802.11n Airport Extreme Wi-Fi
- Wireless Keyboard & Magic Mouse
- Mac OS X 10.6 Snow Leopard
Who would have thought! Should be here next Friday!
IPhone
|
|
|
A Mac Guy Once Again |
Saturday, February 20, 2010 5:02 PM |
|
Before I came to work at Microsoft, I worked at OCLC (technically, Ameritech bought our division right before I left). I did a variety of things at OCLC but one of the projects I got involved with was a pilot Macintosh project. In 1987, or so, OCLC became a developer partner with Apple. As a result they got an Apple Lisa (a firmware upgrade later, the MacXL) and one of the very early Macintosh's. When OCLC ended its pilot program, they gave me the Lisa/MacXL. I've kept it all these years and it is now out in the garage.
Well, after all these years I've decided to buy a Mac. I'll keep everyone posted on the experience!
IPhone
|
|