WWDC2004 Session 409

Transcript

Kind: captions Language: en ladies and gentlemen please welcome frameworks engineer Chris Parker thank you welcome to session 409 what's new in cocoa it's gonna be a fast hour so I'm gonna get right into it my name is Chris Parker I'm a cocoa frameworks engineer for the last three years and we're starting with a familiar formula here what you'll see is everything that we've done in cocoa so far for Tiger in both the app kit and foundation we'll be covering a lot of new features a lot of new significant API changes or behavioral changes we're gonna skip the bug fixes we're gonna hope you guys are all going to get out there and read the release notes for those we'll talk about some usage patterns for some of these new features it'll also give you some pointers to other sessions there's a lot of stuff in here with a lot of new api's that actually are implemented in some other places so starting up with the app kit in Panther there was some enhanced printing support to support things like the number of pages you could put across the page or down the page or start and end pages and collating settings and things like that we've added some automatic support in the printing system in Cocoa so that existing applications will get some of these new features but if you really want to do it right there's a new application delegate method on NS application application print files with settings and show print panels and this will give you an opportunity to be able to get information about what you're being told to print and you'll be able to return a value that says hey this printing up operation succeeded it failed its printing later that kind of thing there's also an it's document enhanced printing support so if you're an estimate sub classes you can do print document with settings show print panel there's a delegate object you can pass in a selector for did print selector and your context info pointer that you'll get back when you get this delegate callback the settings dictionary should be applied to the NS print info for the print operation and there are keys for print pages across pages down what time to print the printer name to print on there's a lot better fine grained control in Cocoa now over the printing mechanism that you get for the information you get from from the finder or other places and this document now also has support for dynamic document type so a lot of applications are being written now using bundles to do all of their reading and writing which means that they can extend the number of the kinds of documents that they can read and write there are a number of different ways you can represent those documents so you can override using to do this using a customer out put type customizable output type you can override writable types for save operation and you'd use this to limit those types so if you've got something in the window that can only be represented as an RTF D you probably don't want to write out RTF you can return on NS array containing RTF D from this so some data may not be represented you can control what's actually shown in the UI when you write this out and it's document now and in a lot of places throughout the applicant the app kit and foundation you'll see this is now more consistently using NS error so there are new methods with error parameters so in it with contents of URL of type and now this by reference error pass if something goes wrong will tell you what went wrong in that NS error okay also write to URL of type with error there's an error parameter on that also again you pass it by reference we'll try and tell you what went wrong we're using nsurl as our locator more consistently throughout foundation in the kit so you probably won't quite see so much in it with contents of file you'll start seeing a lot more in it with contents of URL okay we've seen it in mail right you're typing away on your email message and it saves it periodically in the drafts folder you might have three or four drafts going on and it's document now supports this kind of auto saving directly so periodic auto saving of documents you can chain you can set how often that autosave is going to occur using set auto saving delay there's a new NSA vous operation type that you'll get told about when things happen and there's also because the auto saving mechanism drops a copy of the document next to the one you've got initialize that there's an initializer for customizing the reopening of a document so if you want to say oh you've got an auto saved version here you can in it with the URL but the contents are going to come from that auto saved document okay and again we're providing in it with URL with in it for URL with contents of URL of type error and that error parameter is going to have as much information about what may have gone wrong as possible one of the things you see in mail is as you've been working you quit mail all those messages come back when you fire it back up again and this document now supports a thing called fast logout so if you're a if you're an assassin out of saving you can also get fast log out of support automatically so when fast log out will come along it'll quit an application with no UI it'll save Auto it'll auto save the modified documents and then when they're up when the application launches again it'll open all the autosave documents for you right where you left off so when you log out quickly all this stuff comes back your Nana's document app they look at most of this for free we've put new controls in the kit this is an NS level indicator there's a control and a cell variant of this there are relevancy indicators it's the top one here so if you're displaying search results you'd use the relevancy indicator a capacity indicator how full something is the discreet capacity indicator so it fills up in Quantum's and a rating indicator so just like in itunes with the stars and the dots the rating indicator here lets you do that and it's customizable it's customizable four tick marks it's the small and large ones kind of like the sliders capacity indicators do automatic critical and warning values so they'll turn yellow or they'll turn red as that fills up and gets closer to that that you know running out of disk space indicator the ranking indicator also supports custom images both for the filled in rank and the the not yet filled in rank so if you got seven out of ten you can have seven stars and three holo stars however you want to do that there's a new NS date picker control I lost the bet I thought the applause was going to come later there's a control and cell variant of this it's object value as an NS date it's customizable so from what you're seeing here you can edit and you can control what things you can edit what things you're not going to edit as well as enabling and disabling display of elements of the other picker they're arranged constraints you can set a min value in a max value and it also has full calendar locale and timezone support and we'll talk about some more of that in the foundation talk in a minute and there's also an additional two opportunities for you to validate the date that's in there from a delegate method and also again you've seen it in mail and it's token field there's a control and cell variant of this as well so as you type you can set it tokenizing character and I'll break it up into those nice little blue lozenges that appear in the in the field so it behaves a lot like males address fields it supports text completion this is actually a text view you can set your custom character sets for tokenizing you can also set represented objects so if what you're putting in here really isn't strings you can set the represented object for each token and then have a string representation for it show up here and when you drag it to the pasteboard there's actually support for putting those representative objects on the pasteboard there will also be support for menus coming up so you can attach a menu to these tokens and drop it down and put your own actions on those and we actually have a very short demo here of these to walk all the way across this huge stage though so the new UI elements many of them are bindable out-of-the-box I suppose I should look at the smaller screen in front of me and the level indicator this is the discrete capacity level indicator and we can set the warning value and the critical value here somewhere up higher as I move the value slider up you'll see that as I cross the 50% mark within each bar it fills in right and as we get up here close to the warning value it crosses over into yellow and then turns into red so we've now completely run out of space here and have to go buy another hard drive the date picker so this is just three date pickers dragged out on from from the interface builder palette and I can set the minimum date here let's let's bump the the year up a little closer to something we've got now and pop this maximum date down and as we adjust the the date and the main date picker we can set the maximum minimum values and they clamp so as I try and exceed the values there it automatically stops for me and the delegate would have an opportunity to to handle these as well so and finally token field and token field actually is pretty slick if we launch TextEdit here just so I can have this up as well as I type the default token field is set to use comma as its separator so this let's see get a email address here and we have the tokens I can drag these tokens around within the within the token field and if I select them all I can drag them out onto the paste on the pasteboard into TextEdit and all of this stuff just happens automatically this is nib where here I've got a my main menu nib that just drags these out as a custom class for token field and I did a little bit of binding stuff here for date picker and for indicator cell and the setup for token field is actually pretty short so we could go back to the slides please so as our you eyes become more dynamic we need support for NS animate we need support for animation specifically in cocoa and it's animation is the class that supplies that so this provides timing for animations in cocoa it does some other things for it but it's mainly about timing there are three modes for this blocking non blocking and non blocking threaded so a blocking animation everything's going to stop all the animations are running okay so the non blocking animation runs in the current run loop other events are happening as it goes and the non blocking threaded means that will spin off a background thread and do the animation back there for you well other stuff is happening in the foreground there's also API that supports animation progress frame rate control as well as the curve so if it's going to go it's going to proceed at the same rate all the way across the animation or if it eases in and out you know it happens really slowly at first speeds up and then slow slows down again at the end so there's a the progress API uses a thing called progress marks so they're checkpoints for animations and you set the progress marks via this progress marks and set progress marks API you provide an NS array of floats and as the delegate as the animation proceeds the delegate delegate will get callbacks as it crosses those marks so you know when you're happy if you set up animation progress at 50% and at 75% you'll hit those and your delegate callback there are also notifications for these as well that you can listen for for Moranis animation NS animation also allows you to link animations so once you've got the progress are set on a particular animation you can synchronize them using start when animation reaches progress and stop one animation reaches progress so you can say that this animation should only start when that one hits 25% and it should stop when the other one hits 75% to do this with views a lot of the view animation stuff is pretty common you want to do frames and and and ease things in and out and do cross fades and this NS view animation subclass is how you do that so there's a dictionary that defines the view animation behavior you set a number of different keys the target key the start frame key the end frame key what kind of effect you want whether it's a fade in or fade out and this can change the frame and opacity and it can be applied to both views in Windows you initialize them using an array of view animation so you can have five or six different dictionaries that represent the view animations and you can also set them so if you have an existing animation it's a mutable class you can you can change the array of animations and we actually have a quick demo of this as well I had to switch projects close that so on the demo controller now there's a tab view in that nib and down here in demo controller M we do some calculations at the tab you did select tab view item delegate moment and after calculating the start frame and the end frame and things like that we set up here the animation parameters in a dictionary so the window is going to be the target will have a start frame and an end frame we'll set up the animation mm-hm I set the blocking mode in the duration it started so running this now as I shift from level indicator to token field we're starting and ending the frame and in about four lines of code we've got that nifty effect from system preferences and this can also do all the crossfade opacity so if you're fading out to something it'll actually hide the window or the order the window out or hide the view automatically it's like the next slide please we're starting to see with those gorgeous 30 inch displays that they won't let me have resolution independent UI and we'd like to be able to do here is allow the user to set the scale of the interface to be as larger as small as they want and they can make the trade-off between detail versus screen real estate if you're like me and you want everything really really small you'll be able to do that if you need the windows a little bit larger you can scale that up this is independent of the display resolution okay but what does this mean for you guys it means that you can't make the assumption anymore that one point is equal to one pixel okay so the scaling factor is going to affect some of the rectangles and events that you get in the kid there we go Cocco implements what we call framework scaling and the short answer for this is we're gonna do all the heavy lifting for you so when you set a scale factor you'll be able to have us do all the view scaling automatically windows and screen coordinates will continue to be in pixels so when you're sizing your windows that's in actually the screen resolution view coordinates are in points so it's really important now more so than it ever used to be to make sure you're using the correct conversion for view to window coordinates or going the other way if you're adding an auxilary review there a couple places where you may have been doing this and just sort of getting away with the fact that it was one-to-one and you'll actually I'd to be very careful now about the height of the view versus the window that you're putting it in to resize the window correctly and making sure that you're getting when you get event locations you do the translation in the view coordinate system correctly there's also API to be able to get around this and do what's called application scaling where you'll be able to control this on an individual view basis that's we're actually recommending that you let us do it if you were here for the core graphics talk I think they actually mentioned this quartz debug now has a user interface resolution window so if you fire up quartz debug and you go to the window menu it'll have one of these in it this represents the scale factor for pixels per point okay and actually taking the screen shot is a lot easier when you bump the whole thing up two to one and a half but these are applied to applications F launched after the change so you can set this up and then go ahead and run your app and code run you're out from the command line and from the finder and this will actually let it show up with a larger menubar and bigger windows or if you're like me smaller windows and it's bitmap image rep now has new support for additional image formats so we're not just handling premultiplied rgba anymore we now a floating-point 32-bit samples can now take alpha as the first portion of the sample order when we read these images in it also deal with non premultiplied images and there's also JPEG 2000 support this is probably the longest method in this entire presentation I don't think it's the longest method and the kit get them in it with bitmap data planes the the important bit down there is the NS bitmap format bit field that actually lets you say things like I'm loading alpha first or I'm loading a different format and it's graphics context you can now specify compositing operations in NS graphics context so these are saved and restored along with all the other operations of saved graphic state and restore graphic state may have no effect on existing things that already take it's a composite to point with operation that that's already handled but this allows you to set the compositing operation for Jarrah's NS view now supports drawing redirection and panther views drew to Windows or for printing and things like that that's pretty much the only place you could draw now you can draw view hierarchies any view hierarchy to an arbitrary NS graphics context so be able to take something like your dialog grab it into an NS graphics context and put it on top of an OpenGL view or something like that and incorporate that into into other user interface elements that may come from other places so use display rect ignoring capacity and ignoring opacity in context you can get bitmap image rep for caching display in R X that'll return a caching appropriate bitmap image rep and cache displaying erect to bitmap image rep you can take the rectangle for a given view and slam it right into that in that bitmap image keeping up with an SVU NS window we have new resizing support one of the things that you do when you resize a window is that you're really only dirtying that l-shaped portion in the lower right in the right-hand side so you're not dirtying the entire window so we probably shouldn't draw the entire window so valid contents is preserved in a drag and a live resize as long as it doesn't move relative to the upper left-hand corner of the window so this is enabled by default for windows so when you drag out the windows and you'll you'll get this behavior you can find out you can opt out of it using set preserves content during live resize tell it no you can find out whether it's doing that or not you can disable it but it's disabled by default reviews rather so if you override preserves content during live resize to return yes then it'll start doing this behavior also but as you're resizing all this stuff you're going to need nowhere to draw so what changed Rek preserved during live resize is that slot that didn't change it's that section that didn't change get Rex exposed during live resize you'll get an array of four rectangles the at the present in the seed you're only getting at the bottom two but at most you may actually wind up getting all four if the view can be moved if the view inside can be moved into the middle of the window so this can be called anytime during live resize and I'm after set frame size or before the recursion display the view hierarchy so you've got this window where you can actually work with it and this window now automatically calculates the key loop so as you add a view it's got a bunch of sub views it will automatically recalculate this for you you can change this behavior using set auto recalculate ski Lu key view loop and there are some accessors there also you can also tell it immediately recalculate the key view loop now adding views to the window recalculates the key loop so it will do it right when the window is first ordered in and if you don't set the initial first-responder it's it's the same as the default and it's based on the order of the views in the window so if you've been adding things and it'll do it from that order and it's workspace moving a little bit into the file space now custom icon creation set icon for file options this supports transparency so if you've got any NS image it's got some transparency it's got some nice effects in it this will allow you to set an icon on a given file there's some compatibility options not all of our releases the operating system support all of these icon formats so if you tell it to exclude quick-draw like on creation then it's only going to be visible the icons only be visible on 10:4 if you exclude the ten four elements then it'll work everywhere but you won't get the spiffy larger icons and this supports things up to two 256 by 256 so in Panther there were tablet events but tablets - Coco really looked like a big special Mouse and now in in Tiger we've introduced explicit tablet events support so native tablet events for Tiger so you'll get actually proximity event so as the pen approaches the tablet you'll actually get the event that says oh it's getting near the tablet tablet pointing events explicit for that also there are subtypes for the mouse events right click left click stuff like that and pointer type support so a lot of these pens have both a pen tip and an eraser right so you're actually gonna be able to tell the difference between those in the event hierarchy there are accessors for most of the common tablet properties these are things like pressure right so when you when you stroke the pen you actually can find out how hard the user is pressing on the yeah on the on the tablet you'll get XY absolutely XY & z positions they also find out how whether the pen is tilted if it supports that rotation tangential pressure and these are their anis responder methods for tablet point and tablet proximity so you can hook this right into the responder chain and handle those at a higher level than the view that you may be looking at so NS tree controller hierarchical data structures the API parallels NS array controller so if you've got things that are that are a tree structure you can now do tree binding with this he uses NS index pass from foundation we'll talk about that in a minute that defines how to find something in a tree the content can be set to the root of the tree of the model object so you just hook this up right to the root and it'll it'll worry about finding all the children and it uses KBC to find the children of the model object so set children key set count key there's a an opportunity for performance there insert object to arrange object at a range object index paths you can provide that so that you can insert objects into the tree of specific locations the implication here is that this is the mechanism at NS outline view and NS bruh are used to be now fully bindable if you've been waiting for that this is your big chance and as tableview now has better Auto resizing support for its columns so we actually take into account things like proportional resizing for initial positions of columns SEC column Auto resizing style there's a flag that you can set on that we now support custom tooltips and then this table for you so if you want different tool tips on different cells and rows you can get those now by having your delegate returned and appropriate string from table view tooltip for cell rect table column row mouse location it's still shorter than that one for Menace bitmap image wrap and finally an NS table View variable row Heights and Tiger so your delegate can actually say that the height of the row is a specific float and you can note that the height of the rows with a specific set of index has changed so and its toolbar item now has some automatic validation techniques it used to be the toolbar relied on NS window and window updates in order to do its validation work and now validation can be done in a per item basis so you can set individual tool items to say yes this auto validates notice doesn't you can also avoid overflow with NS toolbar items in some cases in your toolbar you may actually want a particular button to be on the toolbar all the time right so when you resize the window and that overflow menu gets generated you can actually make sure that some items will always be visible but in keeping with our theme that the user is king here the users may want different items visible themselves so even though you may want something up jammed up there all the time they may want something different there are some priorities you can set using set visibility priority the visit the standard low high end user priorities ok the user one is the most you should not use anything higher than that you can define any range in here these are defined in the kit headers you can take a look at it but standard means that basically you're letting us do it if you assign something low it will be one of the first things that gets pushed off in the in the overflow menu and if you do something high it'll stay up and not get not get overflowed so how did this slide wind out there and a spawn descriptor is now the primary font reference for the kid and this replaces postscript font names as the method for matching and substitution as well as we do we do cascading with this now too so you can set up different font descriptors representing various attributes without necessarily having to specify the font itself texting controls now support based writing Direction support this is baseline this can be specified in individual controls there's IB support forthcoming for this so that if you're fortunate to have localizers working for you they can set the writing direction on the controls in the various nibs the default setting is the natural writing direction based on the content so if you've got a string that is in a space that would be right-to-left this will get picked up in that way automatically you can set it explicitly using the base writing Direction accessors and specific ranges and you can also change the base writing direction it'll toggle back and forth NS text view now supports multiple selection so there are new selection primitives in the text system for multiple ranges there are also some new delegate methods and they take arrays of ranges rather than just them in this single range there's a new fine panel action too you can also have the fine panel actions are hooked up to do things like select all of the things that match all at once existing methods if you've got code that is going to operate in a textview that has this attribute set it'll return the first sub range so things will continue to work for you you're only going to find out about the first sub range it's selected in all of these the text system now supports tables so this is actually TextEdit with an HTML imported table here and this is handled through some new classes as well as lists text system also supports lists the tables new classes are NS text block and NS text table block the lists allow you to do things like customize the marker format so you can have one dot or you can have a bullet or things like that these appear on attributes on the paragraphs and they're also conveniences for these NS attributed string so you'll be able to pick these out of your strings and render them how you like but the text system will take care of all the tables and stuff for you now we've also started to incorporate and keeping up with spotlight and things like that new document metadata so there are new document attributes in our RTF files that we support in the RTF reader for title what company subjects authors if you're fortunate to have an editor who takes a look at your stuff you can set the editor document attribute type all of these are available to check for in the spotlight api's as well as right off the document attributes and it's typesetter I'm taking a lot of the stuff that was in the 80s type side of the Apple type system so types that are moved it up is to the defaults that types out our system now in in Tiger and you'll be able to do things like applicant concrete subclasses with your own layout engines and there's new access to a number of ranges and attributes I could talk for an hour on the text system but personally I don't know enough about it and you guys don't have an hour to sit here for it but there's another our advanced development with cocoa text session 437 on Friday Doug Davidson will be talking about that and he'll go into all of the tables lists and everything for for cocoa text so let's talk about foundation move down a step foundation now includes a new class NS XML document this is a Dom based API you can initialize this from strings and other types of you if you have a URL or if you have an XML if you have an NS string that contains XML you can initialize it from that you can also initialize it right off the network with an it with contents of URL there are options to set here things like fidelity and and what kind of preservation you want stuff like that it provides a Dom like model so you can find out how many children are in a particular node what the children are insertion deletion things like that it also supports a lot of querying and transformation behaviors so XPath annex query or to query formats that allow you to ask questions of the document and find out more information from that so you can actually say give me all of the nodes that have attributes of this particular value so the XPath nodes for XPath error and error will get returned to you if something goes wrong objects 4x query X Aquarius is a technology that we've been putting into things like Sherlock and stuff like that we also have XSLT support so if you have a Dom tree and you have an XSLT transform you can just ask for object by applying XSLT and you'll get back the appropriate item so that may be an X and s XML document depending on what you're asking for in the transform there is a session on this as well easy and powerful XML processing with cocoa that's a Friday at 10:30 so if you're still here you should probably go take a look at that and it's gonna be an excellent talk NS locale now with with a lot more localization information and things like that this is the preferred mechanism and foundation to get localization information out of the system so a lot of the things that you would have gone to nsuserdefaults for you're gonna go to NS locale for now there's a lot of general information that's stored in the NS locale class and it's you can ask for the available locale identifiers there ISIL language codes country codes currency codes you can also ask for all the components from a specific locale identifier and once you've got a locale you can get information from it so object for key will tell you basically the same kind of thing localization information you're getting from again from nsuserdefaults display name four key values some of these maybe localized in their particular languages and that's what this display named for key value method is for so you can get information that represents the actual localized value for those in continuing with this and it's date format or now has a number of new capabilities there are a lot more settings to configure in an estate format or you can go through and and toggle all sorts of switches in it this is also replacing a lot of the functionality you would have gotten from nsuserdefaults it's based on the CF date formatter stuff that we've got done in corefoundation that's actually based on the international components for Unicode one side affected this is there's a new format string available in date formatter so some of the things that you've been doing you'll have to change a little bit in order to get this format to work correctly so if you've been formatting dates in particular way you may have to tweak that a little bit there's a compatibility mode applications linked on Panther will actually get this compatibility information and you can set it so that the formatter behavior will act the old way versus the new way so if you've got existing code you want to make sure that it's actually going to continue to work the way you expect it you can use this set format or behavior method and this number formatter also has a number of new capabilities there are new styles in formatting you can format decimal currency or scientific style so you can spell things out actually there are a number of new settings for this for group separators whether you're showing decimal and group separators prefix and suffixes for numbers as well as text attributes for some of those values okay and this also has compatibility mode again if you've got existing code it'll continue work the old way but this is new for for tiger we spend a lot of time trying to do this we're deprecating as many c string methods that do not have encoding arguments as we can so you know you've got a blob of data but you don't have any any encoding information and Stan getting a string from that it sort of fraught with a little bit of guesswork and peril so some new methods will report errors in encoding conversion there are a lot of new methods for the C string encoding we deprecated a bunch put a bunch in with encoding support and it turns out we actually have less API than we started with so you can convert using a specific encoding using an it with C string encoding there's also string coding sensing so when you in it with the contents of a URL we're gonna pick out and try to figure out what encoding that is and you'll get an error back cool you can also specify the encoding on the output so when you write to the URL if you specify an encoding that it can't do you'll get an error back about that also and we're again we're trying to put as many places in the in foundation the kit where we're using this error parameter to be able to allow you to return more information up to the user so and that's net service has some new features one of the things that developers did a lot and it I have to admit that's partially my fault because I did it in a sample code oops was leaving the resolve open if you leave the resolve open for a long time that generates a lot of network traffic so now we're doing is we're allowing you to specify timeout for resolves so you can say resolve for five seconds usually if something's gonna happen it's gonna happen in that five seconds so if they haven't gotten a response back it probably isn't coming so there's also text record access so for whatever reason the the old gettin set protocol specific information methods are actually deprecated now an NS net service and these are what we you should be using instead set text record data and text record data you just send us data blobs there's some convenience is to shift things back and forth and s note service but this will allow you to be able to put that information out so that other rendezvous enabled applications can see that it's a little little data payload in each net service that you can put in and you can monitor those for when they change so this is actually some very similar to the mechanism that I Chet uses in order to update your status and on rendezvous and update your your status string all right you can do the same kind of thing now with NS net service using start monitoring and stop monitoring and there's a new net service delegate did update txt record data where when the remote service updates is text record you'll get the data back in that callback NS index path and this index path is a way that you represent sequences of indexes so it'll be something like 1 dot 3.5 which is the fifth child of the third child or the first element in the the path it's for navigating a tree of objects and this is partly how NS tree controller gets a lot of its work done okay and there are also accessors for this index of position and get indexes this will allow you to be able to pick out individual indexes along the way the mechanism if you have to use this directly that's fine but it's it's mainly a behind-the-scenes addition specifically for tree controller so you've heard me jumping up and down about NS error for awhile we specified a new error domain for the cocoa frameworks so NS cocoa error domain as much as possible can be the area that we use the error domain that we use it may contain underlying errors from other systems so if a file not found error occurred way down here will bubble that up but will also include the underlying NS errors as keys and in the dictionary as we were trying to do before this cocoa error domain is specifically for use with foundation in the kit we've defined a number of error codes in epcot errors and foundation errors in order to to describe all of these there are some new methods for richer error recovery so localize description was already there and that's that's what you should be using to describe the problem that occurred the localized recovery suggestion is an opportunity for you to say something like oh you tried to save a document and the disk is full and however you say that in a number of different languages the localized Recovery Options is an array it returns an array and this should be a list of actions that the user can take in order to solve their problem that you may actually handle for them once they hit an appropriate button these should be designed specifically for presentation to the user ok so what you do with a domain and code is sort of up to you but these descriptions should be handled specifically for showing to the user and we're actually trying to work on a couple of interesting ways to be able to bubble this all the way up through into the kit and and perhaps handle errors in a more graceful dynamic fashion so spotlight metadata most of the files and you discs have a number of different attributes right creator creation time content type images have sizes and widths and Heights and DPI's and things like that one of the things that we'd like to be able to do is find them absolutely as fast as possible right and as files change as they come onto the discus they leave the disk we want to find out about those changes as much as fast as we can one of the ways that we do this is now with NS metadata query so this is the cocoa API that surrounds the spotlight API that Steve was using in this demo and that I believe there's a talk about soon in the next couple of days it uses and it's predicate and this predicate lives up in a different framework it lives up in core data it's an expression that evaluates to true or false given a set of objects so you'll construct a predicate that will define the kinds of things that you're searching for and this finds files matching that predicate and then it stores the results so you touch off the query and it's actually going to go out and find all this stuff and it's gonna hang on these results for you and it can group these results and attributes so it can actually hang on to all of these and say okay well I've got this list of results and I'll sort them according to their creator or their author it can also answer some specific questions about the results set but most importantly it's actually a bindable model object so once you set off one of these queries you can actually hook it up an interface builder and bind the write to it so you can have a very dynamic user interface setting up a query is very simple you create it with a lock in it you set the queries predicate then you start the query you can optionally stop the query but if you leave the query open it will continue to update its results so a set predicate start query and start stop query this has happens actually on the current run loop the run loop that you instantiated the object on and you can handle the results either by direct access or binding so there's actually an accessor for result count and resultant indexes so you can actually ask it specifically for individual results and at specific locations or use bind to the results array okay the results that has a value list and the value list is something like if I've searched for are all the RTS on my machine and I come up with 15 probably up a lot more but if I come up with only 15 the night had three individual authors it might be me and I'll leave my boss and mark the guy who works down the hall so those three doc knows three authors work on those 15 documents that's one way that I can group those documents or I might have 250 mp3s and that I searched for and and they might only be in three genres or four you know rock pop classical and something else I'd say country but I'd be terribly embarrassed results can be sorted by the NS to metadata query one of the things that happens is the query is going to go out it's gonna do all this work it's gonna find all these files on your disk but having since the query has all of this information about it you can tell the query to sort it and this is actually a big performance win the query knows all this information it can do all the work to sort it as the results come in and then when you actually go ahead and display this in the in your table view or in your outline view it's taking care of a lot of the heavy lifting for the sorting for you results can also be grouped by their attribute values all right so again those those country mp3s can get packed into one group along with and then all the rock ones and then all the classical ones NS metadata query also supports asynchronous updates okay so as if you leave the query open as files come and go from your disk this thing gets updated so the queries go through a phase when you first create them you touch off the start query there's a gathering phase that's going on is finding as many results as it can initially and it's going to drop it's gonna return those results to you if you continue to let the query run new results matching the predicate will just appear and you'll get a callback for that and files no longer matching the predicate will disappear so you have all this bound all this stuff sort of just happens automatically right there are some implications for this you should be as lazy as possible when you're using this so when you get some of these notifications that say hey my results that changed should do as little processing as possible because the idea here is that you're providing a dynamic look at the file system a window into what's happening as things come and go okay and actually I have a short demo here as well so if we could cut over so I have in my nib a simple field here with a start button and a table view and if we look at the table view here we'll see in the table columns portion of things that I've got these bound to some identifiers this identifier is actually this KMD item FS name is actually in the met in the spotlight framework and this is a these will be defined possibly in foundation as well but the path here is the path name of the file on disk and that's actually bound to KMD item path I've got my little results control in my results array controller here and those bindings are set up to the content array of my results and if we take a look at the code here for brief moment okay you'll see this in the release notes this is a way that we can control what the notifications are that you'll get for various things like the initial notification count and time the progress notification and update notifications for how often you get callbacks you can't really crank these down but you can extend the time you don't want to get these notifications a lot because it'll affect your performance I have a sender action here set up to toggle the query so if I'm being told to start here I'm going to set up my predicate so that I'm looking for filesystem names that are matching a query what I typed into the query string query field string I create this NS predicate and then set the predicate on the query I actually skipped a step here in that when this thing wakes up from the nib it allocate and in its itself we set these parameters in order to handle the notifications and then here I'm actually taking advantage of the fact that query is going to set these sort descriptors and it's going to set up an initial sort for the filesystem name based on an ascending sort I've added some notifications in here that I believe actually I'm driving the will change and did change right here but you can bind to this directly and then I just set the delegate start the query and change my button tile there's not a whole lot of code here but it does actually do stuff there may be more things on this disk than I thought hopefully I won't have to show you the crash report or either I think this g5 has a bigger hard drive than my laptop I'm not sure I'd go back and look at the code but you've already seen great I joked I was gonna have a John Cameron Swayze here moment and have to say I don't get it it worked and rehearsal but it did it worked in on herself you'll just I suppose have to take my word for it but that's the P list but again it's mainly just making sure that you set the predicate up initialize the sort descriptors and take care of starting the query so unfortunately this is just a fizzled out on me here but there are a number of other api's there we go that are coming out and tiger okay one of them is the core data framework core data framework provides object lifecycle management this is a model driven system this is a way to manage persistence both in getting stuff up off of disk into memory and getting it back out to disk there's a custom subclass and it's persistent document that's been defined that handles this this will also allow you to do a significant amount of UI synchronization with a lot of very tight bindings integration okay one of the side effects of using core data is automatic undo and redo and this is actually a new framework that's on tiger this is under the cocoa umbrella okay so if you're linking the cocoa framework you're getting this for free and this provides everything from faulting objects and noun so here are 10,000 objects and your honor looking at 50 of them it'll take care of keeping only those 50 in memory and handling all of the rest as dynamic objects its handles all sorts of things like both actual object inheritance as well as entity inherent and there's a go back here there's actually an introduction of core data talk this is andreas wankers team that's a session for 18 Wednesday at 2:00 the Qt kit there's new QuickTime kit on tiger providing objective-c api's new things for classes for QuickTime media for QT movie movie view track media stuff like that there's an IB palette for this and this actually completely adopts the cocoa API model using delegates and notifications you don't have to drop into idle proxxon FS specs and anything like that it also covers media exporter next and this is actually Thursday session two to 14 at 9:00 a.m. it's gonna be a talk about that the instant-message framework provides present services so when your buddies change there's online status availability methods for getting all the Buddy information out of out of the system provides official art for the present sets those a little jelly gumdrops that are green and yellow and red it'll map 80 persons and aim handles automatically and this is actually the same mechanism that I chat uses in order to get its work done so you can actually add this to your applications now you saw in the demo core image framework provides image processing that's going to push all the filtering and transforms and effects and things like that off on the graphics card so if you really wanted to hear those fans fire up in the PowerBook you've got an opportunity to do it in cocoa here right it uses the graphics card to do the work there will be api's to convert between NS images and CI images and NS colors and CI colors so you can do all those sepia tones and the things if you want to make all the electrics libros you want you can please read the release notes there's a lot of bug fixes described in the release notes a lot of pointers to new behaviors a lot of different techniques for handling a lot of these new behaviors as well as api's that I didn't even mention here there's a lot of stuff in cocoa the documentation is now in the I believe on the tiger seat it's an ATC reference library documentation cocoa the release notes are also in a similar location and the release notes folder there for cocoa Foundation and for the app kit okay if you have any questions about this stuff cocoa feedback a tap group that Apple comm there's Matt Formica who is the cocoa development tools evangelist and John Randolph everybody's favorite DTS engineer