Re: Cocoa bug? release/removeObserver from inside observeValueForKeyPath
On 30.5.2008, at 00:53, Hamish Allan wrote: On Thu, May 29, 2008 at 11:15 PM, Geoff Schmidt <[EMAIL PROTECTED] > wrote: 3) If this is already known, is there a customary pattern for avoiding the problem? "Never release from observeValueForKeyPath" is a bit harsh! I don't know if it's known, but you could try [obj performSelector:@selector(release) withObject:nil afterDelay:0] instead of [obj release] Or use [obj autorelease] instead of [obj release] which should be pretty much the same with less typing. Again, you probably need to be able to handle the extra observeValueForKeyPath: (My guess is that when A receives observeValueForKeyPath:, it is already too late to still remove B from the list of objects which will be notified. Most likely some kind of copy is made of the list of objects to notify internally by Cocoa.) Kai if you don't mind getting the extraneous observeValueForKeyPath:... for that obj (it could have an "about to be released" flag which would cause it to ignore the observeValueForKeyPath:...) Hamish ___ 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/kai%40granus.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: Problems with a Layer backed NSView in a NSScrollView
Hi, I am not sure whether this is relevant for your problem, but it might be useful to know that the content view of a scroll view gets a CATiledLayer instead of a normal CALayer via [setWantsLayer:YES]. The reasoning is that the content view can be potentially large and easily exceed the max size of OpenGL textures. Besides being tiled, CATiledLayer updates its contents lazily and in some background thread, if I remember correctly. In any case, it is different. Best Kai On 19.6.2008, at 19:54, Moray Taylor wrote: Thanks for the reply... I've tried [[[self pageScrollView] contentView] setWantsLayer:YES]; This results in a still flipped display, and very badly corrupted, lots of artifacts etc [[self pageScrollView] setWantsLayer:YES]; Nice display, but still flipped. The transform that used to work before I tried the above line makes no difference if I set the scrollview to be layer backed. Any ideas? --- On Thu, 19/6/08, Scott Anguish <[EMAIL PROTECTED]> wrote: From: Scott Anguish <[EMAIL PROTECTED]> Subject: Re: Problems with a Layer backed NSView in a NSScrollView To: [EMAIL PROTECTED] Date: Thursday, 19 June, 2008, 5:50 PM have you tried just setting the contentview of the scroll view to layer backed? otherwise you can remvoe the extra transofrm you added to the view itself. On Jun 19, 2008, at 11:38 AM, Moray Taylor wrote: Hi there! I've been tearing my hair out trying to figure this out, so hopefully someone will take pity! Basicaly, I've a CALayer-backed custom view, which works pretty great, I use a transform to flip it, and it works fine, the problem happens when I put it in a NSScrollView If I put it in the scrollview, and set the scrollview's setWantsLayer to YES, then it works good, very fast and smooth scrolling, BUT, it's completely upside down! If I setWantsLayer to NO, then it's the right way up, but jerky and generally doesn't work (i.e. the scroll bar doesn't do anything in the scrollview) I've tried flipping and unflipping the view, applying a transform to the CALayer (I had a transform to begin with, removed it, no difference), nothing I do will flip it back! Please help! Thanks Moray __ Sent from Yahoo! Mail. A Smarter Email http://uk.docs.yahoo.com/nowyoucan.html ___ 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/scott%40cocoadoc.com This email sent to [EMAIL PROTECTED] __ Sent from Yahoo! Mail. A Smarter Email http://uk.docs.yahoo.com/nowyoucan.html ___ 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/kai%40granus.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: PDFKit guidance
On 20.6.2008, at 13:47, Torsten Curdt wrote: On Jun 20, 2008, at 13:09, Antonio Nunes wrote: On 20 Jun 2008, at 11:07, Torsten Curdt wrote: you can't go wrong by reading the "Cocoa Drawing Guide." Surely will read through that. Because frankly speaking I didn't think this was Quartz related. Well, you need to know how to generally draw in Cocoa, and you need to know how to take advantage of PDFKit, so both John Calhoun and Joel Norvell provided useful pointers. The scaling is done when a PDFPage needs to be drawn, so you need to implement it in your subclass's drawWithBox: method. Use an affine transform set up to serve your needs and apply it to the current graphics context within the drawWithBox: method before drawing the page. Right. The point though is - I don't really want to display it. So I did not look into the drawing side of things. But I guess I just read up on the Quartz stuff and then get back to you guys (if needed). I assume one could also draw in memory - without displaying. Just didn't know that's the right direction. You just should be aware that Quartz rewrites the PDF from scratch when using this approach. That is, while still showing the same grafics, the result is a completely new PDF file with potentially very different structure. Plus, since Quartz is about displaying, some non- display properties of the original PDF may be lost. Its a while ago that I last checked (Tiger, I think), but I would be surprised if Quartz became perfect in this respect in the meantime. Depending on your application, this may be between no problem and inacceptable. Greetings Kai ___ 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: Newbie question: error in creating a NSData object using handle (Resource Management)
Hi, "I GOT AN ERROR HERE" may be a little too unspecific. Perhaps you can elaborate: crash, exception, nil return, Console entry, what else? That said, you should use GetHandleSize (dataHandle) instead of GetResourceSizeOnDisk(dataHandle). GetResourceSizeOnDisk() can return values which are too large (see documentation). Ah, and I just see that you combinded CountResources with Get1IndResource, that’s probably wrong. You should use CountResources with GetIndResource or Count1Resources with Get1IndResource. Neither of this directly explains the difference between using NSData and the direct copy. But since you potentially access non existing bytes or data, that may be coincidence. Best Kai Hi folks,I'm a newbie to Cocoa. Recently, I'm working on a project relating to Resource Management. In my project, there's a part that I'm reading through the resources in a resource file. I'm using: int count = CountResources( typeName ); to get all resource that has the type "typeName", then loop through this resource list to take resource data out. for (n = 1; n <= count; n++) { Handle dataHandle = Get1IndResource( type1, n); NSData *data = [NSData dataWithBytes: *dataHandle length: GetResourceSizeOnDisk(dataHandle)]; // I GOT AN ERROR HERE //using data struct A_STRUCT aStruct; memcpy(& aStruct,[data bytes], [data length]); } After several times looping through the list, I got an error in the line above. But if I use data directly, like the following code, there is no error occurred. memcpy(&pgControlRes,*dataHandle, GetResourceSizeOnDisk(dataHandle)); Any suggestions for my problem. I highly appreciate all your helps. ___ 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/kai%40granus.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: Newbie question: error in creating a NSData object using handle (Resource Management)
On 25.6.2008, at 10:42, Tran Kim Bach wrote: Thanks Ken and Kai for your very very quick responses This is my first post in the list, I'm sorry for not clarifying my problem. Actually, the program stopped at the mentioned line. In console, it said something like: objc[2144]: FREED(id): message release sent to freed object=0x17d1d0 Ok, this looks like a standard overrelease problem. You posted too little code to include the problematic point. Best to read up on Cocoas Memory Management Rules and make sure, that your Objective-C objects are not overreleased. Enabling Zombies can help if you can’t find it in source. (Note: retain counts are the same concept as AddRef and Release in Microsofts COM, which you may know.) Unless you have exceptionally many or large resources, I’d say you won’t need to worry about running out of memory in the loop on todays machines. Best Kai PS: In case you have more questions about old-style resource access, you’d better take them to Apples Carbon list. People there are probably more understanding about the need to use time proven but no longer fancy APIs. ;-) This GDB was configured as "i386-apple-darwin" (Error from the debugger) /users/...path_to_my_exe_file: No such file or directory. But I checked the exe file and it's absolutely there(in the bundle). I tried an autorelease pool inside the loop, disposing of datahandle.etc, but still got the same problem. Now, when I confirmed the *dataHandle, it returned NULL but I don't know why? --Bach On Wed, Jun 25, 2008 at 3:36 PM, Ken Thomases <[EMAIL PROTECTED]> wrote: On Jun 25, 2008, at 1:19 AM, Tran Kim Bach wrote: Hi folks,I'm a newbie to Cocoa. Recently, I'm working on a project relating to Resource Management. In my project, there's a part that I'm reading through the resources in a resource file. I'm using: int count = CountResources( typeName ); to get all resource that has the type "typeName", then loop through this resource list to take resource data out. for (n = 1; n <= count; n++) { Handle dataHandle = Get1IndResource( type1, n); NSData *data = [NSData dataWithBytes: *dataHandle length: GetResourceSizeOnDisk(dataHandle)]; // I GOT AN ERROR HERE What do you mean "GOT AN ERROR"? What error? How did it manifest? //using data struct A_STRUCT aStruct; memcpy(& aStruct,[data bytes], [data length]); } After several times looping through the list, I got an error in the line above. But if I use data directly, like the following code, there is no error occurred. memcpy(&pgControlRes,*dataHandle, GetResourceSizeOnDisk(dataHandle)); Any suggestions for my problem. I highly appreciate all your helps. You don't show if you're: 1) Checking if dataHandle is NULL 2) Checking if *dataHandle is NULL 3) If (1) or (2), checking ResError() 4) Disposing of dataHandle with ReleaseResource() Also, in the pseudo-code you provide, the NSData objects will accumulate in the autorelease pool until some point after your "for" loop. You can try using an autorelease pool inside the loop so that the NSData objects are released after each iteration. You may just be exhausting memory. For the case where you're not using NSData, the memory exhaustion might not happen since you're not storing the data twice in memory (once in the handle, once in the NSData), but would if there were twice as many resources. Cheers, Ken ___ 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: Newbie question: error in creating a NSData object using handle (Resource Management)
On 27.6.2008, at 05:00, Tran Kim Bach wrote: Wow, thanks Ken a lot. About the endian issues, I have a compatible swap function to convert data to Big-endian (and vice verse). Then, I will correct big-endian issues. I may know where the problem is. When I read to your suggestion, On Fri, Jun 27, 2008 at 6:11 AM, Ken Thomases <[EMAIL PROTECTED]> wrote: data = [NSData dataWithBytes:*dataHandle length:sizeLong ]; resID = [NSNumber numberWithShort:resIDShort]; if((type2 =='PREC')&&([resID intValue]== 302)) { struct PGControlRes pgControlRes; memcpy(&pgControlRes,[data bytes], [data length]); Have you tested that the resource size is the same as the structure size? I found out something. Actually, I'm just trying to make a prototype in one fixed size of the same resource type. I used to test on the same resource files with this fixed resource structure. but in reality, in my application, the resource size for this type(PREC) is various for each resource file(.rsrc). So, I think the struct caused my problem ( I never thought of it before). By the way, I have a lot of structs of the same resource type(PREC for example) written in C, Is there any way to still take advantage of them in Objective-C? Absolutely. Objective-C is a superset of C, so you can use all C you’d ever like to use. Code of you like NSNumber* resID = [NSNumber numberWithShort:resIDShort]; and later [resID intValue] is pretty unnecessary - unless you are going to use resID with some Cocoa message which expects an NSNumber. Another tip: Handle locking (HLockHi, HUnlock) is a no op under Mac OS X and can be skipped. Best Kai (I mean if I can use these C structs in Objective-C?, don't have to rewrite them using Objective-C language). Thank you for your supports. ---(Bachtk ___ 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: Calculating accurate bounds of stroked paths
Hi, have you checked CGContextReplacePathWithStrokedPath (CGContextRef c) ? This together with CGRect CGContextGetPathBoundingBox (CGContextRef c) might do the trick for you. Best, Kai On 8.7.2008, at 14:16, Graham Cox wrote: I need to know a rect within which all pixels will be painted for a given path and stroke width. I'd prefer not to make this rect any larger than it really needs to be. To compute this, I have to factor in all sorts of bits and pieces such as the angles of the line joins, miter limits and so on. It's getting so complicated I feel there has to be an easier way. Surely there's something in Quartz that can do this? A close second best would be a rect that was the worst case bounds for a given stroke width (it wouldn't need to know the actual path, just its basic bounds), which thus assumed that all angles were acute enough to trigger the mitre conversion. Even that is proving hard to figure, as I'm probably not really understand the miter limit calculation. The docs state: "The miter limit helps you avoid spikes at the junction of two line segments connected by a miter join (NSMiterLineJoinStyle). If the ratio of the miter length—the diagonal length of the miter join—to the line thickness exceeds the miter limit, the joint is converted to a bevel join. The default miter limit value is 10, which converts miters whose angle at the joint is less than 11 degrees." So what *is it*? A value in degrees? Or a ratio of two sides of a triangle? What triangle, exactly? How can I tell just how far out I need to outset the rect to make sure I'm always just outside the edge of any mitred corner? thanks for any insight into this, it's getting frustrating. I'm pretty OK at trig generally, but the definition is a bit vague, so I'm not sure what I should be using as my starting points (I possibly mean that literally!). cheers, Graham___ 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/kai%40granus.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: Any good advice for naming parameters of init methods?
On 11.7.2008, at 04:59, William Xu wrote: Jens Alfke <[EMAIL PROTECTED]> writes: With any naming convention, the possible problem is a conflict with a name in a superclass. Apple's Cocoa frameworks tend to use a "_" prefix for both ivars and private method names. How about using "_" as postfix then? Like `this_one_'. I find google c++ guide suggests that: http://google-styleguide.googlecode.com/svn/trunk/cppguide.xml#Variable_Names Looks good to me. The only disadvantage of this approach is that KVC’s direct access to your ivars_ will no longer work. KVC knows about the _ivar convention (because it is used by Apple ;-) ) and matches an _ivar to the key "ivar". It won’t for ivar_. But than again it is better anyway to have explicit accessors, I’d say. Kai PS and OT: _ivar is not (any more) considered portable C++ either because all names beginning with _ are reserved for compiler/library use by the standard. -- William http://williamxu.net9.org ... I think I'd better go back to my DESK and toy with a few common MISAPPREHENSIONS ... ___ 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/kai%40granus.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: Cleaning up my Data Model
Yes, there is: IB 3.1 (coming with Xcode 3.1) lists all "Referencing Bindings" pointing to an object under the "Connections" tab. Hope this helps. Kai On 25.7.2008, at 18:06, Richard Gutierrez wrote: Thanks for the response... Ultimately what I am trying to do is determine which objects are bound to which array controllers. I understand that if I delete an array controller, all of the bindings associated with that array controller will be removed, but I need to know which items are associated with that array controller so I can re-bind them to the new array controllers that I am creating. Basically, I am re-structuring my data model to get myself better organized. I need to transfer the bindings for my objects from my old array controllers to my new array controllers without leaving any objects that were bound to my old array controllers "unbound" when I delete the old array controllers. My problem is that I cannot see which items are bound to my old array controllers without going through them one by one, which can take forever with the amount of objects I have. Is there an easier way to see all bound objects to an array controller? ___ 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/kai%40granus.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: Design Question: Pro & Cons of KVC/KVO
Oleg, by all means, go ahead with what you started and spend more time learning about KVC/KVO. Yes, this is used in many many projects and I personally would really miss it if it wouldn’t be there. Actually, as you described yourself, if it wouldn’t be there, you’d had to brew something similar yourself. Which I did, coincidental, like 15 years ago under Mac OS 7 or so. Only that Apple can spend a lot more resources than you (I guess) or me (I’m sure) in making this "right". And they did. Yes, it has a learning curve. And yes, it is sometimes unfortunate that the inner workings are a black box and can not be looked at with the debugger. Nevertheless, these are minor disadvantages in comparison to the whole thing. Amin already mentioned all the advantages of KVC/KVO as provided by Apple, including the integration with other Cocoa technologies, which a home-brewn solution could never provide. Concerning Core Data: it is equally great - inside its specs. Just take the build-in multi-level undo and redo support. Another great reason to use KVC/KVO, by the way: when Core Data undoes something, KVO is the way to get notified about these changes. Done consistently, this works simply beautiful. And I wouldn’t restrict Core Data to database+forms apps. You can certainly use it for a drawing application. Whether it is the best solution for this kind of application depends - as always - on many details. Hope this helps a little Kai On 21.8.2008, at 16:41, Oleg Krupnov wrote: Thanks Amin for responding. You are correct that there's no need to reinvent the wheel, and that's exactly what I'd like to avoid, that's why I am now re-reading about KVC/KVO and reconsidering it. So, does everybody really always use KVC/KVO for implementing MVC, in all projects? Is this the recommended best practice? BTW does anyone use Core Data? I've watched the video tutorial and it looks like too much magic. I would never guess how to make Core Data work for a drawing application like the Sketch. Is Core Data rather for database+forms apps? 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/kai%40granus.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: Strange Strange Bug
Steve, looks like the debugger tries to inspect your uninitialized string pointers. And it happens that the stack location assigned to the 6th string pointer still contains the address of a now deallocated object left there when another method exited. So this is a debugger-only problem and completely harmless without debugger (if I am not mistaken, of course). To fix it, assign nil to the string pointers when you declare them: NSString *gAsOf = nil; etc.. Or, better yet, do not declare the variables before using them (that is, not all together at the start of the method). (Note that this style may be only possible with certain C dialects. I use Objective C+ +, therefore I’m not sure). Hope this helps. Kai On 5.9.2008, at 09:04, Steve Cronin wrote: Folks; OK this behavior has me a little spooked... This behavior occurs the first time through the method! I have a breakpoint set at the first line of a method, which happens to be a NSLog(@"Ready"); As is normal I have my local variable declarations at the beginning of the method: NSArray *myKeys, *workingValues; NSString *gAsOf, *gAsOfDate, *gDataMask, *gDataMaskName, *gID, *gIDName, *gVersion, *gVersionName; gAsOfDateName = [[NSUserDefaults standardUserDefaults] stringForKey:@"groupAsOfDatePropertyName"]; gDataMaskName = [[NSUserDefaults standardUserDefaults] stringForKey:@"groupDataMaskPropertyName"]; Nothing surprising or complicated... However, the console window will show at least two of these messages:. 2008-09-05 00:56:45.101 XYZ[345:813] *** -[CFString _cfTypeID]: message sent to deallocated instance 0x16d1db80 2008-09-05 00:56:45.563 XYZ[345:813] *** -[CFString _cfTypeID]: message sent to deallocated instance 0x16d1db80 2008-09-05 00:56:46.776 XYZ[345:813] *** -[CFString _cfTypeID]: message sent to deallocated instance 0x16d1db80 If I scroll the variables display at the upper right in the debugger window, the console will add more of these messages. One of the strings in the variable display will have its 'Value' shown as the instance id shown in these messages. For this string variable the 'Summary' will be empty as opposed to all other 'Summary' which have 'Invalid' The debugger is paused several lines above the declaration of this variable... If I merely switch the positions of the variables I can change which variable has the 'bad' instance id. It is always the 6th declared string variable. I can mix up the order of variables, change the actual variable names, or interleave NSArray declarations, it doesn't matter...the 6th string exhibits this behavior. Hovering over the variable it displays the 'yellow help ribbon' with 'NSZombie_CFString', whereas all the others are 'NSString' Commenting out the declarations and use and compiling works fine. Uncommenting brings back the exact behavior. Note: If I take out the breakpoint then the console does NOT show these messages even though I have left log messages in the method so I know the method is being executed I have restarted XCode as well as the system (Intel 10.5.4, XC3.1) no change What in the heck is going on? Should I be worried? How can I shed this anomaly? Thanks, Steve ___ 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/kai%40granus.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: Strange Strange Bug
On 6.9.2008, at 02:10, Steve Cronin wrote: Kai; OK That seems reasonable but: why do I not see this behavior anywhere else? Yes, it surprised me a little, too, that I had never seen something like this. Now if I am right, this occurs only if such a variable happens to be at a location where another object pointer has previously been, which has been deallocated in the meantime. And if zombies are enabled, if I interpret your findings correctly. That may explain it. why have I never seen it before now? Zombies not enabled? Pure luck? why if I restart XCode does the 'bad' instance fall on exactly the same string? Because your program behaves reproducible and always does the same things on the stack before calling the method in question. Again, I am not 100% sure about this. Kai Thanks, Steve On Sep 5, 2008, at 4:11 AM, Kai wrote: Steve, looks like the debugger tries to inspect your uninitialized string pointers. And it happens that the stack location assigned to the 6th string pointer still contains the address of a now deallocated object left there when another method exited. So this is a debugger-only problem and completely harmless without debugger (if I am not mistaken, of course). To fix it, assign nil to the string pointers when you declare them: NSString *gAsOf = nil; etc.. Or, better yet, do not declare the variables before using them (that is, not all together at the start of the method). (Note that this style may be only possible with certain C dialects. I use Objective C++, therefore I’m not sure). Hope this helps. Kai On 5.9.2008, at 09:04, Steve Cronin wrote: Folks; OK this behavior has me a little spooked... This behavior occurs the first time through the method! I have a breakpoint set at the first line of a method, which happens to be a NSLog(@"Ready"); As is normal I have my local variable declarations at the beginning of the method: NSArray *myKeys, *workingValues; NSString *gAsOf, *gAsOfDate, *gDataMask, *gDataMaskName, *gID, *gIDName, *gVersion, *gVersionName; gAsOfDateName = [[NSUserDefaults standardUserDefaults] stringForKey:@"groupAsOfDatePropertyName"]; gDataMaskName = [[NSUserDefaults standardUserDefaults] stringForKey:@"groupDataMaskPropertyName"]; Nothing surprising or complicated... However, the console window will show at least two of these messages:. 2008-09-05 00:56:45.101 XYZ[345:813] *** -[CFString _cfTypeID]: message sent to deallocated instance 0x16d1db80 2008-09-05 00:56:45.563 XYZ[345:813] *** -[CFString _cfTypeID]: message sent to deallocated instance 0x16d1db80 2008-09-05 00:56:46.776 XYZ[345:813] *** -[CFString _cfTypeID]: message sent to deallocated instance 0x16d1db80 If I scroll the variables display at the upper right in the debugger window, the console will add more of these messages. One of the strings in the variable display will have its 'Value' shown as the instance id shown in these messages. For this string variable the 'Summary' will be empty as opposed to all other 'Summary' which have 'Invalid' The debugger is paused several lines above the declaration of this variable... If I merely switch the positions of the variables I can change which variable has the 'bad' instance id. It is always the 6th declared string variable. I can mix up the order of variables, change the actual variable names, or interleave NSArray declarations, it doesn't matter...the 6th string exhibits this behavior. Hovering over the variable it displays the 'yellow help ribbon' with 'NSZombie_CFString', whereas all the others are 'NSString' Commenting out the declarations and use and compiling works fine. Uncommenting brings back the exact behavior. Note: If I take out the breakpoint then the console does NOT show these messages even though I have left log messages in the method so I know the method is being executed I have restarted XCode as well as the system (Intel 10.5.4, XC3.1) no change What in the heck is going on? Should I be worried? How can I shed this anomaly? Thanks, Steve ___ 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/kai%40granus.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]
NSXMLParser and character entities?
When NSXMLParser hits a character entity like ä (-> German umlaut 'ä'), it sends parser:resolveExternalEntityName:systemID: to its delegate and if this is not implemented or returns nil, parser:parseErrorOccurred: is called with NSXMLParserUndeclaredEntityError. Am I supposed to resolve all these character entities myself? And if so, what should the NSData object returned by parser:resolveExternalEntityName:systemID: contain? Unicode? Which Unicode encoding? But this can’t be, can it? I must be missing something simple. Thanks for any hints Kai ___ 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: NSXMLParser and character entities?
On 14.9.2008, at 10:45, Nathan Kinsinger wrote: On Sep 12, 2008, at 3:56 PM, Kai wrote: When NSXMLParser hits a character entity like ä (-> German umlaut 'ä'), it sends parser:resolveExternalEntityName:systemID: to its delegate and if this is not implemented or returns nil, parser:parseErrorOccurred: is called with NSXMLParserUndeclaredEntityError. Am I supposed to resolve all these character entities myself? And if so, what should the NSData object returned by parser:resolveExternalEntityName:systemID: contain? Unicode? Which Unicode encoding? But this can’t be, can it? I must be missing something simple. Thanks for any hints Kai The main problem is that entities like ä are defined by HTML and have nothing to do with XML or NSXMLParser. Understood. I haven't dealt with this problem myself but I was curious so I tried a few things. My first attempt was using NSAttributedString to convert the HTML entity to a UTF8 string. - (NSData *)parser:(NSXMLParser *)parser resolveExternalEntityName: (NSString *)entityName systemID:(NSString *)systemID { NSAttributedString *entityString = [[[NSAttributedString alloc] initWithHTML:[[NSString stringWithFormat:@"&%@;", entityName] dataUsingEncoding:NSUTF8StringEncoding] documentAttributes:NULL] autorelease]; NSLog(@"resolved entity name: %@", [entityString string]); return [[entityString string] dataUsingEncoding:NSUTF8StringEncoding]; } This works, parser:foundCharacters: gets the ä but for some reason parser:parseErrorOccurred: is still being called with the same error you received: "Operation could not be completed. (NSXMLParserErrorDomain error 26.)" The parser does continue and parse the file correctly (with the ä), it just makes it hard to tell when you have real errors. I'm really curious as to why this doesn't work (running 10.5.4 on Intel). And the fact that the parser keeps parsing after the error, when the documentation says it will stop, is odd too. That’s indeed odd behavior. Guess I’ll better file a bug. Another option is to add an XHTML DocType DTD to the file and set setShouldResolveExternalEntities: to YES (default is NO). This works with no errors because the DTD defines the entities. However NSXMLParser will download the DTD (over the net) every time you parse a file. So you probably want to copy one of the DTD's (say http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd ) locally. Although I didn't try it, you could copy the entity definitions into your own DTD to make the file smaller and parsing it faster. That should work well, thanks for the hint. Of course if the content really is XHTML you should really be using an HTML parser and not an XML one. No, it isn’t. Just needs some way to encode all German characters. I’ll have to investigate whether simply using utf8 encoding is an option, though. --Nathan Thanks a lot for your very helpful answer Kai___ 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: NSXMLParser and character entities?
On 15.9.2008, at 22:24, Nathan Kinsinger wrote: On Sep 15, 2008, at 1:45 PM, Kai wrote: Of course if the content really is XHTML you should really be using an HTML parser and not an XML one. No, it isn’t. Just needs some way to encode all German characters. I’ll have to investigate whether simply using utf8 encoding is an option, though. --Nathan Thanks a lot for your very helpful answer Kai Someone who knows more about unicode can correct me if I'm wrong, but I don't think ä is an utf8 (or any other string) encoding. The point I was trying to make is that ä and such are specifically defined by HTML. XML supports utf8 so you can just use german text without the HTML entities. Or rather it can, if you use encoding="UTF-8"?> as your XML declaration (this is typically the default). NSXMLParser will parse it correctly. This was exactly what I meant. Sorry for the unclear wording. Kai --Nathan ___ 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]
Core Animation Caching Resolution
Hi, I am having a CALayer with a scale-down transform and many sub layers. It seems to be the case that these sub layers cache their contents with 1 unit to 1 pixel, that is they ignore the (outer) transform until it comes to draw to the screen. Is there a suggested way to work around this? What I want is to have the cache at screen resolution to keep memory usage controlled. Thanks for any hints Kai ___ 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: Which language to get started with cocoa development?
Achim: I can’t answer your questions concerning the scripting languages, but given your background I’d suggest to go ahead with ObjC. It won’t really be a new language for you since it is but an extension of C. Granted, the bracket notation for message sending needs a little getting used to, but that’s about it, syntax wise. The by far larger part of the learning curve is getting used to the Cocoa design patterns, which you’ll have to do anyway. And since ObjC is the "native language" of Cocoa, approching it from this side probably has some obstacles less, which may be introduced by bridiging to other languages. Have fun! Kai On 31.12.2008, at 09:22, Achim Domma wrote: Hi, I develop software for a living and want to get started with cocoa development just for fun. I'm good at python, C, C++ and C# and have some Ruby knowledge. Now I'm asking myself, which language I should use to get started with cocoa development: - ObjC looks interesing, but would be a new language to learn. I like to learn new languages, but I also prefer to do one step after another. So learning Cocoa and Obj-C toghether could be frustrating. - I like dynamic scripting languages like python and ruby, but I would like to ship my apps to other users. And they should not care about the language I have used. Can pyObjC or RubyCoca be bundled with my app, so that the enduser will not recognize that python/ruby is shipped with my app? - As far as I understand, GUIs are usually build with the interface builder of XCode. That tools is tuned to be used with ObjC. How good is the integration with scripting languages? - How up to date are bindings to "non ObjC" languages usually? If I will like cocoa development, I want to have a look at core data and core animations. Are these also available for ruby and python? - What about Mono/Cocoa#? Looks like Mono is not an good option, if I want to distribute my app as small download via the web. Or am I wrong? I would be very happy to hear some opinions of experienced cocoa developers about these topics. Any feedback would be very appreciated. cheers, Achim ___ 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/kai%40granus.net This email sent to k...@granus.net ___ 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 arch...@mail-archive.com
Re: Problems when putting a window between desktop and desktop icons
On 28.10.2008, at 08:27, Markus Amalthea Magnuson wrote: On Mon, Oct 27, 2008 at 21:45, Karl Goiser <[EMAIL PROTECTED]> wrote: Dear Markus and others, This is a problem that I have had with an application of mine, iCalViewer, which displays a window on the desktop. What happens is that you can find a window level which draws the window under the desktop icons and over the desktop itself. However, at that level, that window captures the mouse events as if it was _over_ the desktop icons. My only solution was to disable mouse interaction with my window. I raised this as a bug with Apple, bug number 3521992 on 5 January, 2004 - coming up to 5 years ago! Regards, Karl Thanks for your reply, good to hear it's not just me, on the other hand not so good because it obviously can't be done :) Hm, you could try to detect mouse events for the icons yourself and if such an event is detected repost it to the Finder using some low level event posting in Core Graphics. I’m not sure though whether you can post events for a specific app or even for a specific window. Or (maybe easier) turn it around: set your window to ignore mouse events and use a low level event tap to catch those mouse events you are interested in. Best luck! Kai Time to come up with an entirely different solution then. -- Markus Amalthea Magnuson http://konstochvanligasaker.se http://nattlek.se "Life... is like a grapefruit. It's orange and squishy, and has a few pips in it, and some folks have half a one for breakfast." – Douglas Adams ___ 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/kai%40granus.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: Question about NSThread?
It depends... You may well just be lucky that it seems to work (or unlucky, this again depends...). If your worker thread is only reading any data shared with other threads, it will indeed never disturb these other threads (probably just the main thread in your case). But if the main thread modifies this data, your worker thread may get inconsistent values. Like reading the width, then the main thread modifies the size (both width and height), then the worker thread reads the height. The simplest approach would be to give the worker thread the complete info it needs at once when it is started, thus avoiding any shared data. NSOperation and NSOperationQueue might be of help here. You would create a sub class of NSOperation which knows all the info your worker thread needs and off you go. Best luck Kai On 19.11.2008, at 22:37, Jean-Nicolas Jolivet wrote: Mmm I see Well, right now I would say my worker thread is pretty much just reading values (size of image to generate etc)... but it's not "modifying" anything... it doesn't change any variables etc... just reads the info it needs to generate the images and ...well, generates the images... If my worker thread doesn't have to "write" in any variables/objects whatever, shared with the UI, can I assume that it's safe to leave it like it is? On 19-Nov-08, at 4:32 PM, Stefan Sinclair wrote: In a word, yes :) If you are accessing a piece of memory across threads, you should be making sure you are synchronizing any access to that memory which could occur across threads. For simple primitives (such as possibly your work progress number) just using an atomic integer would suffice. For more complicated access, you will want better protection (such as using locks around any APIs which can access your data). You're probably getting away with it now b/c your UI thread (the main thread) is only reading data (the work progress value - I'm guessing a single integer or floating point value which can be read/written in a single instruction) while the worker thread is modifying it. But it doesn't hurt to use proper thread- safe access patterns for data shared between threads even for small things like this. -Stefan > From: [EMAIL PROTECTED] > To: cocoa-dev@lists.apple.com > Date: Wed, 19 Nov 2008 15:57:44 -0500 > Subject: Question about NSThread? > > I have an app that generates a bunch of images... the process can be > long so I wanted to start it in a separate thread so that the UI can > be responsive etc... > > basically the only thing I did was: > > [NSThread detachNewThreadSelector:@selector(doLongProcess) > toTarget:self withObject:nil]; > > and I added > > NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; > > at the beginning of my doLongProcess method, and [pool release] at the > end... > Now the weird part is that... it appears to be working... the images > are created...the UI stays responsive..my status textfield gets > updated (it wasn't getting updated when the long process was not in a > separate thread)... > > Am I wrong to think that it should've been much more complex than > that? (With NSLocks and whatnot...) Maybe I should just shut up and be > happy that it work, but somehow this doesn't seem right... > > Jean-Nicolas Jolivet > [EMAIL PROTECTED] > http://www.silverscripting.com > > ___ > > 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/stefan_sinclair%40hotmail.com > > This email sent to [EMAIL PROTECTED] Proud to be a PC? Show the world. Download the “I’m a PC” Messenger themepack now. Download now. Jean-Nicolas Jolivet [EMAIL PROTECTED] http://www.silverscripting.com ___ 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/kai%40granus.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: Magnify anything on the screen?
Hi, if you’re on Leopard only, you can use the new screen capturing APIs to capture the screen area you need (look for the SonOfGrab sample code). I’d say magnifying the captured pixels is left to you. Some carefully chosen scale factor during drawing together with disabled anti-aliasing might work. Kai On 23.11.2008, at 17:03, Tim Andersson wrote: Hi guys. I'm currently working on my own custom color picker, and it's all going well. However, I need to replicate the magnifying function found in a NSColorPanel. I think I've figured out how to capture mouse-events anywhere on the screen, but I don't know how I would go about to "magnify" what's beneath the cursor. Any help is greatly appreciated. Kind regards, Tim ___ 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/kai%40granus.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: Adding an associated reference is memory expensive (was: Adding an observer is memory expensive)
On 12.9.2009, at 00:35, Greg Parker wrote: We have your earlier report rdar://7212101. Thanks, Torsten. (Ken didn't see it because the bug didn't pass through his group's hands on its way to my group.) This is a bug in the associated reference machinery. That code keeps a C++ std::hash_map per augmented object, mapping associated keys to associated values. std::hash_map uses an std::vector internally, and the default hash_map constructor pre-allocates 100 entries for that vector. Which are then raised to 193 by __stl_next_prime() in hashtable.h. Times the 64 bit pointer size makes 1544 bytes, which GC seems to round up to the 2k seen by the OP. This is overkill for associated objects usage. The fix is to use a non-default constructor that specifies a much smaller initial hash_map size. Unfortunately constructing the std::hash_map with a small capacity will lower the number of preallocated bucket slots only to 53 (-> 424 bytes under 64 bits), because this is the smallest number returned by __stl_next_prime(). (I deduced this from the stl source in the 10.6 sdk, so I may be mistaken.) Still a lot for the probably predominate case of a single association. Especially if the OP is right with his observation that this memory is scanned by the collector, which adds time overhead to the space overhead. Kai On Sep 11, 2009, at 2:25 PM, Ken Ferry wrote: Hi Torsten, Please file as a bug if you haven't already. That clearly needs to be looked into. For your KVO issue, you can probably work around it by implementing - (void)setObservationInfo:(id)observationInfo; - (id)observationInfo; on the object that you are observing. This provides the storage, and KVO won't have to use associated references. Note that the observation info is typed id despite being typed void * in the headers. KVO needs strong storage here to implement the feature described in "Automatic Removal of Finalized Key-Value Observers" in the release notes. KVO assumes you are providing strong storage if the method is typed id, which can be introspected out of the runtime. If you aren't, it'll have to use an associated reference to keep things alive. -Ken Cocoa Frameworks On Fri, Sep 11, 2009 at 3:13 AM, Torsten Radtke >wrote: Is this when the first observer is added to each of the 100k objects? Yes, it happens for the first observer I add. But I expressed the problem not good enough. Adding an observer is realized by adding an associated reference (with objc_addAssociatedObject (), new in Snow Leopard) to the observed object. So the main problem is that adding a single associative reference to an object results in an allocation of 2048 byte block. If I do this to my 100.000 objects, about 200MB are allocated (in comparison to about 3MB for the objects). These blocks seem to be scanned memory, as I also noticed significant delays as the garbage collector scanned and collected. This amount of memory seems to be allocated on purpose (see the ::reserve method on top of the stack trace shown below) but seems way too high for the general case of adding a single associative reference! 0 libauto.dylib std::vector<__gnu_cxx::_Hashtable_node const, void*> >*, Auto::AuxAllocator<__gnu_cxx::_Hashtable_nodeconst, void*> *> >::reserve(unsigned long) 1 libauto.dylib Auto::Zone::set_associative_ref(void*, void*, void*) 2 AssociativeReferences -[Object setName:] 3 AssociativeReferences main 4 AssociativeReferences start The Object class is implemented as follows: static char name_key; @implementation Object - (NSString*)name { return objc_getAssociatedObject(self, &name_key); } - (void)setName:(NSString*)aName { objc_setAssociatedObject(self, &name_key, aName, OBJC_ASSOCIATION_COPY); } @end Torsten ___ 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/kenferry %40gmail.com This email sent to kenfe...@gmail.com ___ 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/gparker%40apple.com This email sent to gpar...@apple.com ___ 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
Re: Undo architecture advice needed
Hello Dave, undo/redo is a model operation and should be handled inside the model. That is, I wouldn’t pick your suggestions 1) or 2), because they both do not observe (in a general case, not KVO) the model to generate undo information. If I understand you correctly, the phase objects are your model. If this is correct, the changes do go through your code: when they arrive at the phase object (typically in a setter). And this is the place to record the information needed for undoing the change. Hope this makes any sense Kai On 9.10.2009, at 19:53, David Hirsch wrote: Hello list- I have a document-based application. Each document has a NSArray of phases. Phases is an NSArrayController created in IB and bound to FIle's Owner.phases. When a given phase is selected in the NSTableView (bound to phase controller), then its properties show up in a set of text fields, check boxes, color wells, popup menus, etc., through bindings similar to "Phases.selection.size". Here is my question: what is the best way to implement undo/redo here? I'd like to enable undo of changes to the settings (like size) that the user makes in the text fields, but they don't go through my code - they are just bound directly to the array. (Note that I do understand that the field editor has its own undo that operates during text editing; that is not what I'm talking about.) Here are some potential avenues I'm considering: 1) Make the document the delegate for all these fields. Then I can get a controlTextDidChange: notification, figure out the current phase, get the object and the value, and post an undo. However, this requires me to implement a whole bunch of setters in my NSDocument subclass that duplicate setters in my phases class, which seems inelegant, to say the least. Also, I don't see an obvious way to do something similar for, say checkboxes. 2) Try to set up KVO (from my document subclass, I guess?) on the NSArrayController to watch for changes, and then register undo operations in the observing method. I would have to be careful not to get into a loop when re-doing the undo operations, though, since I would observe any changes I made during undo. 3) I'm sure there are other ways, but I'm not smart enough to think of them. Thanks in advance, Dave ___ 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/lists%40kai-bruening.de This email sent to li...@kai-bruening.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 arch...@mail-archive.com
Re: Snow Leopard: unsupported PointerFunctions configuration was requested
On 10.10.2009, at 13:56, Chris Idou wrote: Below is the RegexKit code that causes the Snow Leopard error. After reading the doco, I don't feel very enlightened about what the unsupported configuration is, or what the solution might be. Can anyone give me a clue? Sure: replace NSPointerFunctionsIntegerPersonality by NSPointerFunctionsIntegerPersonality | NSPointerFunctionsOpaqueMemory. Best Kai + (void)load { RKAtomicMemoryBarrier(); // Extra cautious if(RKCacheLoadInitialized== 1) { return; } if(RKAtomicCompareAndSwapInt(0, 1, &RKCacheLoadInitialized)) { if((cacheMapKeyCallBacks= dlsym(RTLD_DEFAULT, "NSIntegerMapKeyCallBacks")) == NULL) { cacheMapKeyCallBacks= dlsym (RTLD_DEFAULT, "NSIntMapKeyCallBacks"); } #ifdef ENABLE_MACOSX_GARBAGE_COLLECTION id garbageCollector = objc_getClass("NSGarbageCollector"); if(garbageCollector != NULL) { if([garbageCollector defaultCollector] != NULL) { id pointerFunctions = objc_getClass("NSPointerFunctions"); RKCacheIntegerKeyPointerFunctions = [pointerFunctions pointerFunctionsWithOptions:NSPointerFunctionsIntegerPersonality]; RKCacheIntegerKeyPointerFunctions.acquireFunction = intPointerFunctionsAcquire; RKCacheIntegerKeyPointerFunctions.descriptionFunction = intPointerFunctionsDescription; RKCacheIntegerKeyPointerFunctions.hashFunction= intPointerFunctionsHash; RKCacheIntegerKeyPointerFunctions.isEqualFunction = intPointerFunctionsIsEqual; RKCacheIntegerKeyPointerFunctions.relinquishFunction = intPointerFunctionsRelinquish; RKCacheIntegerKeyPointerFunctions.sizeFunction= intPointerFunctionsSize; RKCacheObjectValuePointerFunctions = [pointerFunctions pointerFunctionsWithOptions:(NSPointerFunctionsZeroingWeakMemory| NSPointerFunctionsObjectPersonality)]; [[garbageCollector defaultCollector] disableCollectorForPointer:RKCacheIntegerKeyPointerFunctions]; [[garbageCollector defaultCollector] disableCollectorForPointer:RKCacheObjectValuePointerFunctions]; } } #endif // ENABLE_MACOSX_GARBAGE_COLLECTION } } From: Bill Bumgarner To: Chris Idou Cc: cocoa-dev@lists.apple.com Sent: Thu, 24 September, 2009 12:36:04 PM Subject: Re: Snow Leopard: unsupported PointerFunctions configuration was requested On Sep 23, 2009, at 7:09 PM, Chris Idou wrote: Very early in application startup, even before main() is called, I get the following error: 2009-09-24 12:07:11.462 MyApp[5534:a0f] *** An unsupported PointerFunctions configuration was requested, probably for use by NSMapTable, NSHashTable, or NSPointerArray. The requested configuration fails due to integer personality not using opaque memory It happens twice on startup, and below are the stack traces when it happens: What does it all mean? #00x7fff84b342f7 in NSLog #10x7fff84ac84d1 in +[NSConcretePointerFunctions initializeSlice:withOptions:] #20x7fff84aea796 in -[NSConcretePointerFunctions initWithOptions:] #30x7fff84aea74d in +[NSPointerFunctions pointerFunctionsWithOptions:] #40x10004b633 in +[RKCache load] One change to the NSPointerFunction based collection classes (which support a number of things that NSArray & the like do not) between Leopard and Snow Leopard was to tighten up the validation of the pointer function validation such that a handful of non-sensical configurations are detected that weren't before. I.e. RKCache is trying to create a set of pointer functions that doesn't make sense (and for whose behavior is undefined). As someone else pointed out, RK is most likely RegexKit and, thus, the source is available and can be fixed. Given the relatively common use of RK*, please provide a patch to the author so it can be fixed upstream. b.bum __ Get more done like never before with Yahoo!7 Mail. Learn more: http://au.overview.mail.yahoo.com/ ___ 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/lists%40kai-bruening.de This email sent to li...@kai-bruening.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 arch...@mail-archive.com
Re: Appropriate dealloc and finalize actions
Hi Karolis, I’d say your pattern is absolutely correct. I assume those two objects do not retain each other, they just need to know about the other one. And they should be allowed to die separately, while cleaning up the otherwise dangling pointer in the other object. The good news is that GC has support for this: weak references. Simply declare the connection ivar as weak: __weak MyClass* connection. GC does the rest. No dealloc, no finalizer, no dangling pointer. And it’s even thread safe. Best Kai On 12.10.2009, at 04:44, Karolis Ramanauskas wrote: If you want to do something that doesn't break encapsulation, then you should simply release the one ivar connection. That will let the receiving object perform its own actions, by itself, on its own behalf, as appropriate to its own affairs. Thanks, however, I do not see how to accomplish my purpose. I'm confused. Help ;) I have object1 that has a connection to object2, (object1.connection = object2). And at the same time object2.connection = object1: O1 -> O2 O2 -> O1 If one of these objects gets deallocated how should I make sure the other object is not pointing to the now deallocated object without doing what I did: - (void)dealloc { if (self.connection) { self.connection.connection = nil; } [super dealloc]; } Thanks On Sun, Oct 11, 2009 at 6:11 PM, Greg Guerin wrote: Karolis Ramanauskas wrote: - (void)dealloc { if (self.connection) { self.connection.connection = nil; } [super dealloc]; } Why would you do this? You're making one object responsible for the internals of another object. This is a bad idea. It breaks the individual encapsulation of each object. One of the cardinal points of good object-oriented design is that an object's responsibilities are circumscribed. It should manage itself and the things it directly references, nothing else. For any objects it DOES reference, each of those objects also has its own responsibilities, and so on recursively. Objects shouldn't poke their noses into another object's business. If you want to do something that doesn't break encapsulation, then you should simply release the one ivar connection. That will let the receiving object perform its own actions, by itself, on its own behalf, as appropriate to its own affairs. -- GG ___ 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/lists%40kai-bruening.de This email sent to li...@kai-bruening.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 arch...@mail-archive.com
Re: Appropriate dealloc and finalize actions
On 12.10.2009, at 13:42, Roland King wrote: On 12-Oct-2009, at 7:26 PM, Karolis Ramanauskas wrote: Thanks, Kai, Greg, Jens, It's generally a bad idea to have two objects each retain the other. It produces a reference loop, which means neither object can be deallocated without manually releasing each side of the relationship. As was stated in my original email these are all weak references: @property (readwrite, assign) MyClass * connection; I am not retaining the other object. In fact I couldn't really do it because I'm pointing to the object of the SAME class. yes you could - nothing stops you in retain/release mode from retaining an object of the same class, or even yourself, multiple times. MyClass 1 > MyClass 2 MyClass 2 > MyClass 1 If I made a property to retain the value it would automatically mean that I get a retain cycle. indeed you would one you would have to break. So whenever either an input or output is deleted I have to nil the connection of the object pointing to the soon to be deallocated object: self.connection.connection = nil; Yes that looks like it would work, you explicitly remove the pointer to yourself as you go away. That's fine. Of course it means you aren't managing the lifetimes of the objects between each other, their lifetimes are totally dependent on external factors, but if that's what you want, that's good. Thanks, Kai, for pointing this out: The good news is that GC has support for this: weak references. Simply declare the connection ivar as weak: __weak MyClass* connection. GC does the rest. No dealloc, no finalizer, no dangling pointer. And it’s even thread safe. No. Under GC you don't have this problem at all. You don't need weak references or anything else funky, it just works. MyClass1 pointing to MyClass2 and back with ordinary object references/assign properties does create a cycle yes, however GC can manage that perfectly well. Once there are no references to either MyClass1 or MyClass2 from the *ROOT* objects, even though they point to each other, they are subject to collection. GC is able to deal with these reference loops quite happily. Of course you’re right, you do not need weak references under GC to break reference count cycles - these are a non-issue under GC. I made the implicit assumption (bad bad!) that these objects should not keep each other alive. This is what __weak is good for: it marks a reference which does not keep the target alive and is auto-niled when the target dies. Depends on what you need. And there’s no need to conditionalize __weak in any way. It’s simply ignored under non-GC. Best Kai ___ 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/lists%40kai-bruening.de This email sent to li...@kai-bruening.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 arch...@mail-archive.com
Re: GC and atomic getters/setters
On 17.10.2009, at 17:38, BJ Homer wrote: In the Garbage Collection Programming Guide: Architecture [1], an example is given of a set of non-GC getters and setters which use @synchronized (self) to control the access to the ivar, and in the setter to protect the releasing of the old object and retaining of the new. Then, a GC example is given in which the getters and setters have no synchronization; the getter simply returns the value, and the setter simply assigns the new value. I understand why the setter is so much simpler under GC; no retain/ release fiddling is necessary. However, I'm confused about the lack of synchronization in the GC examples. I know there's lots of skepticism as to whether synchronization at the getter/setter level is even useful (hence the general recommendation to make properties nonatomic). But assuming that you wanted it there in the first place, why does the GC version not need the synchronization? Is it simply because the setter is doing less, and thus the getter wouldn't ever catch the setter halfway through its setting? (After releaseing the old value, but before retaining the new, for example.) Basically yes. Another way to look at it is that assignment to a GC-controlled pointer variable must be thread safe anyway (because GC is running in a separate thread and because there are things like weak references), so there is no need to put extra synchronization around it. By the way, this thread safety feature of GC is another big reason to use GC over managed memory besides the automatic memory management. Kai ___ 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 arch...@mail-archive.com
Re: how to make cocoa application run as a command line tool?
The clean solution for this is to refactor your application into a framework, a Cocoa application and a command line tool. The framework contains all the document logic (the model part of the MVC pattern). Both the Cocoa application and the command line tool use the framework. The tricky part is probably to find the right border between framework and application/tool. I haven’t done it myself yet, therefore I am for instance not sure whether NSDocument sub classes can/should be part of such a framework. Others may know whether it is possible/feasible at all to run a Cocoa application faceless. Good luck Kai On 20.10.2009, at 11:58, XiaoGang Li wrote: Greetings, I have created an document-based cocoa application, now I need to provide a command line interface for my users. for example, users input this into the terminal: ./myApplication.app/Contents/MacOS/myApplication -c --srcFolder "A/B/ C" --dstFolder "A/B/D"; I can get the argument information through [[NSProcessInfo processInfo] arguments] in the init method of the application delegate, and parse the arguments, then step by step. My question is that, I don't want the window and other document be displayed on the screen, even the menu. I want all the action be processed without user's interventio. Maybe, this feature seems odd. anyway, however, user can open my application in the Finder, and open a document to edit it. but they also can run it like a shell command utility to do some other faceless work, like convert the type the document to another type. I don't know whether I have a detailed description for my issue, but I will be very appreciated for your feedback. ___ 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/lists%40kai-bruening.de This email sent to li...@kai-bruening.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 arch...@mail-archive.com
Re: xml object memory issue
On 30.10.2009, at 08:36, Roland King wrote: Autoreleased objects are only autoreleased when the pool is drained. It is more than likely that the XMLDocument initWithContentsOfURL makes a lot of temporary objects which end up on the autorelease pool but they won't actually be released until the end of your loop. Put another pool alloc at the start of your loop before the NSURL alloc and then drain it after you release the xmlDocument - that will ensure all temporaries created during the parse are destroyed. Or switch to garbage collection. By far the better alternative unless you must support Tiger or iPhone. Kai XiaoGang Li wrote: The piece of code I want to discuss is followed: #import int main (int argc, const char * argv[]) { NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init]; for(int i=0;i<5000;i++) { NSURL *inAbsoluteURL = [[[NSURL alloc] initFileURLWithPath:@"the path to one xml file"] autorelease]; NSError *error = NULL; NSXMLDocument *xmlDocument = [[NSXMLDocument alloc] initWithContentsOfURL:(NSURL*)inAbsoluteURL options:0 error:&error]; //hande my Xpath, and do check work. will not cosume the memory. [xmlDocument release]; } [pool drain]; return 0; } I used the Instruments to detect the objects created but still live until the application quit, I also use top command to check the memory usage. I found a lot of node, element, and other children object still live after the xmlDocument do release. I found that the memory usage of this application is increasing rapidly. Can any one give me a guilde to force the system to dealloc the memory during the for loop. I need to batch handle a lot of xml files. But after the application runs for a while, the system will crash because of no memory. ___ 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/rols%40rols.org This email sent to r...@rols.org ___ 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/lists%40kai-bruening.de This email sent to li...@kai-bruening.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 arch...@mail-archive.com
Re: Should I learn CoreData for this project?
Hi David, this question is most definitely on topic :-) So, lets see, what would Core Data give you: - Scalability, fast incremental loads and saves for big data sets. I don’t think you’ll need this. Loading and saving 500 items each time will be fast enough. - A data model modeler. That’s actually more valuable then it may seem on first glance. I often look at my Core Data models when thinking about algorithms and want to recap how the object graph looks. - Automatic and semi-automatic version migration. Depends on the lifecycle of your application. When needed, it’ll save you tons of time. - Object graph consistency management. A big one. Core Data automatically updates inverse relationships as needed. A lot of work to do manually, and always a source of subtle bugs. - Automatic undo support. Big - Disadvantage: Core Data does not support ordered relationships. That is, it uses sets instead of arrays. If you need an order, you have to manage this yourself. Not hard, but sometimes an annoyance (the reason for this "shortcoming" are hard technical problems). That’s it out of my head. I’m sure I forgot something. The learning effort? Hard to say. Core Data is well documented and works (almost always) as advertised. So it depends on how well you learn new abstractions. One unrelated advice: by all means use garbage collection. It makes object graph management (and a lot of other things) so much easier, no matter whether you use Core Data or not. Good luck! Kai On 4.11.2009, at 05:22, David Hirsch wrote: So, I'm hearing folks sing the praises of CoreData, which I have not yet learned. It seems like a long uphill climb, but if life will be spectacular afterwards, I'll do it. I am a semi-casual programmer; I've just finished a couple of small programs that do not use CoreData, and I can see the advantage in gaining open/save and undo/ redo for free, but I'm concerned about the work I'll have to put in to learn it. I've read a bunch of the CoreData intro documentation, but it doesn't give a feel for how difficult it will be to learn, nor how big the advantages are if I do. Here's the next project I'm going to work on, for which I'm considering CoreData: A simulated annealing code for class scheduling. The CoreData part would lie in managing all the lists involved: classes, rooms, instructors, preferences, conflict cost weights, etc. I estimate that I will have about 500 items spread over about 10 arrays. I would not expect to have a complex object graph (if that's the right term) - just a lot of items in lists, items that need to be managed, displayed, saved, loaded, etc. I could use NSArrays for all these, which I currently understand. Does this sound like it's worth learning CoreData for? Thanks, Dave S.A.: I hope this is on topic; I think it is. Those recent projects I mentioned: http://almandine.geol.wwu.edu/~dave/research/code/ModeMaker/ http://almandine.geol.wwu.edu/~dave/research/code/ModeQuiz/ Dave Hirsch Associate Professor Department of Geology Western Washington University persistent email: dhir...@mac.com http://www.davehirsch.com voice: (360) 389-3583 aim: dhir...@mac.com vCard: http://almandine.geol.wwu.edu/~dave/personal/DaveHirsch.vcf ___ 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/lists%40kai-bruening.de This email sent to li...@kai-bruening.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 arch...@mail-archive.com
Re: Should I learn CoreData for this project?
On 4.11.2009, at 11:33, Ruotger Skupin wrote: more disadvantages to mention: 1. schema updates with every model change if you use an sql store (you have to make a mapping for every single from version/ to version combination you need to support) In Snow Leopard Core Data does this automatically for "simple" cases. For non-simple cases you would have to write code for migration of non- Core Data documents, too. 2. multithreaded core data is very hard to get right (multiple contexts, data merges) Isn’t this true for multi threaded code in general? Seriously, the documentation explains how to structure multi threaded use of Core Data. This might even save you some pitfalls compared with a "naive" approach to multi-threading a model. 3. performance tuning of core data often means making your schema more complex (see also point 1) Probably irrelevant for the task at hand. 4. debugging core data can be hard (most bugs only get to the surface when you try to save your data). Sure, you have more black box behavior compared to a hand crafted model. Helps to go by the recommendations in the documentation and avoid anything which smells like a hack. 5. core data throws exceptions all over the place so you may end up with a try-catch block with every data access in your code Not my experience. As with the whole of Cocoa, exceptions in Core Data indicate programmer errors, which should be fixed before releasing. If your data set fits in memory and you don't mind loading it all at once, stay away from core data. my two cents Ruotger On 04.11.2009, at 08:54, Kai Brüning wrote: Hi David, this question is most definitely on topic :-) So, lets see, what would Core Data give you: - Scalability, fast incremental loads and saves for big data sets. I don’t think you’ll need this. Loading and saving 500 items each time will be fast enough. - A data model modeler. That’s actually more valuable then it may seem on first glance. I often look at my Core Data models when thinking about algorithms and want to recap how the object graph looks. - Automatic and semi-automatic version migration. Depends on the lifecycle of your application. When needed, it’ll save you tons of time. - Object graph consistency management. A big one. Core Data automatically updates inverse relationships as needed. A lot of work to do manually, and always a source of subtle bugs. - Automatic undo support. Big - Disadvantage: Core Data does not support ordered relationships. That is, it uses sets instead of arrays. If you need an order, you have to manage this yourself. Not hard, but sometimes an annoyance (the reason for this "shortcoming" are hard technical problems). That’s it out of my head. I’m sure I forgot something. The learning effort? Hard to say. Core Data is well documented and works (almost always) as advertised. So it depends on how well you learn new abstractions. One unrelated advice: by all means use garbage collection. It makes object graph management (and a lot of other things) so much easier, no matter whether you use Core Data or not. Good luck! Kai On 4.11.2009, at 05:22, David Hirsch wrote: So, I'm hearing folks sing the praises of CoreData, which I have not yet learned. It seems like a long uphill climb, but if life will be spectacular afterwards, I'll do it. I am a semi-casual programmer; I've just finished a couple of small programs that do not use CoreData, and I can see the advantage in gaining open/save and undo/redo for free, but I'm concerned about the work I'll have to put in to learn it. I've read a bunch of the CoreData intro documentation, but it doesn't give a feel for how difficult it will be to learn, nor how big the advantages are if I do. Here's the next project I'm going to work on, for which I'm considering CoreData: A simulated annealing code for class scheduling. The CoreData part would lie in managing all the lists involved: classes, rooms, instructors, preferences, conflict cost weights, etc. I estimate that I will have about 500 items spread over about 10 arrays. I would not expect to have a complex object graph (if that's the right term) - just a lot of items in lists, items that need to be managed, displayed, saved, loaded, etc. I could use NSArrays for all these, which I currently understand. Does this sound like it's worth learning CoreData for? Thanks, Dave S.A.: I hope this is on topic; I think it is. Those recent projects I mentioned: http://almandine.geol.wwu.edu/~dave/research/code/ModeMaker/ http://almandine.geol.wwu.edu/~dave/research/code/ModeQuiz/ Dave Hirsch Associate Professor Department of Geology Western Washington University persistent email: dhir...@mac.com http://www.davehirsch.com voice: (360) 3
-[NSDateFormatter dateFormatFromTemplate:options:locale:] does not work as expected
Hi, I am having problems using -[NSDateFormatter dateFormatFromTemplate:options:locale:] (new in 10.6.). It’s a great API which makes world-savvy custom date formats possible. Unfortunately it does not seem to work. Examples of wrong results are: - Hour format templates like "h a" (12 Hour with AM/PM) are converted to format "H" (24 Hour) under US locale. Other combinations ("ha ", "h", "H" under US or German locale) also always return "H". - The template "EEyMd" is converted to format "EE, -M-d" under German locale. This is completely wrong, expected would be "EE, d.M.". I filed a bug under rdar://7803429. Does anybody have similar experiences with this method? Any work around to make it work? - Kai - Test code: The following code: NSLocale* usLocale = [[NSLocale alloc] initWithLocaleIdentifier:@"en-US"]; NSLocale* germanLocale = [[NSLocale alloc] initWithLocaleIdentifier:@"de-DE"]; NSString* format = [NSDateFormatter dateFormatFromTemplate:@"h a" options:0 locale:usLocale]; NSLog (@"Template “h a” with US local results in �...@”", format); format = [NSDateFormatter dateFormatFromTemplate:@"H" options:0 locale:usLocale]; NSLog (@"Template “H” with US local results in �...@”", format); format = [NSDateFormatter dateFormatFromTemplate:@"h" options:0 locale:usLocale]; NSLog (@"Template “h” with US local results in �...@”", format); format = [NSDateFormatter dateFormatFromTemplate:@"h a" options:0 locale:germanLocale]; NSLog (@"Template “h a” with German local results in �...@”", format); format = [NSDateFormatter dateFormatFromTemplate:@"H" options:0 locale:germanLocale]; NSLog (@"Template “H” with German local results in �...@”", format); format = [NSDateFormatter dateFormatFromTemplate:@"EEyMd" options:0 locale:germanLocale]; NSLog (@"Template “EEyMd” with German local results in �...@”", format); gives me this output: Template “h a” with US local results in “H” Template “H” with US local results in “H” Template “h” with US local results in “H” Template “h a” with German local results in “H” Template “H” with German local results in “H” Template “EEyMd” with German local results in “EE, -M-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/archive%40mail-archive.com This email sent to arch...@mail-archive.com
How to parse multipart/form-data?
Hi, I'm using CocoaHTTPServer to upload files from computer to iOS devices. But the result NSData received from the browser is multipart form data, which is really hard to parse manually. I know I can write a parser from scratch, however, it's time consuming and bug prone. I'm wondering wether there's a sophisticated library/framework for this. Any help would be appreciated. Thanks in advance. Best regards, Kai nonamel...@me.com sent from Mobile Me ___ 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: https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: My try/catch block isn't catching exceptions on 10.6
On 28.11.2009, at 13:57, Gwynne Raskind wrote: > On Nov 28, 2009, at 4:25 AM, Greg Parker wrote: >> Here's a fun idiom for handling both C++ and Objective-C exceptions in the >> same place (on iPhone and 64-bit Mac). >> >> @try { >> // do stuff >> } @catch (NSException *e) { >> // NSException >> } @catch (id e) { >> // Other Objective-C exception >> } @catch (...) { >> // Non-ObjC exception >> // Decode it by rethrowing it inside a C++ try/catch. >> try { >> @throw; >> } catch (std::bad_cast& e) { >> // C++ failed dynamic cast to reference type >> } catch (...) { >> // Other C++ exception >> // or non-ObjC non-C++ foreign exception >> } >> } > > > I apologize if this is a dense question, but can't you just go like this? > > @try { > // do stuff > } @catch (NSException *e) { > // NSException > } @catch (id e) { > // Other Objective-C exception > } @catch (std::bad_cast& e) { > // C++ failed dynamic cast to reference type > } @catch (...) { > // Other C++ exception > // or non-ObjC non-C++ foreign exception > } No - there’s a syntactically subtle but important difference above between @try/@catch and try/catch, the further being the Objective-C variant, the later C++. Kai ___ 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 arch...@mail-archive.com
Re: Migrating changed objects between contexts
On 2.12.2009, at 18:27, Jim Thomason wrote: >> It shouldn't deadlock. The doc for -lock says: "If you lock (or successfully >> tryLock) a managed object context, the thread in which the lock call is made >> must have a retain until it invokes unlock. If you do not properly retain a >> context in a multi-threaded environment, this will result in deadlock." Did >> you heed it? > > It didn't matter one way or the other. Incidentally, I've seen that > warning too, but in this case I was sharing the [document > managedObjectContext] across threads, so it was guaranteed to exist as > long as the window was open. So I take it that you have code in place that postpones window closing while your background thread works with the context? > What was the need to retain it in that > case, anyway? To safe writing above code. > > Sigh. Nevermind, I'm an idiot. My worker thread that refreshes my > graph does 3 different things in it. 1 is fairly old and has been > around for months, the other 2 things are newly added. > > The original one ended up calling rearrangeObjects on an array > controller, and since that's not threadsafe (right?) I dispatched the > call to the main thread, and helpfully set waitUntilDone:YES. That was > fine originally, since the app was guaranteed not to be looking at the > context in the main thread, and basically I got lucky and could get > away with it. > > But now, due to additional processing in the main thread, it was > looking at the context. So my worker thread would happily chug along > until it reached the rearrangeObjects call. It'd hand it off to the > main thread and wait for it to finish. But the main thread was paused > since my worker thread had the lock on the context. And blamo. > Deadlock. > > Solution? Disturbingly easy to see now 12 hours into trying to fix it. > Just do the rearrangeObjects on the main thread as before, but set > waitUntilDone:NO. All problems miraculously fixed. And an important lesson learned: blocking or waiting in any way while holding a lock is a dangerous thing to do. Kai ___ 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 arch...@mail-archive.com
Re: App works when launched from Xcode, not from Finder
Great you found this issue. But according to the log output, it seems that you do have a serious threading-related problem. I wouldn’t ignore this, it may raise its head any time in the future and bite you badly. Good luck Kai On 18.12.2009, at 03:26, PCWiz wrote: > Thanks, will do. > > And regarding Jeremy's note about the 2 libraries can't be loaded, those are > Input Manager plugins that have nothing to do with my app. > > But I'm happy to say that I eventually found the cause of my problem. One of > the frameworks I was using was compiled using "i386 ppc" set as the > architecture. Setting this to "Standard (32-bit/64-bit Universal)" and > recompiling the framework fixed it. Xcode seems to launch the app in 32 bit > mode whether its in Debug or Release (because I have the Active Architecture > set to i386). When launched from Finder, the app launches in 64 bit mode, and > since that framework was not compiled with the x86_64 architecture it screwed > up the app. > > Hope this helps anyone else that runs into this issue. > > Independent Cocoa Developer, Macatomy Software > http://macatomy.com > > > On 2009-12-17, at 9:55 AM, Jens Alfke wrote: > >> >> On Dec 16, 2009, at 10:04 PM, PCWiz wrote: >> >>> I'm not using NSLock or NSRecursiveLock directly. I'm using @synchronized >>> on an object that multiple threads acess, to allow only one thread to >>> access the object at a time. >> >> The fact that the description of the lock is " >> '(null)'" makes me suspect that you're synchronizing on a nil pointer, i.e. >> that when you call >> @synchronized(foo) { ... } >> the value of foo is nil. I'm pretty sure that's illegal, and I would have >> thought it would throw an exception, but maybe not. Try putting a check >> above the block, something like >> NSAssert(foo!=nil, @"no foo"); >> >> —Jens > > ___ > > 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/lists%40kai-bruening.de > > This email sent to li...@kai-bruening.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 arch...@mail-archive.com
Re: App works when launched from Xcode, not from Finder
On 18.12.2009, at 15:54, PCWiz wrote: > Yeah I definitely need to squash this bug. But as Greg Parker said, > @synchronized (which I'm using) has nothing to do with NSRecursiveLock. And > the only other threading related classes I'm using are NSOperationQueue and > NSInvocationOperation. Would one of these classes use NSRecursiveLock? Possibly in Leopard, but very unlikely under Snow Leopard: NSOperationQueue is now based on Grand Central. > I am positive that I'm not directly using NSRecursiveLock or NSLock anywhere > in my project. Have you tried to break on [NSRecursiveLock alloc]? Or on one of the init methods? Kai > > Independent Cocoa Developer, Macatomy Software > http://macatomy.com > > > On 2009-12-18, at 12:07 AM, Kai Brüning wrote: > >> Great you found this issue. >> >> But according to the log output, it seems that you do have a serious >> threading-related problem. I wouldn’t ignore this, it may raise its head any >> time in the future and bite you badly. >> >> Good luck >> Kai >> >> On 18.12.2009, at 03:26, PCWiz wrote: >> >>> Thanks, will do. >>> >>> And regarding Jeremy's note about the 2 libraries can't be loaded, those >>> are Input Manager plugins that have nothing to do with my app. >>> >>> But I'm happy to say that I eventually found the cause of my problem. One >>> of the frameworks I was using was compiled using "i386 ppc" set as the >>> architecture. Setting this to "Standard (32-bit/64-bit Universal)" and >>> recompiling the framework fixed it. Xcode seems to launch the app in 32 bit >>> mode whether its in Debug or Release (because I have the Active >>> Architecture set to i386). When launched from Finder, the app launches in >>> 64 bit mode, and since that framework was not compiled with the x86_64 >>> architecture it screwed up the app. >>> >>> Hope this helps anyone else that runs into this issue. >>> >>> Independent Cocoa Developer, Macatomy Software >>> http://macatomy.com >>> >>> >>> On 2009-12-17, at 9:55 AM, Jens Alfke wrote: >>> >>>> >>>> On Dec 16, 2009, at 10:04 PM, PCWiz wrote: >>>> >>>>> I'm not using NSLock or NSRecursiveLock directly. I'm using @synchronized >>>>> on an object that multiple threads acess, to allow only one thread to >>>>> access the object at a time. >>>> >>>> The fact that the description of the lock is " >>>> '(null)'" makes me suspect that you're synchronizing on a nil pointer, >>>> i.e. that when you call >>>>@synchronized(foo) { ... } >>>> the value of foo is nil. I'm pretty sure that's illegal, and I would have >>>> thought it would throw an exception, but maybe not. Try putting a check >>>> above the block, something like >>>>NSAssert(foo!=nil, @"no foo"); >>>> >>>> —Jens >>> >>> ___ >>> >>> 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/lists%40kai-bruening.de >>> >>> This email sent to li...@kai-bruening.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 arch...@mail-archive.com
Re: Program not working under Snow Leopard
On 28.12.2009, at 13:07, Quincey Morris wrote: > On Dec 27, 2009, at 07:23, insanely...@mac.com wrote: > >> I'm working on a program that manages file downloads via NSURLConnection. I >> was developing under Leopard and the program was working just fine. I've >> switched to a new computer running Snow Leopard with the latest Xcode. My >> program now crashes with the ever popular EXEC_BAD_ACCESS error at seemingly >> random points. At first it was consistently crashing when I was attempting >> to reference the value in an NSDate variable (via NSLog). So I commented >> that line out and then it crashed with the same error on a different >> variable. Also, I can run the program just fine in the debugger with it set >> to Debug. Once it's set to Release it crashes. I've confirmed the settings >> are identical for Debug/Release. And as I said, this code worked fine in >> Leopard. > > No one can say the cause without further evidence. However, given the > symptoms, the *high probability* is that: > > 1. You have a memory management bug in your code. > > 2. It never showed up under Leopard by pure luck. Since you switched computers together with the OS, there’s another possibility: is your old computer by chance single-core? And do you have any threading in your code? If so, threading bugs tend to be much worse under multi-core because you are introducing real parallelism. Good luck Kai ___ 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 arch...@mail-archive.com
Re: Why is [NSArray arrayWithObjects:] failing for me?
On 4.1.2010, at 13:44, Charles Jenkins wrote: > Thank you to all who offered your expertise! > > Whatta dumb mistake! I thought all objects were retained once when created, > not auto-released. Gah! > > I've been programming for 20+ years--mostly with C++ and C#. Cocoa-ObjC has > the steepest learning curve of any programming I have ever done. Strange that you feel so. I’d say C++ is way more complex - although I did 20+ years of C++ coding and only 2 of ObjC/Cocoa. But in any case you can take the whole retain/release problem out of your learning curve by switching to GC - unless you are targeting the iPhone. > It makes me feel like an idiot, so you can certainly expect to see more of > these noobish questions from me... Thanks in advance for your help and > patience! Kai___ 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 arch...@mail-archive.com
Re: Why is [NSArray arrayWithObjects:] failing for me?
On 4.1.2010, at 13:58, Charles Jenkins wrote: > On 2010-01-03 00:08, Eric Smith wrote: >> Correct, do not release the array. If you don't create it with "init", or >> retain it, then you should not release it. >> > Eric, thank you for stating that rule. It should be easy enough to remember > and help me avoid this problem in the future. > > In my defense, there seems to be a bug in the latest XCode, which make > strings stored in NSArrays look like garbage when inspected during debugging. > So the elements of pnl appeared to be trashed immediately upon creation. > That's why I was looking for the bug in the wrong place. Yes, the data formatters in the debugger do not always work. Typing "po " (e.g. po [pnl objectAtIndex:0]) normally works. "po" stand for "print object". > > Does anyone else find XCode extremely buggy? Not at all. For me Xcode is extremely robust and a lot of fun to use. I use the latest version under Snow Leopard, but it was mostly the same under Leopard, too. My impression was that Xcode gained a lot of robustness when it was switched to GC. > I have to continually close and reopen my editing window because the code > display gets trashed and appears to scramble my code. It doesn't really > change the source code file; it just makes it look as if I've randomly gone > through the file deleting stuff, and when I see that happen, I immediately > save, close, and reopen the window, and everything is fine. Sounds scary, i’ve never seen this. > > Mac software is usually first class, stable, and beautiful. How do folks > write such great software when they're stuck with such a sub-par IDE? :-) They aren’t. There must be something very special with your setup. Best Kai ___ 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 arch...@mail-archive.com
Re: Use NSDocument as a variable of another NSDocument
On 18.1.2010, at 23:17, Jarod Wen wrote: > Good points guys! In my application the table data depends on the movie it > comes from. And also, there will be several tables for one movie (for > example, one is for the video information and the other is about the audio > information). > > The reason why I want to select the document architecture is because all the > table data can be edited by the user, and finally, these data should be able > to save onto the disk as text for further usage. Maybe a wrapped file for > both the movie and the tables will be a better choice? In this way I think a > NSDocument for the movie and then a list of table controllers will be better? I’d say you are starting to approach it from the right side now: consider how your application should be structured document-wise as the user sees it. After you got a clear picture, mapping this to AppKit concepts is the second step. Concerning NSDocument, this is very much tied to what the user sees as a document: something visible in the Finder which can be double-clicked, edited, saved again and so on. So you’ll have to decide whether your tables are documents in their own right or whether the "save onto the disk as text for further usage" is an export. In the later case you would have a single document which is able to export tables as text files (or Excel or Numbers or HTML, you name it). Hope this helps a little Kai > > Thanks! > > On Jan 18, 2010, at 1:59 PM, Jeffrey Oleander wrote: > >>> At Mon, 2010/01/18 15:19, Quincey Morris >>> wrote: >>> On 2010 Jan 18, at 10:48, Jarod Wen wrote: >>>> Is it a proper design to use a NSDocument as a >>>> variable of another NSDocument? >>>> >>>> I am now working on an application which generates >>>> some information from a movie. The information >>>> generated will be showed as a table, and the >>>> information in the table can be saved/opened. >>>> Multiple types of information are possible >>>> so for one movie there may be several tables. >>>> >>>> I used the NSDocument architecture for the movie >>>> document, and I am a little bit confused about >>>> the hierarchy... >> >>> The question isn't whether one document object >>> can contain a reference to another document >>> object. The question is what's supposed to >>> happen later when the derived (table) >>> document is re-opened. >>> >>> If the table refers to information in the >>> original (movie) document, you'll need to >>> open the movie document too. >> >> That depends on what you mean by "refers to". >> >> I can refer to the Encyclopedia Brittanica >> without opening it. I can say "this is >> related to the movie 'Blah' whose screen- >> play was written by Blurp, was direced >> by Blorp, and produced by Bloop" without >> having to open up that movie file. >> >> It just depends on what Jarod Wen wants >> to do. >> >> If he wants the extracted data which he >> displays in tables to be mostly independent >> of the original movie, then he will need >> that to be in a document with its own >> hierarchy. The original movie would be >> one document with its own data, >> and the extracted data for that movie might >> be a separate document with its own, >> independent data hierarchy. If he does >> that, then the 2 files can diverge, and >> he might have to consider how to control >> proliferation of related data files, >> each derived from the same movie file. >> >> So, his question becomes, what object >> owns each document type? What object >> owns the movie? What object owns the >> derived data that he displays as tables? >> Or, should he just keep only the movie >> document and extract/generate at run- >> time the data to display in table views >> as "views of the movie". >> >> >> >> ___ >> >> 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/jarodwen%40gmail.com >> >> This email sent to jarod...@gmail.com > > -- > J.W. > > > > > ___ > > Cocoa-dev mailing
-[NSBundle preferredLocalizations]
Hi, Apple’s documentation states about -[NSBundle preferredLocalizations]: "The localizations in the array are not returned in any particular order." This makes no sense, I’d expect this to be true for -[NSBundle localizations], why I’d expect -[NSBundle preferredLocalizations] to be implemented similar to the following: - (NSArray*) preferredLocalizations { return [NSBundle preferredLocalizationsFromArray:self.localizations]; } and the docu of -[NSBundle preferredLocalizationsFromArray:] says: "These strings are ordered in the array according to the current user's language preferences". Could somebody with insight confirm whether this is a documentation bug? (Sure, I could check the actual order. But if the documentation is correct, the result would be meaningless for the future.) Thanks Kai ___ 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 arch...@mail-archive.com
Re: -[NSBundle preferredLocalizations]
Done: rdar://7637393 Kai > > On Feb 10, 2010, at 5:52 AM, Kai Brüning wrote: > >> Could somebody with insight confirm whether this is a documentation bug? > > This is indeed an error in the documentation. Please file a bug against the > documentation with the information you have provided. > > Douglas Davidson ___ 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 arch...@mail-archive.com
Re: #define and if statements
A tip for the next time you have problems with macros: use Xcode’s Preprocess command (in the Build menu) to see your macros resolved. Helps a lot in such cases. Kai On 27.2.2010, at 07:37, Adam Gerson wrote: > Thanks! I can't believe I missed that. Its 1:35am here and its been a long > day. > > Adam > > > On Sat, Feb 27, 2010 at 1:24 AM, Dave DeLong wrote: >> #define's are basically a simple find and replace, so if you do: >> >> #define IsDemo NO; >> >> and then do: >> >> if (IsDemo) { ... } >> >> It's going to become: >> >> if (NO;) { ... } >> >> See the problem? You've got a semicolon in there. Generally, you don't end >> a #define with a semicolon unless you want a semicolon in the place where >> the #define will be used. >> >> Dave >> >> On Feb 26, 2010, at 11:22 PM, Adam Gerson wrote: >> >>> I have the following constant set up. I have tried all three of these >>> variations and none of them work in an if statement in cocoa. I get >>> error: expected `)' before ';' token >>> >>> #define IsDemo NO; >>> #define IsDemo false; >>> #define IsDemo 0; >>> >>> >>> if (IsDemo) { >>> bla... >>> } >>> >>> Same problem, when I try: >>> #define FreeUpdateDaysAllowed 180; >>> if (daysSoFar > FreeUpdateDaysAllowed) >>> >>> >>> What am I doing wrong? Whats the right way to have a bool or int constant? >>> >>> Thanks, >>> Adam >>> ___ >>> >>> 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/davedelong%40me.com >>> >>> This email sent to davedel...@me.com >> >> > ___ > > 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/lists%40kai-bruening.de > > This email sent to li...@kai-bruening.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 arch...@mail-archive.com
Re: Short-circuit evaluation
On 23.6.2009, at 17:14, Kyle Sluder wrote: On Tue, Jun 23, 2009 at 7:47 AM, Graham Cox wrote: I'd like to if I could - unfortunately in this case the method in question is -validateMenuItem: which is designed to have intentional side- effects, like setting the item's state or title, as well as returning a boolean value for the enable state. The API might have been better if it returned nothing and made you handle the enable state directly also, but it wasn't so I'm stuck with it. There is no reason you can't do this: BOOL a = [foo bar]; BOOL b = [baz quux]; return a || b; Or, different style: BOOL a = NO; if ([foo bar]) a = YES; if ([baz quux]) a = YES; return a; Kai ___ 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 arch...@mail-archive.com
Re: How to share Cocoa classes?
On 6.7.2009, at 20:30, Alexander Bokovikov wrote: Thank you for the reply, It looks like your case is just what I'd like to have, though my situation is simpler, as my shared code is the same for different projects (though different projects may include other different pieces). Therefore the problem of code stripping (which you described) should not appear for me. Nevertheless, I'd appreciate it highly, if you'll guide me through the XCode project settings adjustment, as it sounds foggy for me, how to make static library to rebuild itself when main project is built. What particular settings should I add to the main project? Also it's not clear, where to put that "common" header file? What is the correct location for that? Am I correct in my understanding, that placing this .h file into the right place I'll have the ability to include my classes (stored in static library) by single #import ? If yes, then it is just, what I'd like to get! The same question is about static library itseklf -- where it should be located? Should I create my own directory system or is it better to use some standard (system) directories for that? If I must use my own directories, then where should I add a path to them to avoid the necessarity to add this path to every new XCode project manually? Besides the suggestions of other, an additional method to handle this are Xcode source trees. You can define paths to source trees in Xcode preferences (that is, per machine), and then use these definitions to set paths in projects relative to a defined source tree. This frees you from the need to have the exact same directory setup on each computer which uses the project. Kai ___ 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 arch...@mail-archive.com
NSView.alphaValue without Core Animation Layer?
Hi, the documentation for -[NSView setAlphaValue:] states: "Sending this message to a view that is not managing a Core Animation layer causes an exception." But experiment under 10.6 shows that not only no exception is thrown, setting the alpha value on views without Core Animation layer even works just fine. Is this a feature of Snow Leopard we can dependent upon? We were not able to find it documented, not even in the AppKit release notes for 10.6. Thanks Kai ___ 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 arch...@mail-archive.com
Re: image transition while dragging
Hi Rajesh, as far as I know Cocoa has no provision for this at least up to Leopard. (If I remember correctly, you could do this easily with Carbon ;-) ) If you absolutely want this behavior, I can think of two ways to persuade: - Return no or an empty image from dragImageForRowsWithIndexes:, track the mouse yourself and move a temporary window with an image of your chosing around on the screen. Should be doable, but probably not in a single afternoon. - Read about Cocoa hacking and look for some private API IB might be using for its dragging. Usual caveats apply, like Apple might break your code with any update etc. Best success Kai On 23.4.2009, at 13:23, rajesh wrote: Hi All, I am working on dragging table row (not for re-ordering or deleting) onto a NSView I am returning an processed image (for dragImage) in - (NSImage *)dragImageForRowsWithIndexes:(NSIndexSet *)dragRows tableColumns:(NSArray *)tableColumns event:(NSEvent *)dragEvent offset: (NSPointPointer)dragImageOffset { // return doctoredImage; } I want to change the dragged image with smooth transition to another image, whenever it reaches its destination(NSView) or when drag moves out of the source(NSTableView) just like the effect to the drag image in interface builder tool when items from palette are dragged out of it. Any pointers or ideas is appreciated. Thanks Rajesh. ___ 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/kai%40granus.net This email sent to k...@granus.net ___ 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 arch...@mail-archive.com
Re: Drawing 1 pixel line with zoom change
On 12.5.2009, at 06:23, Graham Cox wrote: On 12/05/2009, at 12:44 AM, Sahana A wrote: We have a feature in our application wherein we have to draw a 1 pixel line. This drawing also varies relative to the zoom factor of our view. For example if we are drawing at a zoom factor of 200% we draw 0.5 pixel line. ( basically: 1/zoomfactor width of line; 1 if the zoomfactor < 100 ). For most of the times we succeed in drawing the 1 pixel line. However after we change the zoom factor, our drawing fails. Our 1 pixel line is now drawn in 2 pixels. For example: On changing the zoom values from say 100% to 300% and back to 100% again, the single pixel line sometimes draw in 2 pixels. Even if the stroke width is set to 0.0 or 1.0, the stroked line will draw 2 pixels. It's not just a case of setting the line width, but also of placing the line where you want it. Strokes are placed so that they are centred on the co-ordinate, so half the line is above and half below the integral co-ordinate position. This is true even if you suppress anti-aliasing, which make matters worse since the lightening of the line is disabled and it'll draw as a solid 2 pixel line. You need to truncate the line's co-ordinates to a whole number then add or subtract 0.5 so that the line is drawn on the pixel, not on the co-ordinate. This goes into the right direction, but things are a little more involved. Basically you need to convert to device coordinates first, to the correct rounding, convert the result back and then draw. The 10.5-only NSView methods convertPointToBase: and friends are quite helpful for this. For more details see Apples "Resolution Independence Guidelines". Kai --Graham ___ 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/kai%40granus.net This email sent to k...@granus.net ___ 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 arch...@mail-archive.com