WWDC2001 Session 102

Transcript

Kind: captions
Language: en
so my name is Chuck Sula and just like
everybody else here from Apple today I'm
here to help you and in particular I'm
here to help you learn about cocoa so
let's give an idea again what cocoa is
it's an advanced object-oriented
framework designed from the ground up
using objects and many powerful object
or any methodology it provides you a
full feature set for doing application
development and it integrates well with
other system components it's not a
standalone component you can use in the
POSIX API S or as you heard Scott's say
earlier actually integrate with parts of
carbon like the the print panels
actually comes up through carbon and
it's used by many important Mac os10
applications
system preferences was written in Cocoa
the mail application project builder let
me set the stage for what you're gonna
learn today my goal is to tell you what
makes Cocoa unique by doing so we're
gonna talk about some of the important
classes in Cocoa we can't talk about all
of them there's a lot and we're gonna
discuss some of the main concepts and
features and pick of those that make
Coco unique and powerful above all I
want you to learn that cocoa is powerful
easy to use and can make you more
productive cocoa is powerful it's an
object-oriented framework designed from
the ground up using objects and those
object or methodologies you'll notice
some of these slides are similar to
earlier slides you saw today that I left
for next year not to do them so early so
that they can can't be reused by people
before me so they're designed for
extensively again like Scott said so
that you the developer can make changes
without a lot of effort and we use a
dynamic runtime system that makes many
things easy to do that you might not
even consider doing with other
frameworks it's easy to use because we
have consistent API as of conventions
again in Objective C and Java and again
those of you who are not from North
Objective C shouldn't be frightened it's
something that it's a small extension to
the ANSI C based language to support
things like objects and messaging and if
you're familiar with object our
programming and the C based language
used to build one urn in a day or two
now we also have brought up this
linecount thing many times so one
measure of productivity is lying counts
it's not the only one but it's a measure
of productivity so what can Coco give
you for free well in fact with no lines
of code you can actually have a
reasonable text setter now I know most
of you are here are not in the business
of writing text setters but what this
means is that it this is an example of
what Coco can can give you for free and
the idea here is that although you're
not writing text there's you want to get
lots of stuff for free so that you don't
have to reinvent the wheel this means
you get more time to work on features
which make your product unique and helps
you sell your product so at this time
I'd like to bring Doug Davidson up on
stage he's going to show you how to
write a no line text editor and sort of
show off what you get for free and Coco
done I'm here to show you how easy it is
to get started writing great
applications with Coco so we're gonna
write a Coco application from scratch
right now so it's fire up project
builder get started this will be a cocoa
document based application something
along lines a simple text and all that
project build will create a project for
us
now the main thing we get with this
project is a couple of interface
definition files so let's take a look at
those in interface builder
now the first one has a window for us
where we can put the contents of our
document Andy your document contents
here since this is going to be a text
editor what the thing that I want to put
in here is a text view so I'll just drag
one in off the pallet and I'll position
it the way I want size it the way I want
and I want it to grow when my window
grows for that I have to set a couple of
Springs and let's take a look at the
attributes our text view might have
we've already got its editable that's
good multiple fonts allowed that's also
good about graphics that would also be
nice and undo and the other one has our
main menu let's also take a look at that
here's our main menu now since this is a
text editor I think I would like to have
a text menu font menu
all right now let's see let's try
building it this is always a moment of
truth built that's good let's see if we
can run it straight from project builder
and here is our application what we get
we've got a document window or maybe two
or three that we can type in to let me
make that a little bigger for you
that's better and this has a lot of the
standard text type features that you
might expect like Oh
copy and paste or write write a drop or
maybe undo redo or bold italics
underline multiple fonts
or even multiple languages clinic
or we can drag in inline images they
make that little bigger
we also have a few features that you
might not expect like
as you type spell checking
and we also have
some advanced kerning and look at your
support built right in and we also have
a ruler with some various formatting
options and there's one more thing
notice this little close button up here
has a document dirty - indicator if that
means that our application is
automatically noticed that we edited
this document if we try to close it it
will ask us if we want to save changes
you know bring up a say panel a little
one or maybe a big one whatever we like
you can try save oops didn't save the
document and what's missing here we
didn't write any code we forgot to add
any code well at this point I have to
admit that cocoa can't do absolutely
everything for you you would have to
write a little code to be able to open
or save documents but with an additional
less than twenty lines of code this text
editor would be able to open and save
documents in a variety of formats and we
would have a full working text editor
now back to you chuck
all right thank you very much Doug now
again the point of the demo was not to
show you that you could write a text
edit real easy well you can but most of
you aren't going to be doing that the
point was to show you that you get lots
for free in cocoa and if you're like me
you get like getting stuff for free like
we'll Shipley was up here earlier saying
you don't you know you don't enjoy
writing stuff that's been done hundreds
of times you want to do new unique stuff
that's gonna make your product really
cool okay and that's what cocoa allows
you to do so let's talk about some more
I guess some more realistic applications
just like some of the stuff you guys are
gonna be writing we have the mail
application on Mac os10
who's written in about 75 thousand lines
of code again you've seen this probably
rehashed a couple times now but I just
want to reiterate it because it's so
important to understand that you get
compact code size and still lots of
functionality so of those 75 thousand
lines of code 15,000 are actually
comments so that leaves us with about
sixty thousand lines of code of that
40,000 are written in reusable
frameworks now this means that they're
not specific to mail we're actually
reusing them throughout Apple so that we
write at one time and multiple
applications get to use it that leaves
only 20,000 lines of code for this mail
application that are specific only to
that mail application many of you are
familiar with omni web omni web is a
full-featured cocoa application it's a
web browser and it was written in three
hundred thousand lines of code now at
first this might sound like a lot but
I've been told by the omni web folks who
are generous enough to give me the line
counts that 120 thousand lines of code
are there only to support about five
various plugins like flash and so on so
that leaves us what half the code only
to support a couple of but you know
plugins that were in C that leaves about
170,000 lines of cocoa code of that a
hundred and forty thousand of them are
written as reusable frameworks so even
though you're noticing a theme here
where typically in cocoa you're able to
write your code some of it factored out
into reusable frameworks now Omni
actually
host this on your website you can go and
check out the code yourselves and they
address things like networking the web
HTML and some custom controls of their
own so that leaves for a full-featured
web browser only thirty six thousand
lines of code again very compact yet
full-featured okay so let's leave that's
a bit of the motivation as to why you
might be interested in checking out code
let's talk about where cocoa fits you've
seen this many times you seen at the
lowest level is the cherry flavor Darwin
pill love that we have maybe lime
flavored graphics of quartz OpenGL and
QuickTime and then like Scott talked
about we have many programming
environments one of which is cocoa its
own tasty little component so cocoa in a
little bit of detail it's it's actually
divided up into two layers we have the
foundation which typically non-ui
classes and the app kit which are the
non UI or which are the UI classes and
the app contains its graphic
capabilities from application service
which again is quartz cook time in
OpenGL cocoa is full featured there's a
lot of classes here in fact there are
two hundred and twenty or so classes so
we don't have time to talk about all
today some of you have already picked
these up if you go to Hall two there's
these references that you can use I
guess they're cheat sheets just try and
hide them conspicuously on tests so
again we're not gonna have time to talk
about all this today and I just want to
point out what some of the stuff that
we're not addressing today are Coco's
again broken up into the foundation and
app kit layers apke addresses things
like windows and views graphics and
imaging events and system interaction a
number of classes for text handling
which are showing off in the earlier
demo then in the foundation level we
have classes for basic storage and
collections abstractions for dealing
with file input and output for dealing
with operating system mechanisms such as
processes and threading and networking
and communication and then some others
ok so let's dive into the foundation now
in detail
at the root of the foundation is a class
called nsobject in fact you'll notice
that all classes and Coco's start with
the letters NS brief history lesson this
actually stands for next step because
Coco was a next step technology so maybe
this is a lesson for including company
names your API is I don't know
foundation again is below the UI level
and it provides basic classes for
storage and collections operating system
abstractions to make dealing with the
operating system easier and our core
support for internationalization and
localization and while I talk about the
foundation I'm also going to touch on
some topics or which are important at
that level and in particular memory
management and the concept of
immutability so we have basic storage
and collection classes for things like
values and s strings which store unicode
strings and it's data for storing a bag
of bytes collections that you're
typically used to from CS type classes
you know arrays dictionaries and sets
and what's important about these are
that there have very consistent api's
and they can be written to files as
property lists now let me explain
property lists a little bit because
we've only been talking about XML in
that property list Oh property lists are
basically a simple object graph that we
use when we write out two files and
these are defined using the format is
defined using XML in fact if you're
interested the DTD is on the system now
property list our deal is a small
flexible data store for that reason has
been mentioned a couple times now
they're used throughout cocoa and Mac OS
10 for things like user preferences and
configuration files now we also have
abstractions for dealing with the
operating system and I use the term
abstraction a lot today and what I
wanted to find what I mean by that we
have it that's by extraction I mean we
have a higher-level interface to gaining
access to this functionality it doesn't
mean that the functionality is any less
powerful it just means that it's easier
to use now we have abstractions for
dealing with the operating system such
as threads and locks for doing file
input and output things like nsurl and
its file handle for dealing with files
we also have classes that help you do
networking communication and for
accessing system information now there's
lots of classes and functionality here
but if your needs are exceptional you
can always use any system level
framework or POSIX API for instance so
that again Koko is not a standalone
product you can use it with other
components in the system
internationalization is very important
in Mac OS 10
obviously we're able to ship seven
languages simultaneously the way we're
able to do this at in the coco
frameworks is through our support for
Unicode data which is an NS string now
those of you who are used used to using
the carbene api's may have heard of CF
string and a string is a very very
similar class it's basically just a
small shim on top of CF string so NS
string stores unicode data which means
it can support any language the unicode
can and for that reason we use it
throughout our API s instead of
basically char stars now typically
localizing your application involves
more than just converting strings you
also want to convert your images so a
stop sign in the US might not make sense
when you're running in some other
language or some other country so you
need to localize things like images and
in fact your UI so NS bundle provides
our support for that and this bundle is
just a resource loading mechanism that
knows how to rummage around in your app
packaging system and find the
appropriate resources for the users
currently selected language it's also
just a general resource loading
mechanism but for localization this is
what you'd use it for okay so that
covers some of the basic classes and
functionality and at the foundation
level now I want to talk about some of
the concepts that apply at the
foundation level memory management is
important
Cocco does not use automatic garbage
collection however it uses something
just as simple and easy to understand it
uses reference counting so the basic
idea is here that when you send an
object or retain message that adds a
reference to the object when you send it
a release that decrements the reference
to an object when the reference hits
zero the object will get de-allocated
now the basic rules of our memory
management is simple by convention only
creation methods return objects that
have a retain on it all other methods
return objects that temporarily don't
have any references if you want to keep
that object around you send it to retain
when you're done with it send it a
release and again once it hits has no
references it goes away
mutability is also a very useful
important concept at the foundation
level many classes in the foundation are
immutable classes which means that they
can be modified or we have some that are
immutable meaning that they can't be
modified so why do we have a distinction
there's a couple reasons immutable
objects can't be modified which means
it's safe to pass them around I can pass
you in an immutable array safely if I
know you can't add objects to it I might
need to know that it's not changing
which means I can also return immutable
arrays from from my API to external
clients and safely know that they won't
be modified immutable classes could also
have more efficient algorithms if I know
an array is not going to change I might
be able to do something more efficient
in my implementation however the
drawback of course is well it can't be
modified
not much used to pass around rays that
you can't add things to so for that
reason we also have mutable objects and
for that reason lots of classes at the
foundation level come in both flavors so
we have NS strings and it's mutable
string and in fact you'll notice the
same things you know similar classes at
the core foundation level mutable
classes and non mutable classes so it's
a concept that we throw at Mac O's time
okay so that covers non UI functionality
I myself am a graphics guy I love doing
graphics and we're all Mac programmers
here
who likes to do great graphics okay
everybody start okay so the app kit
again is where we have our UI level
layer and our graphics it provides the
infrastructure for drawing and handling
events and also provides many of the
components that you're going to use
off-the-shelf in your application we
have basic controls like buttons and
checkboxes advanced controls like the
toolbar and we also have standard
dialogues like color panel save panel
open panels and we have many advanced
aqua features such as drawers and
transparent sheets and again as you saw
earlier today Cocco features a very
sophisticated text system so here's a
diagram showing some of the classes that
I'm going to touch on today again only
about five of those 220 I'm gonna start
by talking about NS application because
everybody's running application so
everybody has exactly one instance of NS
application now this application is
important because it manages the or your
connection with the window server the
window Center it'll set up the
connection and when the window server
receives events
it'll dispatch them to the application
who then will appropriately forward them
off to whoever needs to get them and
this application is also important
because it allows you it gives you hooks
to customizing typical application
behavior so for instance if you need to
customize something and do something
special in an application determination
there's hooks for you to customize that
behavior ok everybody has an application
so they got an NS application everybody
also typically will have windows and a
window is the guy who reserves screen
real estate and provides you a place to
put your topmost view and this window is
also the guy who application will
forward events off to and then it will
figure out based on the event who needs
to receive that so clicks go to the view
under the mouse key events go to
whichever view currently wants to
receive keyboard events there's some of
the magic that you heard Scott talked
about we can just
these keyboard events off to dine you
know dynamically figure out what object
wants to handle keyboard events and
again and it's Windows where you'll find
our support for advanced features such
as drawers and transparent sheets and
it's view is where you're gonna do your
drawing and as view handles lots of
details that you don't want to handle so
some of them might you know really enjoy
this stuff but typically most people
don't want to worry about managing the
view hierarchy worrying about coordinate
system transformations view to screen
transforms or worrying about clipping
this all done for you and Coco also
Anna's view provides basic UI
functionality that you're used to having
around like drag-and-drop
context-sensitive menus and help tags
again off the shelf there are many
instances of edits view that you can
just use in your applications such as
and it's text view which you saw Doug
use earlier or in this movie view which
plays QuickTime movies and there's a
number of other views now if you want to
make your own view that does your own
whiz-bang custom really cool drawing all
you need to do is subclass and it's view
and override the methods that you're
interested in so if you want to draw
which you're all gonna do you override
draw a rect if you want to handle mouse
down events you override Mouse down any
other event that you want to handle you
just override that method in order to
handle it and it's to use where you do
is where you do your drawing and Coco
provides you lots of options for drawing
in particular we have and it's Bezier
path which allows you to do path based
drawing lots of things that you're
familiar with the past bate drawings
such as curved a point stroke fill set a
dash pattern in us image is our class
that provides an abstraction over images
so we support images like TIFF JPEG
bitmaps anything else that you typically
would expect QuickTime to support and
the nice thing here is that it's an
abstraction on images so we can add
support for new images in fact which we
have in past like PDF and your
application gets that new functionality
without even knowing that it existed
previously we also have the ability to
drawstrings the strings know how to draw
themselves a class I haven't mentioned
yet is NS attributed string that's our
abstraction on styled text we also have
abstractions for colors and fonts and
again in the past we've added
functionality for things like pattern
colors or true typed to type fonts and
we've done this without changing the API
in those classes so clients have been
able to pick up new functionality
without having any idea that it would
have existed at some point in the future
and if you need to do your own graphics
transforms we have NS affine
transformation now there's lots of
options for drawing but if your needs
are exceptional you can always use
quartz drawing again cocoa is not an
isolated component it can be used it can
use other components in the system
Sony CG functions can be used at this
point I like to bring it Doug back up on
stage he's gonna give you a demo on how
to actually cellquest Emmet's with you
how to draw and how to handle events
done thanks Jeff okay this time I
promise we're actually going to see some
code so what we're going to do right now
is what might be the beginnings of an
image editor perhaps we'll draw an image
and we'll allow the user to click and
drag to make a rectangle selection so
I've already created the project for us
and you're an interface builder instead
of a textview I put in a custom view and
set it to be my custom subclass of NS
phew and back in project builder let's
take a look I've added a few lines
already to the implementation of my
custom subclass actually just two
methods for demo purposes I have
hard-coded a specific image now really
the only interesting line in this code
so far is this one and this is an our
draw rect a custom draw rect method and
what this line says is that we want to
draw the entire image in our entire
bounds and that by itself is enough to
draw the image but we also want to do
the click and drive selection thing so
let's add some
first of all I'm going to add a couple
of instance variables to keep track of
where user has clicked to dragged
keep track of the start point where the
user started to click and the end point
where they track to and next what I need
to do
is add just a couple of methods to keep
track of those things so first of all I
have my mouse down method that's going
to be called automatically when the user
clicks and all that this method does is
to set both the start point and the end
point to the location of that mouse
click
in our view coordinates and then we say
that we need to read redisplayed and
then we have another method mouse drag
which will be automatically called when
the user tracks and all that does is to
set the end point just the end point to
again to the location the mouse was
dragged to in the views coordinates now
given these two points it's fairly
straightforward to compute the rectangle
that they determine and I have a little
function that does that too
it's about as long as the rest of the
covetous and I'm actually I'm going to
insert that
I don't want to go through that and the
final thing we need to do is actually
draw that selection rectangle so I'm
going to add that to our draw rect and
what this is that if the start point and
end point are not the same then we set
an appropriate color in this case red
and create a fuzzy a path in this case
the path is just a rect being the rect
determined by those points and Stroke it
simple enough let's see if it does
let's try running it
now here's our application draws the
image that I've hard coded you notice
again it scales nicely automatically no
code needed for that and I click drag
there is my selection
[Applause]
thank you again dougie
okay so now I've talked about Anna's
application and this window and ennis
view and the attentive ones in the
audience have noticed I've skipped one
class that's everyone right
and it's responder is the common
superclass of all these classes I've
already talked about and the reason is
they all share some similar
functionality in particular all honest
responders can receive events and again
events in KOCO arrived as methods so if
you're interested in keyboard events
your subclass of NS responder will
override the keydown event key known
method excuse me
NS responder also introduces another
important concept called the responder
chain and every subclass of NS responder
can be in this responder chain now the
responder chain works like this
every window knows who its first
responder is every responder knows who
its next responder is and so on down the
line and so this forms a responder chain
what will happen is when events come
into the system they get dispatched
typically to the first responder if it
doesn't want to handle it it gets passed
down the responder chain until it finds
someone that wants to handle it
so typically you're probably not
interested in knowing about actual very
low level events like mouse clicks or
keydown events you're really concerned
with was this button clicked or MIT was
the slider manipulated things like that
this is where enough's control comes
into play as you can see NS control is a
subclass of NS responder and NS View
which means it inherits lots of
functionality from these classes however
NS control has some important
differences and as control is defined to
something that's typically triggered or
activated by user action again
button clicks on a button click on a
button examples would be NS button and
its text field or more advanced controls
even like outline views now again I said
it inherits lots of functionality but it
also has some important differences
every control has a target object in an
action method I'm gonna get into this in
detail in a little bit so let me just
leave that for now
controls also have values that can be
queried so I might need to know that the
sliders current value is 0.5 or that a
text fields current string is something
rather also since controls are typically
things that I can click on I need to be
able to enable them and disable them so
control has support for that target
action is a very important concept in
cocoa and this is what makes some of
that magic that Scott Forstall was
talking about earlier possible the idea
here is that when a control is triggered
it has a target that is going to tell I
was triggered so the target object is
the guy that gets sent an action method
in cocoa targets can be nil and when the
targets nil the message will go to the
first responder and again if the first
responder doesn't implement that action
method it goes down the chain until it
finds something that wants it so this is
how cut is implemented in cocoa
typically when the user clicks on
dragged clicks and drags down to the cut
menu item we haven't actually hard-coded
in a target the targets nil and so what
will happen is the frontmost window its
first responder will get a cut message
if it doesn't actually have my cut it'll
go down the chain
until it finds your custom view which
implements the cut message so again you
can imagine how how much you know gory
detail and management you'd have to do
if you had to actually manage who the
current target was and keep track of
what windows in front we it that's all
taken care of you through the beauty of
the first first responder responder
chain and target action at this point
bring Doug Davidson back up on stage and
he's going to show you how target action
works in KOCO thanks Chuck so this time
we're going to build on a previous
example and we're going to add an action
method to our custom view and to do that
we're going to pay a little closer
attention to scaling so I'm going to add
you
a little bit more code here
now first of all I have one method set
scale that will set the scale on our
view to some float value now in cocoa
every view has two rectangle parameters
one is its frame which determines it in
its extra in the external coordinate
system and the other is its bounds which
is determines its size and the internal
coordinate system so to scale this view
all that we're doing is setting the
frame size to be the size times a scale
factor and setting the bounce eyes to be
our original size just a hard-coded size
of the image and again saying that we
need to be display and also when we get
loaded we want to set the default scale
to some same value one now our action
method is this one called take scale
frog and what that does is to set our
scale based on a value determined from
the sender of the action method in this
case we're going to have the sender of
the action method be a slider and the
value of the slider is just determined
by the position of the slider so the
slider will tell the view what its scale
should be
let's take a look at
our interface and interface builder now
we're going to take our view and I want
to group it into a scroll view so we
make sure we can always see it and make
this window a little bigger this thing
around a bit now here I'll get a slider
drag it on position it the way I want it
and set some nice values for it to close
from 0.5 to 1.5 and it starts at 1 now I
need to hook this up here's the magical
interface builder 1 to Graig saying that
the target on my slider is my custom
view and the method that's called this
takes scale from let's see if this will
build
let's try our application again
now you see we have our slider and the
slider tells the view not a ticket scale
if it's too big we can scroll around you
just don't make our selection we're all
set thank you very much let me show you
that Doug doesn't normally program using
stickies some of the beauty of what you
saw here was that because again
objective-c has very good introspection
interface biller knew that it has these
methods that it can wire together so
we've talked now a lot about classes and
specific functionality and although
that's some of what makes par cocoa
powerful it's some of the it's some of
the concepts that we use in cocoa which
make it really unique and powerful so I
want to talk about in particular some
design patterns that are used throughout
cocoa in particular the notification
notifications sometimes referred to as
the observer pattern delegation and the
model-view-controller paradigm
notifications are a way to broadcast
happenings throughout an application or
even to other applications now those
interested in knowing about happening
will register as an observer typically
in cocoa some of the things you can
register as observers for our tell me
one a window will close or tell me when
a text did begin editing however you
wouldn't expect notifications to be used
for really low-level things like this
did spin or something like that so
observers have to register with somebody
to say hey tell me when this event
happens that guy is the notification
center Notification Center is sort of
the glue that makes notifications work
what happens is observers register with
noticing with the Notification Center
telling them to name the notification
they're interested in and the object
that they want to monitor and also they
provide a method to be called when the
notification is posted
now you don't actually have to tell it
what object you want to monitor you can
say the object I'm modern King is nil
and when you do that you say I want to
monitor all objects for a particular
notification so I might want to know
when any window in my application closed
I do this by specifying nil posters are
the ones who post the notification they
post the name and any additional
information which may be valuable for
instance what windows closing delegation
is a powerful design pattern that allows
one object to act on behalf of another
typically it's a way to provide you a
way to customize an object's behavior
without having to subclass so NS
application has a number of delegate
methods one called applications to
terminate an application soap and file
so if I want to customize my
applications termination I provide a
delegate who does some special work in
applications should terminate ok so at
first notification delegation somewhat
sound like similar concepts and they are
because you're sending messages when
things happen but they have some
important differences with delegation
there can only be one delegate per
object much like with the Highlander
there can be only one however there can
be many observers and because of this
you'll notice that with our api's
delegates typically received messages
they're allowed to affect behavior
because there's only one however
notification observers will receive will
or did type messages there's no way for
you to affect it so let me give it a
sort of a contrived example of making a
US law in this example the house makes
the law and we'll say the president's
our delegate in this situation because
he's allowed to veto the law when he's
asked should the law pass now once the
law finally passes all of us out here as
notification observers learn about it
through the notification law did pass it
did pass we don't have any way to affect
it of course there's always voting but
we know sometimes that doesn't actually
work in all places
okay so another design pattern that we
use throughout KOCO and has already been
mentioned a couple times is the
model-view-controller paradigm in this
paradigm the model stores the data
however typically it's more than just a
simple data store it knows how to
perform intelligent operations or
business logic or things like that on
the data however it's separate from the
view it doesn't know any particulars
about any view that it's being displayed
in the view knows nothing about the data
it just knows how to display typically
some simple types but it's separated
from the the model and the control is
the guy who will tie the two together
again implementing things in Model View
controller is a lot of you probably
familiar with will make it your
application more flexible easier to port
when you need to change UI classes and
so on so I'm going to talk a little bit
more about about it in the next couple
slides and I'll usually talk about it
and just call it MVC okay so I'm going
to hit on a number of application level
topics some which MVC effect and some
which are just application level topics
that you'll be interested in when you're
developing your application in
particular if you're writing a document
sort of application Coco has a wonderful
document architecture that you be
interested in knowing more about every
application on Mac OS 10 should have
undo support and be scriptable and
typically you're going to want to be
able to talk to the clipboard or have
preferences in your application
okay document architecture it provides
you a number of standard features that
you want to have in an application that
works with documents as you saw earlier
in Doug's done we had a document based
application that ran open panels and
saved panels for us we didn't we didn't
write any code to do that it also
manages manage the document edited
status again these are mundane things
that you typically don't want to have to
reinvent now for you to make a docking
base Taplin all you're going to have to
do
provide routines that can load and store
the data again
stuff that we didn't do in the earlier
demo but you provide the custom logics
to do that undo is very easy to do in
cocoa and for that reason every
application should be undoable in fact
every cocoa application as you heard
before already has undo support in
particular the text system has built an
undo support and if you need to add your
own undo support all you need to do is
that when your model changes you
register an undo operation with the NS
undo manager and against this undo
typically wants to be registered when
your model changes a good separation of
your model and view will make undo easy
for you to implement scripting is also
very easy to implement in cocoa and
again that means every applications
should be scriptable cocoa provides a
lot for you already we handle events
from the Apple script standard suite
such as open print and so on the text
system provides a number of the classes
that you need in the text suite and if
you need to add your own support for
scripting which you're all gonna do you
don't have to do a lot of work you have
to edit a P list which again is this XML
based file format and you need to write
a method or two so it's very easy to do
and again since scripting acts through
interfaces through the model a good
separation of the model and the view
makes scripting easy to implement
typically your application also wants to
have preferences when you when you need
to store preferences to disk or read
them from disks you can talk to the NS
user defaults object
it stores preferences per user per
application it also allows you to access
system preferences so anything you see
stored in the system prefs application
you can access through NS user defaults
and also if you have a suite of
applications and its user defaults
allows you to share preferences between
them if you need to implement cut copy
paste or something similar you need to
talk to the clipboard or provided data
right and it's pasteboard is the object
that gives that functionality in
particular the data can be store can be
provided either immediately or in a lazy
fashion and of course we all prefer to
be lazy because if we have some huge
data we don't want to have to compute it
if it's never needed and as pasteboard
also has filtering services so that you
can convert to the requested format and
in fact we provide conversion of mac os9
types for you automatically ok
we've covered a lot of stuff today I
made this thinking it might be earlier
in the day I guess it's actually time to
eat what I'm hoping you take from the
talk today is that cocoa gives you lots
of functionality you don't have to
re-implement mundane tasks that aren't
interesting to you and don't add value
to your product you get spend time
working on features which will help sell
your product cocoa has lots of powerful
concepts more than just the classes and
the functionality of the classes we have
powerful concepts that we use which make
cocoa unique and powerful and again I
love free stuff and cocoa gives you lots
of it so it's day one and we've got a
lot of sessions left if you're
interested in cocoa in particular I
would highly recommend going to the
using cocoa talk there will be lots of
code demos there we didn't show a lot
today we're gonna show a lot more there
the advanced cocoa talk is actually for
beginners too cocoa and cocoa experience
folks so everyone should feel free to
attend to that and if you have feedbacks
come to the feedback session on Friday
there's also a couple more things you
might be interested in
the project builder talk coming up
interface builder and learning about
things such as nsurl again one of these
foundation classes that I talked about
there's lots of documentation on your CD
the first thing I would recommend
checking out if you're new to cocoa is
the concepts documentation because that
again is what what I think makes cocoa
unique and really powerful there's lots
of information elsewhere there's zero
O'Reilly book that you can go grab and
actually there's lots of cocoa
enthusiasts out on the net that provide
things like mailing lists and FAQs and
free frameworks again Heather Hickman is
your contact for anything cocoa there's
a new cocoa development mailing list
that if you're doing cocoa development
you should look into subscribing
you