CGevent and cocoa compatibility
Does anyone know how to get the keycode out of a NX_SYSDEFINED CGEvent? If so, is that keycode the same thing you'd get out of say (([event data1] 0x) 16)? I'm trying to support the media keys on the Apple aluminum keyboards without having iTunes also get the events. Thanks, -Ben -- Ben Lachman Acacia Tree Software http://acaciatreesoftware.com email: [EMAIL PROTECTED] twitter: @benlachman mobile: 740.590.0009 ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to [EMAIL PROTECTED]
Re: CGevent and cocoa compatibility
Yup, this is true as far as I can tell. I've got the event tap installed, the issue is that I'm not able to pull any useful data out of NX_SYSDEFINED typed events. Any thoughts on that? -Ben -- Ben Lachman Acacia Tree Software http://acaciatreesoftware.com email: [EMAIL PROTECTED] twitter: @benlachman mobile: 740.590.0009 On May 2, 2008, at 4:34 AM, John Clayton wrote: Probably means you'll need to use the event taps API and swallow the event - which is relatively simple to achieve as long as you can install an event tap that isnt a listener only. I presume since you're already talked about CGEvent structures, that this is indeed what you are doing - correct me if I'm wrong. Installing an event tap that modifies the event chain won't require special privs (from memory), so long as you don't install it at the window server level. Does this send you in the right direction? -- John Clayton http://www.coderage-software.com/ On 2/05/2008, at 8:32 AM, Ben Lachman wrote: Does anyone know how to get the keycode out of a NX_SYSDEFINED CGEvent? If so, is that keycode the same thing you'd get out of say (([event data1] 0x) 16)? I'm trying to support the media keys on the Apple aluminum keyboards without having iTunes also get the events. ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to [EMAIL PROTECTED]
Implementing fast enumeration
Re-sending as this did not seem to get make it to the list. I have been reading the documentation for implementing the NSFastEnumeration protocol and am having some difficulties following it. For completeness, here is the protocol method: - (NSUInteger)countByEnumeratingWithState:(NSFastEnumerationState *)state objects:(id *)stackbuf count:(NSUInteger)len; typedef struct { unsigned long state; id *itemsPtr; unsigned long *mutationsPtr; unsigned long extra[5]; } NSFastEnumerationState; I have a C array where the elements within it can be converted into multiple objects. Say I have 5 objects. Do I provide them all in one go and return the total number? Or just one per call and return the number remaining? Also, should the objects be returned by reference in the stackbuf variable, or in the itemsPtr field of the state structure? Apologies if these are basic questions, but I got decidedly lost trying to follow the docs. Ben. ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to [EMAIL PROTECTED]
Re: Snazzy open-source slideshow controls
Thanks! It isn't actually customizable enough, but I just used the IK image resources to build what I needed. Ben On Apr 29, 2008, at 9:24 AM, douglas a. welton [EMAIL PROTECTED] wrote: Ben, Have you taken a look at the IKSlideShow class in ImageKit? You can see it demonstrated in the IKSlideShowDemo sample code. regards, douglas On Apr 28, 2008, at 5:48 PM, Ben Kazez wrote: Hi everyone, An app I'm developing has a full-screen slideshow-like view that would benefit greatly from controls like those shown for Finder and Mail photo slideshows -- fade in/out on mouse movement, display white buttons, partial transparency, etc. (though I only need back/ forward/exit buttons). I might well have to write this myself, but before I do so, I wanted to see whether anyone had open-source code I might use instead. (A Google search didn't turn up anything.) Ben ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to [EMAIL PROTECTED]
Re: Counting instances in Core Data
In Tiger that was the best means available, but if you're targeting Leopard there is a better option available: Create your fetch request to fetch all instances of a given entity and execute the fetch with countForFetchRequest:error: which will simply return the number of instances/rows that match your query. Though Steve mentioned off-list that he's targeting Tiger, I had managed to completely forget about this method - my apologies for the misinformation. Well, it's probably best to ask the NSManagedObjectContext -respondsToSelector:@selector(countForFetchRequest:error:) and use the slow -executeFetchRequest:error: if the result is NO. -- -Ben ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to [EMAIL PROTECTED]
Snazzy open-source slideshow controls
Hi everyone, An app I'm developing has a full-screen slideshow-like view that would benefit greatly from controls like those shown for Finder and Mail photo slideshows -- fade in/out on mouse movement, display white buttons, partial transparency, etc. (though I only need back/forward/ exit buttons). I might well have to write this myself, but before I do so, I wanted to see whether anyone had open-source code I might use instead. (A Google search didn't turn up anything.) Ben ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to [EMAIL PROTECTED]
NSScrollView/NSScroller drawing glitch on leopard
Hi all. Recently I noticed that one of the scrollers in my app was drawing a bit oddly on launch. What happens is that the vertical scroller draws as if both the horizontal and vertical scrollers were visible (e.g. a little empty white box below the down button). However, only the vertical scroller is visible (it's the scroller for a table view). Once I resize the window, etc. I have no problems with its drawing, just on initial launch. It also doesn't seem to matter what size it is on launch as long as it is large enough to not have a horizontal scroller. This only happens on Leopard. How can I get rid of this box? Thanks, -Ben ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to [EMAIL PROTECTED]
re: ManagedObjectContext save issue
Steve, What's the error, what's in it's userInfo dictionary, and if you use: future-break +[NSError errorWithDomain:code:userInfo:] in gdb, what's the stack trace from the point that creates the error ? -- -Ben ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to [EMAIL PROTECTED]
Re: setTextContainerInset with different values for left and right
You can subclass the text view and returned an origin point from - (NSPoint)textContainerOrigin. This will give you origin.x +inset.width on the left and just inset.width on the right when used in conjunction with setTextContainerInset. -Ben -- Ben Lachman Acacia Tree Software http://acaciatreesoftware.com [EMAIL PROTECTED] 740.590.0009 On Apr 18, 2008, at 11:44 AM, Ferhat Ayaz wrote: Hi, how would I go about setting NSTextView up so its insets are dx1 from the left and dx2 from the right side? I guess setTextContainerInset: will set for both left and right the same value (dx1 = dx2). ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to [EMAIL PROTECTED]
Re: NSTableView -editColumn:row:withEvent:select: question
Well, you should be able to just override the drawing code, since thats really your problem. Going directly against the docs, while it may work fine now, is playing with fire in my opinion. To get the drawing you want, you can just implement tableView:willDisplayCell:forTableColumn:row: in the delegate and manually switch selection highlighting on or off depending on whether the table column passed to you is the selected table column. You'll probably have to have a couple more cases if you're really trying to get close to the standard spreadsheet functionality that lets you select the full row/column by clicking on the header. But this should get you started, hopefully. -Ben -- Ben Lachman Acacia Tree Software http://acaciatreesoftware.com [EMAIL PROTECTED] 740.590.0009 On Apr 18, 2008, at 1:55 PM, John Stiles wrote: The docs for -editColumn:row:withEvent:select: ominously claim: The row at rowIndex must be selected prior to calling editColumn:row:withEvent:select:, or an exception will be raised. I'm implementing a subclass of NSTableView which behaves a little more like an Excel spreadsheet—it maintains a phony selection by overloading -mouseDown/Dragged/Up: and coloring cell backgrounds as appropriate. It works great. But it means that the table view, internally, never actually considers a row to be selected. My subclass handles that entirely on its own and leaves the table view out of it. Now I'm getting around to implementing the part where the user can edit table cells in place, and since I wanted to follow the rules in the docs, I started by implementing it like this: [myTableView selectRow:inRow byExtendingSelection:NO]; [myTableView editColumn:inCol row:inRow withEvent:myEvent select:NO]; It worked fine but, of course, the entire row turned blue, ruining the spreadsheet illusion. So just to see what would happen, I tried removing the call to - selectRow:: and, lo and behold! No exception. It worked great. Looks just like how I want it to look. Am I getting lucky here? Are the docs just wrong? I don't want to do something overtly dangerous, but in practice it does exactly what I want... are there any gotchas? I'm on Leopard FWIW, and don't need to target older OSes. ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/blachman%40mac.com This email sent to [EMAIL PROTECTED] ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to [EMAIL PROTECTED]
Re: Hand style movement inside a NSScrollView
On Apr 18, 2008, at 9:14 PM, Jens Alfke wrote: On 18 Apr '08, at 12:49 PM, Steve Sheets wrote: However, I also want to implement a Hand style tool. One that allows the user to simple click inside the Scroll View and draw the graphics around. I think you just need to have your view's mouseDragged: handler method call -scrollPoint: on self. The only tricky bit is figuring out what point (in your view's coords) should become the origin of its visible bounds. I tend to like scrollRect:by: for this sort of thing since it takes a offset to a rect. -- Ben Lachman Acacia Tree Software http://acaciatreesoftware.com [EMAIL PROTECTED] 740.590.0009 ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to [EMAIL PROTECTED]
Re: Hand style movement inside a NSScrollView
On Apr 19, 2008, at 12:41 AM, Jens Alfke wrote: On 18 Apr '08, at 8:59 PM, Ben Lachman wrote: I tend to like scrollRect:by: for this sort of thing since it takes a offset to a rect. But that method just blits pixels around on the screen; it doesn't actually change the coordinate system of the view. The scroll view will do the blitting for you automatically when you change its coordinates via -scrollPoint:. Looks like I misread Steve's question. Jens is right of course. In light of rereading the OP correctly though, I think using [view scrollRectToVisible:NSOffsetRect([view visibleRect], offsetX, offsetY)]; might work and would make more sense (at least to me) when going back to the code in a 6 months. -Ben -- Ben Lachman Acacia Tree Software http://acaciatreesoftware.com [EMAIL PROTECTED] 740.590.0009 ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to [EMAIL PROTECTED]
re: Chained Migration of Leopard CoreData stores
Hi, let's say I have four versions of my data model: DataModel1.xcdatamodel DataModel2.xcdatamodel DataModel3.xcdatamodel DataModel4.xcdatamodel (this is the current one) and three model mapping files which always map from version n to version n+1: Mapping1to2.xcmappingmodel Mapping2to3.xcmappingmodel Mapping3to4.xcmappingmodel Now I load a version 1 data file: NSDictionary *options = [NSDictionary dictionaryWithObject:[NSNumber numberWithBool:YES] forKey:NSMigratePersistentStoresAutomaticallyOption]; NSError *error = nil; if (![persistentStoreCoordinator addPersistentStoreWithType:NSSQLiteStoreType configuration:nil URL:url options:options error:error]) { ... } should the data file automatically be migrated to the current version 4 or do I need a single direct mapping like this: Mapping1to4.xcmappingmodel If you want Core Data to do everything, you'll need 1 mapping model, since we don't assume that iterative upgrades will necessarily work. If you're confident that composing your N+1 mapping models together makes sense for your app, you can run N+1 migrations in a row to avoid needing an umbrella mapping model. -- -Ben ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to [EMAIL PROTECTED]
re: Core Data for managing subtree?
At 6:13 PM -0700 4/8/08, [EMAIL PROTECTED] wrote: However, I would like to use Core Data to manage these items. I figure I could have my add and remove methods insert and remove objects from the managed object context as well as the KVO-compliant mutable array, but when I undo such an action, the change will only be reflected in the managed object context. I could create an extra entity to act as a collection for those items and have the add and remove methods manipulate that object, but I don't see how this collection could then be KVO-related to its parent node as per mutableArrayValueForKey:. Hamish, The easiest way to get array and tree controllers to work with Core Data results is to put them into Entity mode. If you want to bind to a to-many relationship keypath, you can bind to their 'contentSet'. Core Data to-many relationships respond to mutableSetValueForKey: If you only want only some of the tree using Core Data objects, you could try having an array controller manage the extra entity, and wire its content into your tree controller. You don't need a to-many relationship for that. The array controller in entity mode directly observes the NSManagedObjectContext with which it is associated. If you want to customize things even further, you can observe the NSManagedObjectContext's NSManagedObjectContextObjectsDidChangeNotification yourself, and update your custom controllers based on the contents of that NSNotification. The array controller in entity mode is basically doing this, plus observing some of the managed object properties directly with KVO. -- -Ben ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to [EMAIL PROTECTED]
Re: Why should we set ivars to nil in dealloc?
Seriously, we're arguing about this ? If you want a total hack, just assign (id) 0x1 to any variable that ... please step away from the tequila. I have a radical suggestion: Test your software. Like crazy talk!! The detection of this class of bugs is extraordinarily easy to automate, so my sympathy is lower than its usual nonexistence. Here are the environment variables to set: export NSZombieEnabled=YES export CFZombieLevel=9 export MallocScribble=1 export MallocPreScribble=1 export MallocGuardEdges=1 You don't have to remember to run with these flags. Because, of course, you have unit tests to at least provide some basic code coverage. If you don't, you really need to stop and fix that first. I can't say I enjoy it, but begrudgingly, the results and ROI from unit tests have been extremely impressive. Compared to the previous project I worked on (no unit tests), we've been able to make much more aggressive changes, and innovate faster, on my current project entirely due to the unit testing infrastructure. And then, you find an old mac mini or imac, and set up a cronjob to run your unit tests every night. Once you have nightly unit tests set up, running them again with different env flags is effortless. If you're wondering wtf CFZombieLevel 9 does, check out Most Awesome TechNote Ever: http://developer.apple.com/technotes/tn2004/tn2124.html Also, for more paranoia (at 100x slower), you can use (do NOT mix with the above): export DYLD_INSERT_LIBRARIES=/usr/lib/libgmalloc.dylib export MALLOC_FILL_SPACE=1 Since those two modes behave differently, we run both nightly. And while we're on this subject, there's another class of bugs that nightly testing can really help with: leaks. There are two easy leak tools to use via scripts. 'leaks' and 'heap'. Leaks is a good first pass, which rarely has false positives, but very often has false negatives. Nevertheless, if your code can't pass through leaks, you have a pretty big problem. So 'heap' fills in the gap to catch the leaks that 'leaks' missed. To use 'heap' to catch leaks, you'll want to create a black list. For example, in Core Data, after each unit test, we grep through the heap result to see if there are any NSManaged*, NSEntity*, etc etc. We skip over stuff that's hard to sort through, like NSString, but we can at least ensure that none of our classes are still present in the heap. That's a pretty thorough leak detection. This is a bit harder than zombies, because you'll need to white list known problems (in other people's code), and for the heap tool create a custom black list. But this is absolutely worth the effort. Running unit tests through debugging tools (zombies, leaks, etc) nightly has been the single highest return on effort debugging decisions I've ever seen. Ever. Seen. The second highest was actually writing the unit tests in the first place, a necessary prerequisite, but more effort. Just imagine what you could do mixing this stuff with dtrace ... -- -Ben ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to [EMAIL PROTECTED]
Re: struct problem
On Apr 12, 2008, at 8:03 AM, Dean Ritchie wrote: On Apr 12, 2008, at 1:37 AM, Hamish Allan wrote: On Sat, Apr 12, 2008 at 2:58 AM, Dean Ritchie [EMAIL PROTECTED] wrote: columnCount = [[LASize cellAtIndex:0] intValue]; rowCount = [[LASize cellAtIndex:1] intValue]; When I stop right after initializing the NSRect local variable, the debugger reports miniscule values for the portions of the rectangle, like it got overlaid with integers instead of float values. Where are columnCount and rowCount declared, and as what types? They are class variables, type int. In general the naming convention used in Objective-C is that class names start with capitals and variable names start with lower-case characters (both use bumpy case which I think you know). For instance NSWindow (class) and aWindow (variable). However in your code you have LASize, which looks a whole lot like NSSize (which happens to be a struct). However you're assigning sender to it which is of type id. This introduces some confusion, since you assumedly assign an object variable to something that looks very much like a struct type. This may not be a bug (we don't know what type sender or LASize are so it's hard to say), but it leaves the code nearly unreadable for the casual observer. If you want someone to help you out, try to post more clear code. In a more general sense, it's good to write code that follows the general naming conventions anyway since if you ever have to share your code or go just back and read it in a year you'll have less work understanding it. -Ben -- Ben Lachman Acacia Tree Software http://acaciatreesoftware.com [EMAIL PROTECTED] 740.590.0009 ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to [EMAIL PROTECTED]
Re: Highlight color of a NSTableView row
Sorry, perhaps I should have been a bit more specific. That implementation both overrides highlightColorWithFrame: and drawWithFrame:. As you noticed, the draw with draw bit just just draws the text white if the cell is selected. This is nice for dark selection highlight colors and most of Apple's iApps that contain table views do it. To remove that behavior just remove: NSColor *oldColor = [self textColor]; [self setTextColor:[NSColor alternateSelectedControlTextColor]]; [super drawWithFrame:cellFrame inView:controlView]; [self setTextColor:oldColor]; Which saves the original color, set the color of the text to white, draws it and then restores the original color. Calling super's draw method just draws the cell as it would normally given the current settings (color, title, etc.). HTH, -Ben -- Ben Lachman Acacia Tree Software http://acaciatreesoftware.com [EMAIL PROTECTED] 740.590.0009 On Apr 12, 2008, at 1:23 PM, Eric Gorr wrote: On Apr 11, 2008, at 12:21 AM, Ben Lachman wrote: I do something like this: @implementation HilightingTextFieldCell - (void)drawWithFrame:(NSRect)cellFrame inView:(NSView *) controlView { if( [self isHighlighted] ) { NSColor *oldColor = [self textColor]; [self setTextColor:[NSColor alternateSelectedControlTextColor]]; [super drawWithFrame:cellFrame inView:controlView]; [self setTextColor:oldColor]; } else { [super drawWithFrame:cellFrame inView:controlView]; } } - (NSColor *)highlightColorWithFrame:(NSRect)cellFrame inView: (NSView *)controlView { return nil; } @end So, based on your code, I have written this... @implementation CustomHighlightTextFieldCell - (void)drawWithFrame:(NSRect)cellFrame inView:(NSView *)controlView { NSColor *evenColor = [NSColor colorWithCalibratedRed:.9 green:0 blue:0 alpha:1.0]; if ( [self isHighlighted] ) { [evenColor set]; NSRectFill( cellFrame ); NSColor *oldColor = [self textColor]; [self setTextColor:[NSColor blackColor]]; [super drawWithFrame:cellFrame inView:controlView]; [self setTextColor:oldColor]; } else { [super drawWithFrame:cellFrame inView:controlView]; } } - (NSColor *)highlightColorWithFrame:(NSRect)cellFrame inView: (NSView *)controlView { return nil; } @end I just want to draw the entire cell with a background color with black text. For a selected row, what I get is a cell drawn with the background color, but white text. I cannot figure out how to get the text drawn with a black color. Will I need to replace: [super drawWithFrame:cellFrame inView:controlView]; with my own code to draw the text? At this point, actually seeing my specific case might be helpful... I have placed my project at: http://ericgorr.net/acc.zip The application is a (not entirely complete) calculator for the board game Advanced Civilization ( http://www.boardgamegeek.com/ game/177 ). What it does is keep track of what civ. cards you have purchased throughout the game and keep track of the current cost of the cards which you can still purchase. Each row corresponds to one of the civ. cards. What I have written, which only uses highlightSelectionInClipRect to control the highlighting, has nearly all of the highlighting I want. 1. Row, in groups of three, have either a light blue or white background, if the card has not been purchased (rantI _hate_ the look of the alternating light blue white...groups of three is _vastly_ superior/rant) 2. If a card has been purchased, it's background is yellow. 3. For #1 #2, the text remains black - my guess as to why this is the case is that the process of highlighting a selected row changes the text to white and if a row is not selected, it get the black text with either the light blue, white or yellow background. 4. When I select a row, it's get the highlight color specified by the system preference - the default blue highlight color on my machine. 5. There is no space between the columns 6. If two cards have been purchased and are in adjacent rows, there is no space between the rows, which have been colored yellow. The only thing I would like to change about how this is working is when I select a row of a card which has been purchased, I would like to use a darker yellow color. just a usage note...to be able to purchase a card, first enter a number (like 200) into the 'Trade Cards' field, this will cause the purchase button to be enabled. Second, select a row, which isn't grayed out. Third, press the purchase button. ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com
Re: Convert NSArray to NSString
I assume you mean selectedRanges, which returns an NSArray of ranges. This array contains NSValue objects that represent ranges of selected text, not actually the text that is selected. To get the text that is selected you have to do a bit more work. First you need to the get string of text from the textview. You can either do this using [aTextView string] or extract a string from the textStorage object that Michael mentioned. Then, for each NSValue in the array you must retrieve an NSRange using rangeValue, and then call substringWithRange: on the string you got in the first part. You can do whatever you want with this string--append it to a mutable string or just store it--just make sure you retain it if you plan on keeping it around since it is an autoreleased object that is returned by substringWithRange (ignore this is if you're using GC). If you just want the full text you can just call [aTextView string]. selectedRange just returns a single range and so you would only have to do the operation described above once, but may not get all the text selected if the textview supports multiple selections. Make sure you also check that ranges returns by selectedRange(s) doesn't contain the NSNotFound marker as well. -Ben -- Ben Lachman Acacia Tree Software http://acaciatreesoftware.com [EMAIL PROTECTED] 740.590.0009 On Apr 12, 2008, at 8:49 PM, Michael Vannorsdel wrote: The textStorage of the NSTextView is actually an NSMutableAttributedString subclass so you can treat it as such and get the text and attributes from it. On Apr 12, 2008, at 6:48 PM, Lincoln Green wrote: I am trying to store the selected text in an NSTextView in an NSString/NSMutableString. I have found the selectedRange method, but can't figure out how to turn the NSArray into an NSString. Any help would be greatly appreciated. Thanks! ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to [EMAIL PROTECTED]
Re: Tips to deploy applications to multiple Mac OS X versions
On Apr 10, 2008, at 6:19 PM, Chris Suter wrote: One caveat, though, is that you should probably have a runtime check for the minimum OS version you expect so that you don't end up with a crash if someone tries to use your nifty Leopard features on Tiger. Adding something to main() would probably be easiest, either checking against NSAppKitVersionNumber or calling Gestalt() to get the OS version. There's something you can put in the Info.plist that does this for free. I forget exactly what it is but I'm sure it's easily found. LSMinimumSystemVersion is the key. -- Ben Lachman Acacia Tree Software http://acaciatreesoftware.com [EMAIL PROTECTED] 740.590.0009 ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to [EMAIL PROTECTED]
Re: Highlight color of a NSTableView row
I do something like this: @implementation HilightingTextFieldCell - (void)drawWithFrame:(NSRect)cellFrame inView:(NSView *)controlView { if( [self isHighlighted] ) { NSColor *oldColor = [self textColor]; [self setTextColor:[NSColor alternateSelectedControlTextColor]]; [super drawWithFrame:cellFrame inView:controlView]; [self setTextColor:oldColor]; } else { [super drawWithFrame:cellFrame inView:controlView]; } } - (NSColor *)highlightColorWithFrame:(NSRect)cellFrame inView:(NSView *)controlView { return nil; } @end HTH, -Ben -- Ben Lachman Acacia Tree Software http://acaciatreesoftware.com [EMAIL PROTECTED] 740.590.0009 On Apr 10, 2008, at 8:47 PM, Eric Gorr wrote: On Apr 10, 2008, at 8:30 PM, Corbin Dunn wrote: Playing with this a bit more, it appears that I need to also do: - (id)_highlightColorForCell:(NSCell *)cell { // we need to override this to return nil // or we'll see the default selection rectangle when the app is running // in any OS before leopard // you can also return a color if you simply want to change the table's default selection color return nil; } Or it will ignore my highlight drawing entirely. It appears this is an undocumented API or, at least, I cannot locate it in the documentation. If a method starts with an underscore, don't even bother looking it up in the documentation :) -- not only is it undocumented, but it is unsupported and might change in the future. The proper thing to do: 1. Subclass NSCell, NSTextFieldCell, or whatever other cell you want. 2. Override: - (NSColor *)highlightColorWithFrame:(NSRect)cellFrame inView: (NSView *)controlView and return nil. How would I go about subclassing NSTextFieldCell NSImageCell and then using these cell with my NSTableView? ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to [EMAIL PROTECTED]
Re: Highlight color of a NSTableView row
Look at: http://katidev.com/blog/2008/02/22/styling-an-nstableview-dttah/ but make sure you read the comments. John Randolph's comments are worth considering. -Ben -- Ben Lachman Acacia Tree Software http://acaciatreesoftware.com [EMAIL PROTECTED] 740.590.0009 On Apr 10, 2008, at 12:27 AM, Eric Gorr wrote: I've got a NSTableView and when I select a row, it is highlighted with the color specified in the Appearance System Preference panel. Is there a way to take control over what color gets used to highlight a row when selected? I need to be able to set the highlight color used based on what row in the table is selected. ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to [EMAIL PROTECTED]
Re: Problems with Split Views?
For the most part, anything you want to do with NSSplitView you can do with RBSplitView (or others) and vice versa. Where RBSplitView really excels is its ease of implementation. Even though NSSplitView in 10.5 is significantly better, I still find that RBSlitView has the upper hand in terms of time-to-deployment. If you need specifics, just compare the documentation of RBSplitView and NSSplitView. I continue to use Rainer's implementation every time I need a split view. Hope that helps, Ben On Apr 6, 2008, at 10:21 PM, Peter Zegelin wrote: I am quite new to Cocoa and have been experimenting with split views in Interface Builder. It's basically 3 vertical splits with each end view also split in half horizontally. It seems to do more or less what I want. However looking around for example projects I get the impression that the split views are somehow buggy and I'm better off using a third party split view such as RBSplitView. Can someone explain what sort of problems - if any - I'm likely to encounter using the regular split view? What I need is to have 3 vertical splits with each end view also split (horizontally). These end views should not resize as the window is resized - just the center view. I know in IB you don't seem to be able to prevent a split from resizing when its parent is resized (or am I wrong here?) but I presume that wouldn't be a problem with some code. Thanks! Peter ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/beinstein%40comcast.net This email sent to [EMAIL PROTECTED] ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to [EMAIL PROTECTED]
Re: Custom Buttons - Tutorial/Examples...
This isn't a subject that I've ever seen addressed really thoroughly in a tutorial type walk though, its more a journey of gleaning all the info you need to create new buttons and controls. Personally I'd call custom control creation the dark art of Cocoa ;-). For your case though I think looking at setShowsStatesBY: and setHighlightsBy: should suffice to solve your problem. Also make sure you look at all the constants that are valid, not just the ones the developer docs talk about (NSNoCellMask and siblings). -Ben -- Ben Lachman Acacia Tree Software http://acaciatreesoftware.com [EMAIL PROTECTED] 740.590.0009 On Apr 5, 2008, at 6:08 PM, John Joyce wrote: Does anybody know a tutorial or example on creating custom buttons in Cocoa? I can certainly set an image in IB or programmatically, but how can I determine the actual hitmask? Or even set the mouseOver type of event for something like a rollover ? I know I'm talking about stepping on Apple's HIG, but it is something I'd like to know how to do without delving into CG or CA right now. I've been toying with it a bit today, and I can certainly set the images, but on mouse down, the background changes to the image with a darkened state inside of a white rectangle... surely I'm missing something stupidly obvious...? Any tips or links are greatly appreciated! Cheers, JJ ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/blachman%40mac.com This email sent to [EMAIL PROTECTED] ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to [EMAIL PROTECTED]
Bindings on Contextual Menu Items when to unbind:
I have a few contextual menus that have items that are generated dynamically and are bound in code to my model. I'm not sure if/when I should unbind them however. Is there a good place to do this? Do I even need to? Thanks, -Ben -- Ben Lachman Acacia Tree Software http://acaciatreesoftware.com [EMAIL PROTECTED] 740.590.0009 ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to [EMAIL PROTECTED]
Re: Propagate changes/insertions in main context
There was quite an extensive conversation about this a couple days ago. Try to check the archives before posting... http://www.cocoabuilder.com/archive/message/cocoa/2008/3/30/202687 and following -Ben -- Ben Lachman Acacia Tree Software http://acaciatreesoftware.com [EMAIL PROTECTED] 740.590.0009 On Apr 3, 2008, at 8:34 AM, malcom malcom wrote: Dear List, I'm working with CoreData. I need to insert lots of objects and make relationship with these and I've decided to perform this operation deteaching a new thread that pool an NSArray where data is placed. This thread make the object and insert it in a second managed object context, perform linking operations and save the context. What's the right way to work with multithread and more than an context? Need I to perform insertion in a second context, then save the context itself (the save operation need to be perfomed inside thread or in main thread?) and make a refreshObject:mergeChanges:YES with the main thread? Cheers, Dex Morgan ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/blachman%40mac.com This email sent to [EMAIL PROTECTED] ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to [EMAIL PROTECTED]
Re: test if another app has hung
On 1 Apr, 2008, at 11:49 am, Ron Fleckner wrote: On 01/04/2008, at 9:28 PM, Ben Dougall wrote: Hello, What's the best way to test if another app has likely hung or not? Programmatically of course. I want to be able to kill an often hanging app and restart it -- when it's hung that is. (10.3.9+) Thanks, Ben. Hi Ben, This question was exhaustively examined in a thread a few weeks ago. Start here: http://www.cocoabuilder.com/archive/message/cocoa/2007/10/20/191068 HTH, Ron Excellent, thanks for the pointer. Ben. ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to [EMAIL PROTECTED]
Re: NSNoCellMask differences in Leopard vs. Tiger
So it ends up that while NSNoCellMask works on Tiger it really isn't the way to do what I was wanting. NSPushInCellMask does the same thing (darken the un-bezeled icon), makes more sense, and works on both Tiger and Leopard. The problem is that the documentation doesn't mention NSPushInCellMask unless you look at the state masks leading me to believe that it wasn't a supported value for setHighlightsBy:. Anyway, hope this helps someone at some point. -Ben -- Ben Lachman Acacia Tree Software http://acaciatreesoftware.com [EMAIL PROTECTED] 740.590.0009 On Mar 20, 2008, at 5:50 AM, Ben Lachman wrote: On Tiger one could set up borderless, momentary light square button with an icon and call setHighLightsBy: with NSNoCellMask and you'd get a nice darkening on the non-transparent parts when the user pressed the button. However these same buttons on Leopard don't change at all during a user's press. Is there a way to get a similar effect on Leopard without using an alternate image (some of my buttons already have alternate images)? ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to [EMAIL PROTECTED]
Re: Threads and Core Data, bindings results in view corruption
On Mar 31, 2008, at 2:47 PM, Jeff LaMarche wrote: On Mar 31, 2008, at 2:36 PM, David wrote: On Mon, Mar 31, 2008 at 2:26 PM, Jeff LaMarche [EMAIL PROTECTED] wrote: 4) You can, as Ben mentioned, use performSelector:onMainThread: to actually have the object inserted on the main thread's context. It's a bit of a pain, but threads are always at least a little painful. How? Core data says that to use NSManagedObjects between threads you need to pass an ID and access it from another context. But you don't even get an ID until you perform a save on the original context. I'm then back to my original problem where the save itself takes too long. From what I've read so far, my current thinking is that I need to give up on Core data. I can easily create my own objects, handle my own locking or synchronization. I was thinking to still use NSTreeController bound to my objects. Its a shame because core data sounds so cool. I love the data modeling aspects. Nice way to think through the problem even if I end up not using it. Well, I don't know exactly what you're doing in your thread, but you could create a method that that took, for example, a dictionary as an argument, then when you're ready to insert the object in your thread, pass that method the values you need having it fire on the main thread and then create the Core Data entity based on the passed values and then insert it into the main thread's context. If you needed to do further work on that entity, like adding relationships to it, then it would get to be trickier, as you'd also need to get its managedObjectID back to your thread. Actually this isn't true. You can add relationships, etc. without having to pass them around since you will be doing a save at some point and that will sync everything back to the persistent store. Then, once you pass the OID of your newly inserted object back to you main thread you can fetch it from the store and the relationships you added to it, etc. will be intact. My worker thread looks something like this (pseudo-code): Main thread: [NSThread detachNewThreadSelector:@selector(workLoop:) toTarget:newWorker withObject:self]; Worker thread executes work loop which inserts new managed objects, saves them and sends the new oids back to the main thread by calling: [owner performSelectorOnMainThread:@selector(addResults:) withObject: [newManagedObjectSet valueForKey:@objectID] waitUntilDone:NO]; The worker also notifies its owner (which was passed to detach...) just before exit. This is loosely based on SIWorkerThread by Daniel Vollmer http:// www.maven.de/2007/01/cocoa-worker-thread/ with use of performSelectorOnMainThread to pass OIDs back. You also should try using an SQLite store. It will be faster than a binary store for saving incrementally since it only touches part(s) of the file. However if you are adding lots of objects make sure you look at how often you save and if there are ways to decrease that frequency. Lastly, I kind of wonder if there might be some way to integrate a secondary In-Memory store into this setup for use in passing the objects created by the worker thread back to the main thread, it seems like it might introduce some more complexity but might also be worthwhile performance-wise since saving to the SQL store does have a certain amount of latency due to how it hits the disk (particularly on Tiger). Any thoughts on this Ben? -Ben -- Ben Lachman Acacia Tree Software http://acaciatreesoftware.com [EMAIL PROTECTED] 740.590.0009 ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to [EMAIL PROTECTED]
Re: Threads and Core Data, bindings results in view corruption
request you should file. There are better ways to implement this than locking at the NSManagedObject level. I have interpreted that to mean that locking the managedObjectContext would be sufficient. I hadn't realized that bindings would try to obtain locks. No, it doesn't. But it needs to obtain locks to honor your locking. The list archives also have these, which you should read: http://lists.apple.com/archives/cocoa-dev/2007/May/msg00222.htmlhttp://lists.apple.com/archives/cocoa-dev/2007/May/msg00222.html http://lists.apple.com/archives/cocoa-dev/2008/Jan/msg01889.htmlhttp://lists.apple.com/archives/cocoa-dev/2008/Jan/msg01889.html It's possible to shuttle pending changes between threads by hand using KVC. Are you describing in general or specifically with Core Data? Can you give more insight on this? Are you saying that I manually track changes from core data? For updates objects, you can just pass a dictionary of deltas between threads if you don't want to save. For inserted objects, you'd need a proxy insert. But, yes this works generally and with Core Data (although not conveniently). Both KVC and Core Data have methods to make this somewhat less painful. Manually tracking changes from Core Data is pretty easy. We post the NSManagedObjectContextObjectsDidChangeNotification every time you call -processPendingChanges. On Leopard, in the scenarios under which you can save, you can also use -mergeChangesFromContextDidSaveNotification: But isn't a notification received on the same thread on which it was posted? Yes, but that's not what the API is for. It takes the notification object, and merges it into the current MOC's state. You could grab the notification object from the save on your background thread, and pass it to the main thread with -performSelectorOnMainThread: and this method will merge all the changes into the main thread's MOC. It still requires inserts be saved, but otherwise handles all the merging logic efficiently. Finally, in 4 years no one has filed a bug about this. File a bug about what? Everything you don't like. Documentation, example code, Core Data, Bindings, performance, enhancements, feature requests ... Do you consider the threading behavior in bindings and Core data to be a bug? This is about what you consider to be suboptimal. -- -Ben ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to [EMAIL PROTECTED]
scrollRangeToVisible from within mouseDown causing crash?
I just added a call to scrollRangeToVisible: that is sometimes called from my text view's mouseDown method. Now, whenever scrollRangeToVisible: is called on a range that is not visible, the next drawRect of the text view crashes with the exception: *** NSLayoutManager, _getGlyphBuffer(): NSZoneMalloc failed! (EXC_BAD_ACCESS). I had assumed that this was just a memory management bug on my part, but the fact that I can basically turn the crash on or off based on whether I call scrollRangeToVisible has me a bit confused. Anyone know what this could be? -Ben -- Ben Lachman Acacia Tree Software http://acaciatreesoftware.com [EMAIL PROTECTED] 740.590.0009 ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to [EMAIL PROTECTED]
re: NSPersistentDocument Revert Question
Mike, Each persistent document has its own Core Data stack. When you close one, and reopen it, it has a new NSPersistentStoreCoordinator, NSManagedObjectModel, and NSManagedObjectContext. So any bindings to managed objects or their entity descriptions from the old, deallocated persistent document are effectively invalid. -- -Ben ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to [EMAIL PROTECTED]
Re: Core Data and NSOperation
Daniel, Each NSOperation is, conceptually, its own thread. In addition to using NSInvocationOperation to easily dispatch a work function to an object, you'll also need to follow the multi-threading rules described in the Core Data Programming Guide. -- -Ben ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to [EMAIL PROTECTED]
re: Core Data migration
David, To sum up: Relationships to entities from which another entity inherits are not automatically set up properly. Unfortunately. This is a known issue. Anyone have any experience with this, or know how to handle this situation? I suppose I could write a whole bunch of custom code to handle it, but it seems as if the migration system should handle the inheritance. I'll trade you a bug report for a work around. -- -Ben ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to [EMAIL PROTECTED]
re: Core Data Client/Server Application
Philip, Core Data doesn't support client server applications. Some developers have successfully used it on the client for its data management (undo, change tracking, notifications, etc) and Cocoa Bindings support, with an in-memory store they manage themselves. A few developers have done more sophisticated things with a Core Data sqlite store that is effectively a cache of a subset of the server's database. But there's no back end support for MySQL or Postgres besides what you do for yourself. -- -Ben ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to [EMAIL PROTECTED]
Re: Core Data faulting and bindings: recursive KVO notifications?
Dennis, Well, it might be far from ideal for CD performance, but that doesn't mean it's bound poorly. It is done exactly to do what we need it to do, otherwise this binding would have been the first to be targeted for rewrite. Creating a gigantic autoreleased NSArray from valueForKeyPath: and simultaneously observing tens of thousands of objects is an awful lot of work for little reward. The user cannot *see* tens of thousands of things. I really do require the app to be able to show the user the values of about 1000 items at once, e.g. for a stack of related items. If they are the same for every item, it is important that that value be visible to the user. You want distinct values, not tens of thousands of them. Too much data is unmanageable from a user experience perspective. Since your data is mostly read only, observing all these values is a horrific waste. Just get the distinct values once, and invalidate the cache in the rare case the user edits one of them. And this is one thing Bindings as it is, cannot do properly: The creation of all observation info (one dictionary for each bound property of each item in the selection) when selecting is just too much overhead. Plus you easily encounter the aforementioned stack overflow. You should file a bug report on this. Also, I still don't see a bug report for your earlier problem with KVO faulting. Properties should be propagatable to 1000 objects at once for my users, as they work equally with individual images and up till 1000- image stacks. Your 30 monitor must be a lot larger than mine. I guess this calls for an extra layer of indirection, with a real separate entity representing the image stack and propagating the changes, without having 1000s of observers-observed object relationships. Exactly. Now that's an idea that can scale. -- -Ben ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to [EMAIL PROTECTED]
re: Threads and Core Data, bindings results in view corruption
David, Jeff, Ben There are a few issues here. First, enough pieces of AppKit and Cocoa Bindings are not thread safe that, even without Core Data, you just can't do this in this particular fashion. If you want multi-threaded work with the view and controller classes in Cocoa, you'll need to perform your background operations, and communicate back to the main thread (view controllers) via the run loop. -performSelectorOnMainThread and its friends in NSThread.h are your best bet. Using a run loop on a background thread and communicating from the main thread to it with the new 10.5 -performSelector... methods is often conceptually simpler (easier to debug) than many other threading patterns. Sharing a MOC with Cocoa Bindings and a background thread will end in tears. Cocoa Bindings doesn't lock its bound MOC, so you're basically SOL. Even if it did work, though, it'd be a bad idea. Sharing a MOC means a background thread would still at times block the main thread and SPOB your app. These 3 points (can't work, doesn't work, shouldn't work) are why the Core Data Programming Guide says don't do this. This isn't to say what what you intend to accomplish is wrong or undesirable. Quite the contrary. Just that this 'how' is going in the wrong direction. The Core data programming guide says its best to maintain a separate managedObjectContext per thread. But this appears to require the data to be written to persistent store to make it work (file). That not reasonable in my case where I'm adding many objects to an object tree. It takes a significant amount to time to write it out, negating the benefit of trying to make the UI seem responsive. The list archives also have these, which you should read: http://lists.apple.com/archives/cocoa-dev/2007/May/msg00222.html http://lists.apple.com/archives/cocoa-dev/2008/Jan/msg01889.html It's possible to shuttle pending changes between threads by hand using KVC. On Tiger, saves are especially expensive as the default behavior was to use a more correct/aggressive version of fsync, specifically fcntl(...,F_FULLFSYNC). This is 100-1000x slower than fsync, which technically is incorrect on nearly all consumer grade hard drives at a hardware level. On Leopard, we made significant performance optimizations, so the user experience can vary greatly between the two OS's. If you're inserting a large number of new objects, you really should just batch the operation together, save, and present the user with new objects in the tree view in batches. On Leopard, in the scenarios under which you can save, you can also use -mergeChangesFromContextDidSaveNotification: While AppKit Bindings makes it impossible to share a MOC with a background thread, theoretically all your background threads can share a MOC if you lock and unlock them. Or you could just have 1 background thread processing asynchronous operations. That'd be a lot easier to debug. You should also use the Debug libraries and Core Data multi-threaded assertions: http://lists.apple.com/archives/cocoa-dev/2008/Mar/msg01098.html Life's a lot easier when your app halts in gdb as soon as you make a mistake. 'thread apply all bt' is your friend. Finally, in 4 years no one has filed a bug about this. If one developer has a problem, it's unfortunate. If three developers have a problem, it's an issue. If two hundred developers have a problem, it's a crisis. Kinda hard to tell the difference if developers can't be bothered to speak up in the only way that really matters: bugerport.apple.com Feature requests, performance problems, and enhancement suggestions are all bugs -- -Ben ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to [EMAIL PROTECTED]
Re: Threads and Core Data, bindings results in view corruption
On Mar 30, 2008, at 7:50 PM, Ben Lachman wrote: I'm guessing the bugs really should be filed on the documentation since one page on performance of a highly complex API like CD is nowhere near enough. My guess is that documentation doesn't get as many bugs as it should since it is, at the point of the developer filing the bug, no longer a road block and therefore is kind of seen (wrongly) as a waste of time since it is just for the greater good of the dev community not getting your project done. There are two sets of bugs you should file. (1) better documentation for the current state of affairs and (2) better support for your work pattern in a future version of the framework. Developers need to file their own bugs. There are several reasons for that. First, to be able to check the status of an issue and track it over however long it takes to get fixed. Second, to be accessible to ADC for follow ups, clarifications in case we can't reproduce it, or receiving work arounds for known issues. Especially since once in a while, you might actually get back a work around that's better than what you came up with yourself. Of course, filing the issue before spending lots of time developing a workaround might also save you some effort once in a while. And so my shadowy masters actually believe real live developers have this problem, as opposed to my imaginary friends. Oddly 20 developers requested this seems to work better than we should spend lots of time on this because I feel like it And that just covers the problems we already know about. There are a few more reasons for filing bugs you've worked around ... Thanks for the feedback it was quite helpful. Any thoughts or tricks to reduce the frequency of saving in worker threads would be welcome, but I think I'm now on the right path. Batching and coalescing are both good ideas, so you're on the right track. Your other alternative is a proxy object for inserts, as I describe in one of the list archived messages I referenced earlier. You could also consider evaluating whether or not requiring Leopard makes sense for your customer base. At some point, there's a diminishing return on your effort to address a problem that $130 can mitigate. A compromise is to not perform the same threading on Tiger, or not in the same way, and accept a somewhat different user experience on older systems. - Ben ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to [EMAIL PROTECTED]
iPhone Interface builder
Hi everyone, I'm new to doing iPhone development and trying to get up to speed on the interface builder for iPhone. I see some basic tutorials on doing Cocoa based apps but can't seem to find anything on Cocoa touch and the interface builder. I know it was just released in Beta 2 but are there any walk through examples of creating a Cocoa Touch interface in IB? Thanks, Ben ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to [EMAIL PROTECTED]
re: Core Data faulting and bindings: recursive KVO notifications?
The problem I'm having arises when selecting all images at once (Command+A), if they are fairly large in number (in my store: ~2000). This takes an enormous time that is definitely O(n). Command-A should be instantaneous, even for selections 10x larger. The typical performance problems I've seen with array controller selections are (1) complex KVO observer actions cascade (2) tripping faults unnecessarily (3) using expensive array controller options. (1) Complex KVO observer actions need to be carefully constrained. If they simply grow organically, then it's pretty easy to fall into the trap of observers creating side effects that trigger other observers that cascade to yet more observers. This (a) makes your code impossible to understand, since no one ever intentionally designed their app that way from the beginning, and (b) sucks for performance. It's often easier to understand, and much faster, to use NSNotificationCenter to defer and coalesce observations for a batch operation like operating upon 2000 objects. One way to achieve this with the array controller is to remove all the objects from the controller, do your batch operation, and then add them back. (2) Firing faults unnecessarily is the canonical performance issue for Core Data developers. Our SQL logging (-com.apple.CoreData.SyntaxColoredLogging 1 -com.apple.CoreData.SQLDebug 1) and our Instruments template can help you find this, and identify which entities you're faulting excessively. If you need that data, it's much (10-100x) better to batch fetch the data instead. This is described in the Core Data Programming Guide under Performance. (3) Auto rearrange content can be very expensive. It can make the notification cascading from (1) worse. Also, Avoid empty selection Preserve selection can force the array controller to fire faults it otherwise wouldn't, which is expensive. Regarding the call into _didChangeValuesForKeys:, the API contract for KVO requires Core Data call -willChange/-didChange during faulting. This is pretty undesirable. This recurses further with all images in the controller selection until the whole object graph is in-memory. It is much slower (1 minute on a MBP with 2000 elements in the controller set) than loading the data in a normal manner, probably because of spread faulting and the large stack depth. If it's actually recursing through the entire graph, then it's probably a bug in your observer method. If it's looping, then it could simply be toggling off a few array controller options will address the issue. You should file a bug with bugreport.apple.com, and include the entire stack trace. Without the rest of it, it's hard for me to say if this is the expected stack depth or not. It may be a problem with one of your custom observation methods not coexisting happily with faulting, but it's a bit hard to tell from this excerpt. -- -Ben ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to [EMAIL PROTECTED]
Re: Core Data faulting and bindings: recursive KVO notifications?
On Mar 28, 2008, at 7:38 PM, Dennis Lorson wrote: On 28 Mar 2008, at 20:24, Ben Trumbull wrote: The problem I'm having arises when selecting all images at once (Command+A), if they are fairly large in number (in my store: ~2000). This takes an enormous time that is definitely O(n). Command-A should be instantaneous, even for selections 10x larger. The typical performance problems I've seen with array controller selections are (1) complex KVO observer actions cascade (2) tripping faults unnecessarily (3) using expensive array controller options. (1) Complex KVO observer actions need to be carefully constrained. If they simply grow organically, then it's pretty easy to fall into the trap of observers creating side effects that trigger other observers that cascade to yet more observers. This (a) makes your code impossible to understand, since no one ever intentionally designed their app that way from the beginning, and (b) sucks for performance. This seems like an easy mistake indeed. However, I checked my code for this when originally debugging the issue, and while it is difficult to eliminate all cases, no custom KVO observer triggers other observers as for my subclass implementation -- and if they do, they relate to disjunct entity objects that should not trigger others. You've bound the text fields to the selection poorly. That's the easiest and best fix. Other workarounds for your edification below. The good news is that the issue is entirely avoidable by batch faulting using the 10.5 [NSFetchRequest setReturnsObjectsAsFaults:NO] and executing the fetch on all objects in the selection. Yes. You can also do something like this to ignore KVO notifications around faulting: #import Cocoa/Cocoa.h @interface SubObject : NSManagedObject { @private BOOL _isAccessible; } - (BOOL) isAccessible; @end @implementation SubObject - (void) awakeFromInsert { [super awakeFromInsert]; _isAccessible = YES; } - (void) awakeFromFetch { [super awakeFromFetch]; _isAccessible = YES; } - (void) willTurnIntoFault { [super willTurnIntoFault]; _isAccessible = NO; } - (void) didTurnIntoFault { [super didTurnIntoFault]; _isAccessible = NO; } - (BOOL) isAccessible { return _isAccessible; } @end and elsewhere: - (void) observeValueForKeyPath:(NSString *)keyPath ofObject: (id)object change:(NSDictionary *)change context:(void *)context { if ([object isKindOfClass:[SubObject class]]) { SubObject* mine = (SubObject*)object; if (![mine isAccessible]) { return; } } // stuff } But still, I have two questions: - Am I overlooking something obvious? If it is the correct approach, someone else must have experienced this in a larger master- detail set, right? Yes, you should disable Allows Editing Multiple Values Selection when you expect selection to include more than a handful of objects. - While I understand the constraints the CD API imposes, shouldn't this be labeled as a bug? I'm not sure here, if so, I'll file it with bugreporter. You should file a bug and attach your sample app as well. (2) Firing faults unnecessarily is the canonical performance issue for Core Data developers. Our SQL logging (- com.apple.CoreData.SyntaxColoredLogging 1 - com.apple.CoreData.SQLDebug 1) and our Instruments template can help you find this, and identify which entities you're faulting excessively. If you need that data, it's much (10-100x) better to batch fetch the data instead. This is described in the Core Data Programming Guide under Performance. While I'm certain to perform some optimization here, the delay I was having was almost fully due to the issue above. It is indeed very useful, but in my case mostly to avoid the critical stack overflow. I will not be having 100.000+ stores so the excessive faulting has still little impact. Each fault is an I/O. Do a few batches v.s. 1,000 individual ones is much much better. You can see this in Instruments Core Data template, with the Cache Miss instrument. If it's actually recursing through the entire graph, then it's probably a bug in your observer method. If it's looping, then it could simply be toggling off a few array controller options will address the issue. You should file a bug with bugreport.apple.com, and include the entire stack trace. Without the rest of it, it's hard for me to say if this is the expected stack depth or not. It may be a problem with one of your custom observation methods not coexisting happily with faulting, but it's a bit hard to tell from this excerpt. As you can verify from the test project, I don't use any custom KVO logic. Still, the crash should occur almost every time, after a variable amount of time (seconds range). Yes, thanks. Sample projects
NSNoCellMask differences in Leopard vs. Tiger
On Tiger one could set up borderless, momentary light square button with an icon and call setHighLightsBy: with NSNoCellMask and you'd get a nice darkening on the non-transparent parts when the user pressed the button. However these same buttons on Leopard don't change at all during a user's press. Is there a way to get a similar effect on Leopard without using an alternate image (some of my buttons already have alternate images)? Thanks, -Ben -- Ben Lachman Acacia Tree Software http://acaciatreesoftware.com [EMAIL PROTECTED] 740.590.0009 ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to [EMAIL PROTECTED]
Re: dataCellForTableColumn method
Make sure the field editor isn't getting in the way. The field editors inserts itself into the first responder chain and grabs textual input during editing. http://developer.apple.com/documentation/Cocoa/Conceptual/ TextEditing/Tasks/FieldEditor.html HTH, -Ben -- Ben Lachman Acacia Tree Software http://acaciatreesoftware.com [EMAIL PROTECTED] 740.590.0009 On Mar 19, 2008, at 2:58 PM, Hans Hansen wrote: Anyone know how best to use multiple NSTextCell subclasses, in a table/outline column? When I use the dataCell... methods in NSTableColumn, NSTableView, or NSOutlineView, it works great until I try to edit the cell, at which point the cells never receive the edit/select actions. I've tried lots of things but can't figure out what's happening, nor a better why to do this overall. In other words: When I use the dataCellForTableColumn method, my table does display the different textcell subclasses returned. But when I send the table/outline [self editColumn:1 row:[self selectedRow] withEvent:theEvent select:YES] message it seems to get lost -- my specified cells don't receive an editWithFrame/selectWithFrame action. If I remove this method and only use one cell class in the column, it works as expected. - (NSCell *)outlineView:(NSOutlineView *)outlineView dataCellForTableColumn:(NSTableColumn *)tableColumn item:(id)item { if ([item isKindOfClass:[Project class]]) return projectTextCell; if ([item isKindOfClass:[Action class]]) return actionTextCell; if ([item isKindOfClass:[Item class]]) return itemTextCell; if ([item isKindOfClass:[Note class]]) return noteTextCell; return nil; } The point of this is to breakout my cell designs for efficiency and comprehension. But so far it's just making me nuts. ;-). ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to [EMAIL PROTECTED]
re: CoreData code working on Tiger - not on Leopard
Steve, You can get some more information. Add an @try/@catch block to your AppDelegate.m:700 line, and log both the exception and its userInfo dictionary. Also, if you search the archives for my recent post [ANN] 10.5.2 Core Data debug library available you can run against a version of Core Data that has assertions enabled. In addition to the multi-threading assertions, it has more just plain old assertions. Most of the problems I've seen like this have been issues with custom accessor methods doing things they shouldn't, or fetching within -awakeFromFetch:, or some odd edge cases involving delegate calls. If you build against the 10.4 SDK, and your application still doesn't work on Leopard, that's a bug, and you should file it with bugreport.apple.com. If it only fails building against the 10.5 SDK, then it could be helpful to review http://developer.apple.com/releasenotes/Cocoa/CoreDataReleaseNotes/index.html -- -Ben ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to [EMAIL PROTECTED]
NSButtonCell doesn't visually update during trackMouse:inRect:ofView:untilMouseUp:
I have a few NSButtonCells that I'm using in a custom view. I need them to track the mouse during clicks and do this by calling NSCell's trackMouse:inRect:ofView:untilMouseUp:. This works fine except that the button cells never update their graphical state by highlighting or whatever. However if I call performClick: on them the button updates as it should. Is the only solution to this to implement mouse tracking at the view instead of at the cell level? Thanks, -Ben -- Ben Lachman Acacia Tree Software http://acaciatreesoftware.com [EMAIL PROTECTED] 740.590.0009 ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to [EMAIL PROTECTED]
Re: NSButtonCell doesn't visually update during trackMouse:inRect:ofView:untilMouseUp:
So my view is a NSControl subclass and after playing with this some it seems you have to do one more thing. If you're going to have a control handle multiple cells (in my case button cells) you have to call setCell: for the correct cell in mouseDown: and then let super handle the mouse event. This seems to work much better than trying to handle the event yourself. Does this sound right to you Ken? In any case I think there should really be more info on how to subclass NSControl and NSCell. The developer docs are really sparse on this. I filed a bug asking for a guide on this topic (rdar:// 5804311). -Ben -- Ben Lachman Acacia Tree Software http://acaciatreesoftware.com [EMAIL PROTECTED] 740.590.0009 On Mar 17, 2008, at 4:25 PM, Ken Ferry wrote: On Mon, Mar 17, 2008 at 8:49 AM, glenn andreas [EMAIL PROTECTED] wrote: On Mar 17, 2008, at 1:42 AM, Ben Lachman wrote: I have a few NSButtonCells that I'm using in a custom view. I need them to track the mouse during clicks and do this by calling NSCell's trackMouse:inRect:ofView:untilMouseUp:. This works fine except that the button cells never update their graphical state by highlighting or whatever. However if I call performClick: on them the button updates as it should. Is the only solution to this to implement mouse tracking at the view instead of at the cell level? You need to set the control view of the cell to your view and then implement the appropriate [update|draw]cell[inside]: methods in your view. Or, a bit more specifically, setControlView: will fail to store anything if the passed view is not an NSControl. You can use an NSCell to purely stamp out drawing in an NSView, but more complicated interaction requires the view to be an NSControl, so that the cell can message the control in various ways. It isn't just updateCell:. Ken Ferry Cocoa Frameworks Basically a cell expects to be inside a control and needs to be able to tell that control to draw itself (and thus redraw the cell). One would think that the parameters to trackMouse would be sufficient to have the cell handle this by itself, but since a control could have a background behind the cell, it's really up to the control to decide how to redraw the cell. ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to [EMAIL PROTECTED]
Re: NSSpeechSynthesizer/UKSpeechSynthesizer speechSynthesizer:didFinishSpeaking: called immediarely [Solved]
I found the problem. I was having the speech synth speak a tag line before the main string and was getting the didFinishSpeaking: call back when the tag was cut off by the main string starting to be spoken. Thanks for confirming that it was my own fault. :-) -Ben -- Ben Lachman Acacia Tree Software http://acaciatreesoftware.com [EMAIL PROTECTED] 740.590.0009 On Mar 13, 2008, at 11:30 AM, Dave Verwer wrote: I have been using this callback extensively recently in the way you describe and have not seen this issue either. On 3/13/08, Paul Bruneau [EMAIL PROTECTED] wrote: On Mar 13, 2008, at 5:27 AM, Ben Lachman wrote: According to the NSSpeechSynthesizer docs: speechSynthesizer:didFinishSpeaking: is invoked when the speaking of the string ends. The second parameter of this method indicates whether the text was entirely spoken or was disrupted (as might happen if the user dismisses a spoken alert). This make me think that I should get my delegate method called when the speech stops in the users perception. However in my code I have it speak fairly long strings and the didFinishSpeaking: delegate method gets called back almost immediately. Is this correct behavior? I tried Uli's UKSpeechSynthesizer replacement for NSSpeechSynthesizer, but it seems to have the same issues. If this is the correct behavior, is there a way to figure out when the speech is actually done form the user's perspective (ie the audio output actually stops)? I'm trying to get a slide show type animation synced with speaking text and if I can't find out when the speech is done I'm not sure how I'm going to advance the animation at the correct time. Thanks, -Ben Hi- I don't see the behavior you are reporting. Aaron's book has a famous example that uses -didFinishSpeaking to disable a Stop button on an interface when the current speech completes, and it gets called exactly when the speech stops speaking. You can download his code and try it: http://bignerdranch.com/products/cocoa1.shtml Look for the solutions to the exercises link. The example I looked at is in the 05_HelperObjects folder and is called SpeakLine_D ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/dave.verwer% 40shinydevelopment.com This email sent to [EMAIL PROTECTED] -- e-mail: [EMAIL PROTECTED] web: http://shinydevelopment.com Shiny Development Ltd. is registered in England, Registration Number: 05805802. Registered Office: 4 Claridge Court, Lower Kings Road, Berkhamsted, Herts., HP4 2AF. ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/blachman%40mac.com This email sent to [EMAIL PROTECTED] ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to [EMAIL PROTECTED]
Re: File upload with NSURLRequest fails
I do this with a perl script on the back end. My experience was that its was more cajoling the perl script into working that the PHP side, but that may be because I'm not much of a perl wizard (maybe only level 8 or so :-). I found it was important to declare a filename if you're transferring data like this. Here is my code: NSMutableURLRequest *postRequest = [NSMutableURLRequest requestWithURL:aURL cachePolicy:NSURLRequestReloadIgnoringCacheData timeoutInterval:30.0]; NSString *boundary = @Boundary+AaB03x; [postRequest setHTTPMethod:@POST]; [postRequest addValue:[aURL] absoluteString] forHTTPHeaderField:@Referer]; [postRequest setValue:[NSString stringWithFormat:@multipart/form- data; boundary=%@, boundary, nil] forHTTPHeaderField:@Content-Type]; NSEnumerator *dictionaryEnumerator = [postDictionary keyEnumerator]; NSString *currentKey = nil; NSMutableData *multipartData = [NSMutableData data]; while( (currentKey = [dictionaryEnumerator nextObject]) ) { [multipartData appendData:[[NSString stringWithFormat:@[EMAIL PROTECTED] \n, boundary] dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:NO]]; id currentValue = [postDictionary objectForKey:currentKey]; if( [currentValue isKindOfClass:[NSData class]] [NSImageRep imageRepClassForData:currentValue] != nil ) { [multipartData appendData:[[NSString stringWithFormat:@Content- Disposition: form-data; name=\[EMAIL PROTECTED]; filename=\image.jp2\\r\n, currentKey] dataUsingEncoding:NSASCIIStringEncoding]]; [multipartData appendData:[@Content-Type: image/jp2\r\n dataUsingEncoding:NSASCIIStringEncoding]]; [multipartData appendData:[@Content-Transfer-Encoding: binary\r\n\r \n dataUsingEncoding:NSASCIIStringEncoding]]; [multipartData appendData:currentValue]; } } [multipartData appendData:[[NSString stringWithFormat:@[EMAIL PROTECTED] \n, boundary] dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:NO]]; [postRequest setHTTPBody:multipartData]; Hope this helps, -Ben -- Ben Lachman Acacia Tree Software http://acaciatreesoftware.com [EMAIL PROTECTED] 740.590.0009 On Mar 13, 2008, at 4:50 PM, Tom Harrington wrote: I'm trying to upload a file with the NSURL* API, but on the server end the PHP code is unable to decode the $_FILES array. The PHP code works fine when posted from an HTML form (and from clients on other platforms). Traffic sniffed on the wire looks good as far as I can tell, so what would be the problem? The code in question follows. NSString *urlString = @http://server:8080/php/post.php;; NSURL *url = [NSURL URLWithString:urlString]; NSString *requestMethod = @POST; NSMutableURLRequest *req = [NSMutableURLRequest requestWithURL:url]; [req setHTTPMethod:requestMethod]; NSString *headerFieldName; NSString *headerFieldValue; NSString *boundary = @-1234567890; headerFieldName = @Content-Type; headerFieldValue = [NSString stringWithFormat:@multipart/form-data; boundary=%@, boundary]; [req addValue:headerFieldValue forHTTPHeaderField:headerFieldName]; NSString *phone = @7195554321; NSDate *currentDate = [NSDate date]; NSDateFormatter *dateFormatter = [[[NSDateFormatter alloc] init] autorelease]; [dateFormatter setDateFormat:@MMddHHmmss]; NSString *dateString = [dateFormatter stringFromDate:currentDate]; // Will look something like this: form-data; name=file; filename=7195554321_1_20080311132327_jpg headerFieldValue = [NSString stringWithFormat:@form-data; name=\file\; filename=\[EMAIL PROTECTED]@_jpg\, phone, dateString]; NSMutableData *postBody = [NSMutableData data]; // Add boundary [postBody appendData:[[NSString stringWithFormat:@[EMAIL PROTECTED], boundary] dataUsingEncoding:NSUTF8StringEncoding]]; // Add form-data with filename [postBody appendData:[[NSString stringWithFormat:@Content-Disposition: [EMAIL PROTECTED], headerFieldValue] dataUsingEncoding:NSUTF8StringEncoding]]; // Add content-type [postBody appendData:[[NSString stringWithString:@Content-Type: null\r\n\r\n] dataUsingEncoding:NSUTF8StringEncoding]]; // Add image data [postBody appendData:imageData]; // Add boundary-- [postBody appendData:[[NSString stringWithFormat:@[EMAIL PROTECTED], boundary] dataUsingEncoding:NSUTF8StringEncoding]]; [req setHTTPBody:postBody]; NSHTTPURLResponse *res = nil; NSError *err = nil; NSData *data = [NSURLConnection sendSynchronousRequest:req returningResponse:res
Re: Can core data save to a remote file?
On Mar 14, 2008, at 2:02 AM, Kyle Sluder wrote: On Fri, Mar 14, 2008 at 1:34 AM, mmalc crawford [EMAIL PROTECTED] wrote: The canonical description is, it's an object graph management and persistence framework. It is not in and of itself an object store, and persistence is only one of its functions -- in some respects the less interesting one. So it manages a graph of objects and stores them. You can't do the second part without the first, and how often have you used Core Data without persistence in mind? You can in fact persistently store files without managing them as a really nifty easy to use, well performing, bindings enabled, undo- able object graph. Its called a filesystem. But most of us don't think they're so nifty anymore*. Also, it is quite attractive in some cases to use CoreData with only an in memory store, which isn't persistent as far as CoreData is concerned... and I'm guessing mmalc has some experience with this. -Ben *excepting ZFS, etc. -- Ben Lachman Acacia Tree Software http://acaciatreesoftware.com [EMAIL PROTECTED] 740.590.0009 ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to [EMAIL PROTECTED]
Re: Custom View drawn twice?
I think I finally solved this while chatting with Wil Shipley earlier this evening. Wil mentioned sometimes needing to display from the opaque ancestor which is basically what I was trying to do with the code Uli questioned. The way I was doing it was only partially successful at best. Given Wil's hints, I added the following to my drawing code and my drawing glitches are no more: - (void)drawRect:(NSRect)rect { static BOOL toggle = YES; if( toggle ) { toggle = NO; [[self opaqueAncestor] display]; return; } else { toggle = YES; } ... Thanks to all those who responded to my original post. Hopefully this will help someone else down the road. -Ben -- Ben Lachman Acacia Tree Software http://acaciatreesoftware.com [EMAIL PROTECTED] 740.590.0009 On Mar 5, 2008, at 4:22 PM, Ben Lachman wrote: displayIfNeededIgnoringOpacity goes back up the view hierarchy looking for an opaque superview to start drawing with. Doing so was causing an infinite drawing loop. I'm pretty sure this is because you're not really supposed to be calling setNeedsDisplay...: and displayIfNeeded...: within your drawRect: method. In any case it was a nasty hack to get correct looking functionality and I'm actually more interested in figuring out what is causing the double drawing than hack a fix on top of it. On Mar 3, 2008, at 5:38 AM, Uli Kusterer wrote: Am 29.02.2008 um 20:55 schrieb Ben Lachman: [self displayIfNeededIgnoringOpacity]; Is there a particular reason why you're calling this method? Won't plain old -displayIfNeeded do the job? ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to [EMAIL PROTECTED]
NSSpeechSynthesizer/UKSpeechSynthesizer speechSynthesizer:didFinishSpeaking: called immediarely
According to the NSSpeechSynthesizer docs: speechSynthesizer:didFinishSpeaking: is invoked when the speaking of the string ends. The second parameter of this method indicates whether the text was entirely spoken or was disrupted (as might happen if the user dismisses a spoken alert). This make me think that I should get my delegate method called when the speech stops in the users perception. However in my code I have it speak fairly long strings and the didFinishSpeaking: delegate method gets called back almost immediately. Is this correct behavior? I tried Uli's UKSpeechSynthesizer replacement for NSSpeechSynthesizer, but it seems to have the same issues. If this is the correct behavior, is there a way to figure out when the speech is actually done form the user's perspective (ie the audio output actually stops)? I'm trying to get a slide show type animation synced with speaking text and if I can't find out when the speech is done I'm not sure how I'm going to advance the animation at the correct time. Thanks, -Ben -- Ben Lachman Acacia Tree Software http://acaciatreesoftware.com [EMAIL PROTECTED] 740.590.0009 ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to [EMAIL PROTECTED]
Re: Autorelease question
If you use convenience methods (as in the else branch) it is autoreleased. See here for details: http://developer.apple.com/documentation/Cocoa/Conceptual/MemoryMgmt/Concepts/ObjectOwnership.html#//apple_ref/doc/uid/2043 On Thu, Mar 13, 2008 at 8:19 AM, Daniel Luis dos Santos [EMAIL PROTECTED] wrote: Hello, I have the following code : if (![fileMgr fileExistsAtPath: indexFilePath]) { NSMutableDictionary *index = [[NSMutableDictionary alloc] init]; [index setObject: [NSNumber numberWithLong: DEFAULTS_BLOCKSIZE] forKey: INDEXKEY_BLOCKSIZE]; [index setObject: [NSNumber numberWithLong: DEFAULTS_BLOCKSPERPAGE] forKey: INDEXKEY_BLOCKSPERPAGE]; _blockSize = DEFAULTS_BLOCKSIZE; _blocksPerPage = DEFAULTS_BLOCKSPERPAGE; if (![index writeToFile: indexFilePath atomically: YES]) { _dirPath = nil; NSLog(LOGMSG_INDEXFILENOTWRITABLE); } [index release]; } else { NSDictionary *index = [NSDictionary dictionaryWithContentsOfFile: indexFilePath]; if (nil == [index objectForKey: INDEXKEY_BLOCKSIZE]) { NSLog(LOGMSG_INDEXFILEOUTOFFORMAT); _dirPath = nil; } else _blockSize = [(NSNumber*)[index objectForKey: INDEXKEY_BLOCKSIZE] longValue]; if (nil == [index objectForKey: INDEXKEY_BLOCKSPERPAGE]) { NSLog(LOGMSG_INDEXFILEOUTOFFORMAT); _dirPath = nil; } else _blocksPerPage = [(NSNumber*)[index objectForKey: INDEXKEY_BLOCKSPERPAGE] longValue]; [index release]; } the [index release] on the second branch gives me the following output on the debugger window : TestRunnrer(1661) malloc: *** error for object 0x112a50: double free *** set a breakpoint in malloc_error_break to debug in the enclosing scope I have set up an autorelease pool. What I am suspecting is that when I init the dictionary with a file it is autoreleased, and then the error when I do the release. I this the case ? If so where do I know when some object is created autoreleased or not ? In the NSDictionary's reference page there is nothing mentioned. Many thanks ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/minustheben%40gmail.com This email sent to [EMAIL PROTECTED] -- Ben Hatfield [EMAIL PROTECTED] ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to [EMAIL PROTECTED]
[ANN] 10.5.2 Core Data debug library available
All, For ADC members, debug libraries for 10.5, and now 10.5.1 10.5.2, are available in the Developer Tools section of Downloads as Debug and Profile Libraries for Mac OS X 10.5. There's a tech note about how to use these frameworks with DYLD_IMAGE_SUFFIX. 'man dyld' also works. Since there are many different debug libraries, one might consider renaming the suffix for just the libraries with which you currently need to work. (i.e. CoreData_debug - CoreData_threading) For Core Data developers, the most interesting aspect of this is the addition of assertions to enforce Core Data's multi-threading policy. You can enable these assertions by setting the user default -com.apple.CoreData.ThreadingDebug 3 (in cmd line style) This works best run in gdb with some additional breakpoints: future-break handleFailureInMethod:object:file:lineNumber:description: future-break handleFailureInFunction:file:lineNumber:description: future-break malloc_printf As a tangent, while not necessarily errors, I find it useful to sometimes toggle these: future-break raise:format:arguments: future-break objc_exception_throw future-break +[NSError errorWithDomain:code:userInfo:] -- -Ben ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to [EMAIL PROTECTED]
re: sorting large tables
Unfortunately, the table is not KVO-compliant so I cannot use NSSortDescriptor. And I need to pass the primary and secondary sort fields at runtime, so I cannot use sortUsingSelector since it takes no parameters. NSSortDescriptor requires an object be *KVC* compliant. It does not use KVO. Since KVC does a pretty good job of inferring keys from method names, typically one has to actually put some effort into breaking KVC compliance. Now, NSSortDescriptor does cache some of the results from KVC, so I suppose if you're doing something pretty whacky like having fake keys that return the result of a computation every time (like random or a series) you might not get the results you expect. Of course, trying to sort on such a key is probably semantically meaningless, so I hereby assert NSSortDescriptor's behavior is still correct ;) I am using sortArrayUsingFunction: context: to sort a fairly large table (100k recs). Judging from the readout of comparisons being made the sort appears to be about 80% done when everything comes to a halt. No message, no nothing. It just stops. Run it in gdb, then hit control-C. What does it look like in top ? Is your heap huge ? Is the machine thrashing (swapping to disk) ? Also, if it's a stray pointer problem, you could try guard malloc (man libgmalloc) I'd really appreciate suggestions on how to 1) get through this file using the function I set up and 2) ideas on alternative approaches that will be able to handle much larger files for the future. Sorting much larger files will require some effort on your part. First, you'll want to tune your current performance. Creating temporary objects during the comparison function is bad. If you absolutely have to, make sure you use -alloc/init and explicitly -release and avoid autorelease objects and objects from convenience constructors. -autorelease just won't fly in a comparison method for a 100,000 objects. This may mean your accessor methods need to be changed so they don't impair the comparison method. You definitely don't want to work with all the data at once. You want to stream through it in a nice batch size, which is large, but nothing that will put memory pressure on the overall system. Depending on your system and deployment target that could 10MB or 100MB. Typically there are diminishing returns as the batch size grows, so some empirically testing (binary search style) should quickly give you an idea. One nice thing about sorting, is that this is easy to do: merge sort. You can break up the problem as much as you want, and use any handy sort function, and then merge the pieces together. Algorithms for merging are readily available on the net. Ask google. It's about 1 page of code to use qsort_r() and a hand written merge function. Merge sort is trivially parallelizable with NSOperationQueue, so you can speed things up more when you're ready to tackle that. It's 1 page of code to allocate, build dependencies, and run a fully concurrent merge sort this way. -- -Ben ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to [EMAIL PROTECTED]
NSLayoutManager boundingRectForGlyphRange:actualCharacterRange: inconsistent results?
To place markers in my rulerview I'm using NSLayoutManager's boundingRectForGlyphRange:actualCharacterRange: to get a rect of a chunk of text that I can base my marker location off of. However when I do programatic updates to my text storage and reset markers the same function gives me rects that don't always account for some newly wrapped lines. Has anyone run into anything like this? Or is there a better way of getting the location of a range of characters than using this method? Thanks, -Ben -- Ben Lachman Acacia Tree Software http://acaciatreesoftware.com [EMAIL PROTECTED] 740.590.0009 ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to [EMAIL PROTECTED]
Re: Causing CFLog error messages
On Mar 10, 2008, at 2:49 AM, Ron Fleckner wrote: On 10/03/2008, at 5:34 PM, Kevin Dixon wrote: 2008-03-10 02:30:08.571 StretchFix[2232] CFLog (0): CFMessagePort: bootstrap_register(): failed 1103 (0x44f), port = 0x3103, name = 'com.YSPf.StretchFix.ServiceProvider' See /usr/include/servers/bootstrap_defs.h for the error codes. 2008-03-10 02:30:08.572 StretchFix[2232] CFLog (99): CFMessagePortCreateLocal(): failed to name Mach port (com.YSPf.StretchFix.ServiceProvider) What do these mean, and how might I be causing them? Thanks! If I remember correctly, this happened to me when I ran my app from Xcode but already had the app running. You know, add some code, run the app, correct code, run the app... oops, forgot to quit it first. Specifically it happens most often when you're running the app in the debugger and then launch it without the debugger. Otherwise Xcode catches it and quits the process (either in the debugger or normally). -Ben -- Ben Lachman Acacia Tree Software http://acaciatreesoftware.com [EMAIL PROTECTED] 740.590.0009 ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to [EMAIL PROTECTED]
Re: NSURLDownload and userInfo
Alternatively, if you're managing more than two requests at a time you can declare a mutable array of connections and then build a dictionary for each connection that includes any info you want you delegate to have available. I have a method that build the connection dict for a connection like this: [self _connectionDictionaryWithConnection:[NSURLConnection connectionWithRequest:postRequest delegate:self] ofType:type andObject:object selector:aSelector context:contextInfo]; which uses this method: - (NSDictionary *)_connectionDictionaryWithConnection: (NSURLConnection *)connection ofType:(NSString *)type andObject:(id) object selector:(SEL)aSelector context:(void *)contextInfo { return [NSDictionary dictionaryWithObjectsAndKeys: connection, @connection, type, @type, [NSMutableData data], @data, object, @object, contextInfo, @context, NSStringFromSelector(aSelector), @selector, nil]; } and then to retrieve it I call: - (NSDictionary *)_connectionDictionaryForConnection:(NSURLConnection *)connection { NSArray *matchArray = [connections filteredArrayUsingPredicate: [NSPredicate predicateWithFormat:@connection == %@, connection]]; if( [matchArray count] 1 ) NSLog(@multiple connection matches\n); if( ! isEmpty(matchArray) ) return [matchArray lastObject]; else return nil; } Perhaps not the most efficient, but work for my 10-15 concurrent often changing connections. HTH, -Ben -- Ben Lachman Acacia Tree Software http://acaciatreesoftware.com [EMAIL PROTECTED] 740.590.0009 On Mar 10, 2008, at 9:22 AM, Clint Shryock wrote: Do you have two instances of NSURLDownload? if they are declared in the .h file you could test for equality in the downloadDidFinish: delegate method. - (void)downloadDidBegin:(NSURLDownload *)download { if(download == myNSURLDownloadA) { // something for a } if(download == myNSURLDownloadB) { // something for b } } 2008/3/9 Trygve Inda [EMAIL PROTECTED]: I am using NSURLDownload and NSURLRequest to download 2 different types of data (A B)... Both of which are related to the same class so they share delegate methods. In my delegate, when there is an error or successful completion I need to call one process method for A and a different one for B. To enable this, is there a way to attach some sort of userInfo type (even an int) to either the NSURLDownload or NSURLRequest... Or should I subclass one of them to add a variable? ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to [EMAIL PROTECTED]
Re: NSURLDownload and userInfo
On Mar 10, 2008, at 9:52 PM, Jens Alfke wrote: On 10 Mar '08, at 6:35 PM, Ben Lachman wrote: Alternatively, if you're managing more than two requests at a time you can declare a mutable array of connections and then build a dictionary for each connection that includes any info you want you delegate to have available. I think it's cleaner just to declare a class with that info as its instance variables, and then use a separate instance of that class as the delegate for each connection. That way you're working _with_ the API instead of around it. —Jens I don't know if I agree with the working with the APIs bit. I think it's obvious that the APIs expect a single delegate to be able to handle multiple objects using it concurrently, thus the passing of the object that is delegating to the delegate. Creating 15 delegate objects over and over again (in my case every time a user does a search, submit, etc.) doesn't seem to be a very clean solution as it spreads your networking code out. You'd basically have to have a class that starts your connections and then have another class that is the connection's delegate and then possibly have one of those two classes, or another one, handle cleaning up or whatever (assuming you do something with any data you receive after connectionDidFinishLoading:). I'd rather start connections, handle their delegate calls and handle the retrieved data within a single class, this is cleaner in my mind. I also think Jens' general solution ends up being a proponent of lots of small, barely there, classes. While I'm not a proponent of monolithic classes I feel like it is all too easy to end up with either huge numbers of class files that contain basically no code and just make project management harder or files with multiple classes per file which also makes project management harder (worse of the two, IMO). Xcode largely makes it quite easy to find the method you're looking for so I really don't see the benefit of splitting things down to the one/variable class point. -Ben -- Ben Lachman Acacia Tree Software http://acaciatreesoftware.com [EMAIL PROTECTED] 740.590.0009 ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to [EMAIL PROTECTED]
Re: -[NSMenu popUpContextMenu:withEvent:forView:] crashing in __isSystemFont on 10.5.2
EXC_BAD_ACCESS. But I think I found the issue. I wasn't retaining the font returned by menuFontForSize:. What threw me off was that this never caused a problem in Tiger (perhaps it is a static instance that is returned there) but did on Leopard. No idea of the reason for the change though. Thanks, -Ben -- Ben Lachman Acacia Tree Software http://acaciatreesoftware.com [EMAIL PROTECTED] 740.590.0009 On Mar 7, 2008, at 4:49 PM, Kyle Sluder wrote: On Fri, Mar 7, 2008 at 4:31 PM, Ben Lachman [EMAIL PROTECTED] wrote: In my custom view I call [NSMenu popUpContextMenu:contextMenu withEvent:theEvent forView:self] during mousDown: in some cases. It sometimes crashes during this call in [NSFont __isSystemFont]. The menu I'm giving it has multiple sizes of the default menu font in it. Any ideas why this is happening? Same code works fine on Tiger. What's the actual crash? --Kyle Sluder ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to [EMAIL PROTECTED]
Textview not resizing in Leopard
Ok, last question of the day. I have a textview (enclosed in the normal scrollview) that resizes fine in Tiger but in Leopard is clipped on the bottom. The text container is set to track the textview width and the textview is set to be vertically resizable but not horizontally resizable. Its autoresizing mask is set to width and height sizable. Both the scrollview and the clip view appear to have the correct frame/bounds while the textview's frame is incorrect. Anyone run into something like this? I googled a bunch of related terms and came up with almost nothing. TIA, -Ben -- Ben Lachman Acacia Tree Software http://acaciatreesoftware.com [EMAIL PROTECTED] 740.590.0009 ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to [EMAIL PROTECTED]
Re: Custom View drawn twice?
displayIfNeededIgnoringOpacity goes back up the view hierarchy looking for an opaque superview to start drawing with. Doing so was causing an infinite drawing loop. I'm pretty sure this is because you're not really supposed to be calling setNeedsDisplay...: and displayIfNeeded...: within your drawRect: method. In any case it was a nasty hack to get correct looking functionality and I'm actually more interested in figuring out what is causing the double drawing than hack a fix on top of it. -Ben -- Ben Lachman Acacia Tree Software http://acaciatreesoftware.com [EMAIL PROTECTED] 740.590.0009 On Mar 3, 2008, at 5:38 AM, Uli Kusterer wrote: Am 29.02.2008 um 20:55 schrieb Ben Lachman: [self displayIfNeededIgnoringOpacity]; Is there a particular reason why you're calling this method? Won't plain old -displayIfNeeded do the job? Cheers, -- Uli Kusterer The Witnesses of TeachText are everywhere... http://www.zathras.de ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to [EMAIL PROTECTED]
re: Core Data, SQLite, and Housekeeping
... so that's fine, but SQLite's documentation says of auto_vacuum: When the auto-vacuum flag is 1 (full), the freelist pages are moved to the end of the file and the file is truncated to remove the freelist pages at every commit. Note, however, that auto-vacuum only truncates the freelist pages from the file. Auto-vacuum does not defragment the database nor repack individual database pages the way that the VACUUM command does. In fact, because it moves pages around within the file, auto-vacuum can actually make fragmentation worse. Okay, well that sucks. So now the question is this: does Core Data implicitly run VACUUM? If so, when? How often? Unfortunately googling and archive-searching did not produce any obvious answers to this particular question. My guess is that the answer is, Yes, at every save, but I'd like to be sure and I'm not familiar enough with SQLite to know how to test this myself. Any takers? No, Core Data does not implicitly run a manual vacuum. Such a vacuum recreates the database file from scratch and then (conceptually) swaps it for the current database file. It can be extremely expensive for large files or files on network mounts, although for most files it's reasonable but slow. The framework can't really know when it's an acceptable time for your app to pause for several to many seconds to do this kind of house keeping. Also, small to medium sized databases with proper indices are very fast, and the benefit to a vacuum back to a clean state is low. Running a manual vacuum at every save would be crazy. Even if you were running very large saves for a gigantic import operation, you'd rather vacuum at the end of the application specific import. That way you could have multiple threads/processes running the import, and the added concurrency would utterly overwhelm any small benefit to defragmentation. For larger databases, reducing internal fragmentation can make a significant difference, especially on lower end hardware/laptops. Laptops typically use much slower drives, and often have less RAM, so they pay a heavy penalty for fragmentation. On modern desktop hardware, the kernel does a pretty amazing job so it can be challenging to observe this problem. Even a vanilla config Mac Pro is a monster compared to most laptops. Since the vacuum command recreates the file, it also reduces external fragmentation which is usually a more significant problem (i.e. fragmentation of the file across the device). If you have any performance data showing problems with internal db fragmentation (i.e. sqlite3 dbname 'vacuum' fixes it, but cp doesn't), we'd love to hear about it. bugreport.apple.com -- -Ben ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to [EMAIL PROTECTED]
Re: Core Data, SQLite, and Housekeeping
If you have any performance data showing problems with internal db fragmentation (i.e. sqlite3 dbname 'vacuum' fixes it, but cp doesn't), we'd love to hear about it. Thanks, Ben, for this informative response. So what you're saying, in summary is: 1 - Vacuuming on every save is inefficient to the point of silliness. Yup. Kinda defeats the point of having incremental load/saves in a transactional persistent store. 2 - For anything but very large databases and/or running on slow hardware, the benefits of vacuuming is minimal anyway. Your mileage may vary as to what exactly constitutes a large database, but for smaller databases and faster hardware there is a diminishing return. Certainly, there are cases where vacuuming makes sense. One might perform a manual vacuum after a initial import, especially for a large database (i.e. the cost for the vacuum is balanced by many future queries) or after a significant operation like upgrading to a new version. To that, I pose another question: Why, then, does it make such a huge difference when I run the vacuum command against Mail's database? After just a month of usage, Mail seems sluggish when switching between various folders, but once I run the vacuum command, it is once again snappy? Well, many people run Mail constantly so the database is experiencing a significant amount of churn over a month, and the envelope index is often quite large. A month of incessant use is a nice chunk of uptime. You can see I/O performance using the fs_usage command. If you're experiencing a large amount of fragmentation, the response times on the I/Os will increase as the drive has to seek more. You can compare the performance gain from vacuuming the Mail index to simply using cp to create a new index file. If the drive has a nice chunk of free space, OSX will try to keep the file's blocks close together when creating the copy. The point at which a manual vacuum pays for the cost of rewriting the file depends on a lot of factors. -- -Ben ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to [EMAIL PROTECTED]
Re: Undo and Core Data issue
At 6:58 PM -0800 3/5/08, Michael Latta wrote: The calls are on the Will/Did undo/redo notifications not the KVO callbacks on object changes. Ah, okay. There shouldn't be any need to call -processPendingChanges there, unless you're programmatically working with your own undo groups. What I am seeing is that my code changes a managed object property, I undo, and no change occurs in the managed object. The property affected is a binary attribute (a CATransform3D as bytes). Does your code changing the property trigger a KVO event (i.e. are you missing a call to -willChangeValueForKey:) ? Do you see notifications from the MOC when you initially make the change ? Are you undoing programmatically or as a user ? The undo behaves the same as before I added any notification processing however. That suggests the problem lies elsewhere. -- -Ben ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to [EMAIL PROTECTED]
CoreData fed ImageView blank on first run.
I have an NSImageView subclass that displays thumbnails of a CoreData attribute via its value binding. The thumbnail (an NSImage) is stored as a transient attribute and updated lazily as needed. This all works and looks great except for the first time the app is launched(and sets up a lot of state). Throughout this run the ImageView is blank white. Debugging leads me to believe that the bindings seem to be intact and that the data is correct coming out of coredata, however the ImageView never gets a drawRect: call even when it's direct superview does. Anyone run into something like this or have any pointers? Thanks, -Ben -- Ben Lachman Acacia Tree Software http://acaciatreesoftware.com [EMAIL PROTECTED] 740.590.0009 ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to [EMAIL PROTECTED]
Tabless NSTabView IB3 Bug
I'm trying to use a tabless NSTabView in IB3. Before Leopard, you could double-click the space towards the top of the view and select the tabs, even though there was no visible tab. I also believe there was a control in the inspector to specify current tab? Anyway, none of these methods work in IB3. So if you create a tabless tab view there's no way to change the current tab in interface builder without changing to a tabbed type (which offsets sizes and positions). I have a hard time believing this has gone unnoticed. Am I missing something? ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to [EMAIL PROTECTED]
Re: Tabless NSTabView IB3 Bug
Yea, I know that. But shouldn't there be a more accessible way? I don't use the browser/outline view much and it used to be much easier to change between tabs. Ben On Mar 4, 2008, at 11:10 AM, Benjamin Stiglitz wrote: I'm trying to use a tabless NSTabView in IB3. Before Leopard, you could double-click the space towards the top of the view and select the tabs, even though there was no visible tab. I also believe there was a control in the inspector to specify current tab? Anyway, none of these methods work in IB3. So if you create a tabless tab view there's no way to change the current tab in interface builder without changing to a tabbed type (which offsets sizes and positions). I have a hard time believing this has gone unnoticed. Am I missing something? You can use the nib’s document window’s outline view to switch between the tabs. -Ben ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to [EMAIL PROTECTED]
Re: Core Data and retain count
Bill, On Mar 2, 2008, at 5:35 PM, Ben Trumbull wrote: My question is, why would changing a property value cause another property to have its retain count increase? No idea. Why don't you run it in gdb and break on the -retain method and get some stack traces ? This works best if the class you're debugging (in this case the value window controller) has a custom retain/release method that you can break on instead of NSObject's etc. If it doesn't, you can trivially make one by adding a category on it and putting -retain/- release/-autorelease methods on it that simply call super. Good idea. Here's the stack trace: #0 0x29aa in -[NSWindowController(MainWindow) retain] at MainWindowController.m:35 #1 0x92dfa378 in -[NSManagedObject(_NSInternalMethods) _newPropertiesForRetainedTypes:andCopiedTypes:preserveFaults:] #2 0x92dfa250 in -[NSManagedObject(_NSInternalMethods) _allProperties] #3 0x92dfa185 in -[NSManagedObjectContext(_NSInternalChangeProcessing) _establishEventSnapshotsForObject:] #4 0x92dfd516 in _PFFastMOCObjectWillChange #5 0x92dfb4e3 in -[NSManagedObject willChangeValueForKey:] #6 0x00021a6c in -[Window setOpenAtLaunch:] at Window.m:117 Not sure what to make of it, nor why setting the property openAtLaunch increments the retain count for the window controller property. At a low level, what's going on is that you're dirtying a managed object and Core Data is taking a snapshot of the previous state for this user event. The snapshot supports undo, rollback, and the merge policies, among other odds and ends. This snapshot may be pushed onto the undo stack, or simply kept around until you -save:, -rollback, or -reset the NSManagedObjectContext At a high level, you've created a retain cycle between the M V layers of the MVC pattern. After some thought, it seems a bit weird to make the NSWindowController an attribute of a managed object. Technically, you could solve this problem by making it an unmodeled property (ivar). However, this is probably a symptom of a larger design issue. -- -Ben ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to [EMAIL PROTECTED]
Re: Custom View drawn twice?
, 470}, {400, 24}} 18.461 RVApp[25760] BackgroundView: drawRect: 18.473 RVApp[25760] TextView: drawRect: 18.479 RVApp[25760] MagnetClipView: setNeedsDisplayInRect:{{0, 0}, {160, 200}} 18.479 RVApp[25760] MagnetClipView: drawRect: 18.481 RVApp[25760] MagnetClipView: setsNeedsDisplay:NO 18.481 RVApp[25760] RVImageView: drawRect: 18.489 RVApp[25760] MagnetView: drawRect: 18.490 RVApp[25760] BackgroundView: setsNeedsDisplay:NO **Top of Run loop** -- Ben Lachman Acacia Tree Software http://acaciatreesoftware.com [EMAIL PROTECTED] 740.590.0009 On Feb 29, 2008, at 5:52 PM, Ken Ferry wrote: I don't see a problem in your drawRect: code, so it'd be in something you haven't posted. Perhaps you could post a sample application? One possibility is that your -isOpaque method returns YES, so the view system thinks it doesn't have to redraw your superview before asking you to draw. If you're subclassing NSView, you'd have to opt-in to return YES from -isOpaque, but if you're subclassing a deeper AppKit view class, it may already be marked as opaque. ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to [EMAIL PROTECTED]
re: Core Data and retain count
My question is, why would changing a property value cause another property to have its retain count increase? No idea. Why don't you run it in gdb and break on the -retain method and get some stack traces ? This works best if the class you're debugging (in this case the value window controller) has a custom retain/release method that you can break on instead of NSObject's etc. If it doesn't, you can trivially make one by adding a category on it and putting -retain/-release/- autorelease methods on it that simply call super. So by the time the user wants to delete a managed object from the list, the window controller could have a high value and is never released! This sounds like a hypothetical concern as opposed to an empirically observed leak. Each retainer is obliged to balance itself out eventually. That's not your problem. Generally speaking, the retain count is an implementation dependent value and not really meaningful API. - Ben ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to [EMAIL PROTECTED]
Re: NSTextField and NSTextAttachment
I'd say the field editor is the problem. NSCell provides setAttributedStringValue: and I assume stores and displays that value as well as reacting to clicks when not editing. Once you begin editing the firstResponder is set to the field editor and your textfield becomes its delegate, so for all intents and purposes the z- order has changed. So at this point you need to deal with the field editor using the delegate methods. I'd say textView:clickedOnCell:inRect:atIndex: and friends looks promising (of course you'll need to subclass NSTextField). your other option would be to implement a custom field editor, but I think this would probably end up being a lot more work. Hope this helps, -Ben -- Ben Lachman Acacia Tree Software http://acaciatreesoftware.com [EMAIL PROTECTED] 740.590.0009 On Feb 26, 2008, at 11:11 PM, Sean Willson wrote: i've created a NSTextView and placed one or more NSTextAttachment within it that wrap controls and i'm able to get the behavior of clicking the control etc as i want. however when i place the same NSTextAttachment in a NSTextField via: [textField setAttributedStringValue:[NSAttributedString attributedStringWithAttachment:attachment]]; it doesn't behave at all like the NSTextView. well let me extrapolate it behaves the same as textview in that if i DON'T click into the TextField but do click on the control it works fine. if i however click into the textfield first, the control associated with the attachment doesn't receive any mouse events after that and it's almost as if it's not sitting in the same z-order as it is when it's in the textview. i was wondering if anyone knew what was happening here? is the FieldEditor getting placed above it when mousedown is performed in the text field? is there any magic i can do to reorder it so that the embedded control can get mouse events? ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to [EMAIL PROTECTED]