Re: How to change the product name with command line builds?
On Jan 14, 2011, at 7:55 AM, Gabriel Zachmann wrote: > I've got an Xcode project that compiles and works fine. > > The short question now is: what is the proper way to change the bundle's name > from the command line? Assuming your project is set up like normal (e.g. with Info.plist values based on build settings), it may be as simple as: xcodebuild -target Foo -configuration Release build PRODUCT_NAME=Foo2 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 arch...@mail-archive.com
Re: Get iphoto scripting bridge handle without starting iphoto?
Hi Gabriel, No, you cannot. Scripting Bridge works by sending messages back and forth with a target process. If there is no process running, there isn't anything to communicate with. A scripting dictionary does not (and cannot) include information about how to access the on disk data iPhoto uses to represent your library. It only contains information about how to ask the iPhoto process for information. There may be other ways to get at what you want (iPhoto has an XML file that describes the library - I don't think it's for third party use, but I could be wrong), but Scripting Bridge will require launching the app. -Ken On Fri, Jan 14, 2011 at 10:10 AM, Gabriel Zachmann wrote: > My question is: can I get a scripting bridge handle on iPhoto without > making iPhoto launch? > And can I retrieve a list of iPhoto albums and a list of images in an album > without making iPhoto launch? > > Right now, I am using > iPhoto_ = [[SBApplication > applicationWithBundleIdentifier:@"com.apple.iPhoto"] > retain]; > but that fires up iPhoto, which can be a bit slow. > Also, as a user, I find it a bit disturbing that iPhoto has been launched > by another program. > > > Best regards, > Gabriel. > > > ___ > > 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/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Get iphoto scripting bridge handle without starting iphoto?
My question is: can I get a scripting bridge handle on iPhoto without making iPhoto launch? And can I retrieve a list of iPhoto albums and a list of images in an album without making iPhoto launch? Right now, I am using iPhoto_ = [[SBApplication applicationWithBundleIdentifier:@"com.apple.iPhoto"] retain]; but that fires up iPhoto, which can be a bit slow. Also, as a user, I find it a bit disturbing that iPhoto has been launched by another program. Best regards, Gabriel. smime.p7s Description: S/MIME cryptographic signature ___ 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
Zoom sometimes messes up resize increments
Hello. I have a window in my application for which I have set resize increments. When I click the zoom button in the window's title bar, sometimes it obeys the resize increments, i.e. the window fills the screen as much as possible without violating the resize increments. But sometimes the window resizes in such a way that it does violate the resize increments. I have not yet figured out what conditions exactly cause this. I suspect it has something to do with the initial size of the window, but I am not sure. I have created a minium working example. It is a standard Xcode- created Cocoa application, but I used a custom view for the content view of the main window. The custom view draws a grid and the window resize increments are the grid cell's dimensions. Here is the implementation of the custom view: === CODE BEGIN === #import "CustomView.h" #define CELL_WIDTH 100 #define CELL_HEIGHT 100 @implementation CustomView - (void)awakeFromNib { NSWindow *window = [self window]; // Set the size of the window content's height and width to a // multiple of the cell height and the cell width, respectively. NSRect frame = [window frame]; frame.size = NSMakeSize(5 * CELL_WIDTH, 5 * CELL_HEIGHT);; frame = [NSWindow frameRectForContentRect:frame styleMask:NSTitledWindowMask]; [window setFrame:frame display:TRUE]; // Set the window's resize increments to the cell dimensions. [window setResizeIncrements:NSMakeSize(CELL_WIDTH, CELL_HEIGHT)]; } - (void)drawRect:(NSRect)dirtyRect { NSRect bounds = [self bounds]; // Draw background color. [[NSColor whiteColor] set]; NSRectFill(bounds); // Draw a grid. [[NSColor gridColor] set]; CGFloat x = 0, y = 0; while (x < bounds.size.width) NSFrameRect(NSMakeRect(x += CELL_WIDTH, 0, 1, bounds.size.height)); while (y < bounds.size.height) NSFrameRect(NSMakeRect(0, y += CELL_HEIGHT, bounds.size.width, 1)); } @end === CODE END === When I played around with the values of CELL_WIDTH and CELL_HEIGHT, I noticed that the problem occurs for some values and for some it does not. For example, it does not occur when I use 100 and 100, but it does occur when I use 47 and 47. Am I doing something wrong or is this a bug? If I am doing something wrong, how can I do it right? If it is a bug, how can I work around it? Thanks in advance. Best regards, Jacob ___ 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
iPhoto "external editor"
I'm working on my first Cocoa / Objective-C app: an "external editor" for iPhoto. Actually, it isn't an editor at all - its sole purpose is to replace the Modified image with a user-selected image from disk. In this way a user can select an Original in iPhoto, double-click to edit, then find the modified version on disk, and import it (preserving the link). In short a way to import Modified versions to iPhoto. So my first problem is, how does iPhoto actually fire up an external editor and pass the image or filename that it is interested in editing? -Greg___ 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 change the product name with command line builds?
I've got an Xcode project that compiles and works fine. The short question now is: what is the proper way to change the bundle's name from the command line? (and, at the same time, its executable name) A little bit of background information might be in order. I am writing a screensaver. Now some users would like to run two different instances (i.e., executables) of it concurrently, because they've got two monitors, and, in addition, they want to set different preferences for each instance. So, my idea was to just compile the program twice, once under the name Foo and once under the name Foo2. In the code, I always refer to [[bundle infoDictionary] objectForKey:@"CFBundleName"] and I save the preferences basically like this: [ScreenSaverDefaults defaultsForModuleWithName: bundle_name] My idea was to write a shell script that compiles the program, then changes the bundle name to Foo2 in Info.plist, and then compiles it again. But: is that the proper way of doing it? Am I missing anything? I suppose it's not the right way, because I tried it and SystemPreferences says that "You cannot use the Foo2 screen saver on this computer". (Yes, Foo2 does contain the "right" Info.plist - the relevant lines look like this: Foo2 CFBundleIdentifier de.zach.Foo2 CFBundleName Foo2 ) BTW: this is the shell script I used to build the two different screen savers: -- [snip] cp Info.plist Info.plist.org sed -E 's/[[:<:]]Foo[[:>:]]/Foo2/' Info.plist.org > Info.plist xcodebuild -alltargets clean xcodebuild -target Foo -configuration Release build mv ~/"Library/Screen Savers/Foo.saver" ~/"Library/Screen Savers/Foo2.saver" mv Info.plist.org Info.plist xcodebuild -alltargets clean xcodebuild -target Foo -configuration Release build -- [snip] I also considered creating a second target in Xcode, and assigning two different Info.plist files to them. However, I see two problems with this approach: 1. I would have two Info.plist files that are almost identical, which is error prone; 2. In the single target that I have currently, Info.plist is not a member of the set of files that are assigned to this target (which seems funny to me, but I have no idea whether this is fine or not) Any advice, insights, or pointers will be highly appreciated! Best regards, Gabriel. smime.p7s Description: S/MIME cryptographic signature ___ 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 Type for Button
On Sat, Jan 15, 2011 at 7:44 PM, John Joyce < dangerwillrobinsondan...@gmail.com> wrote: > > Thanks so much!! > No problem. Arguably, that release note stuff is darn hard to look through. Search > results generally don't seem to find it. I'll file a bug on the HIG docs or on IB docs to get that moved into a more > useful location. Fair enough in general. In this case, the NSImage docs do get the most important bits. Search the page for the word "template" to see. -Ken > > John > > ___ 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 Type for Button
On Jan 15, 2011, at 9:41 PM, Ken Ferry wrote: > > > On Sat, Jan 15, 2011 at 7:15 PM, Ken Thomases wrote: > On Jan 15, 2011, at 8:13 PM, John Joyce wrote: > > > Cannot seem to find this in the HIG. > > What type of image would give the inverted look of the built in media types > > (NSQuicklookTemplate for example) when in a Textured Square Button or > > Segmented control? > > > > The images appear black with a clear alpha in Interface Builder. > > > > I've tried png, tiff, pdf. > > Tried each type with clear alpha background, with black on white, vice > > versa. > > No luck. > > You need to tell the framework that the is image a template image. See > -[NSImage setTemplate:]. > > …which will happen automatically if the filename ends in Template (before the > extension). > > http://developer.apple.com/library/mac/#releasenotes/Cocoa/AppKitOlderNotes.html#NSImageTemplate > : > > Text and image effects: -[NSImage isTemplate] > > So far we've mostly talked about text. Images drawing in cells also have > visual effects applied. For example, images are automatically dimmed out in > disabled cells and darkened when pressed. > > This is extended in Leopard with a new metadata property, -[NSImage > isTemplate]. An image is a 'template' if it is a black and clear mask that > should not be presented to the user directly, but always processed into a > final form. It's similar to a glyph in a font. If a cell is given a template > image, it can perform much more sophisticated effects than usual, similar to > those done with text. The image can be dark most of the time, white in a > selected table view row, and engraved or embossed the same way text is. > > The template property does not affect the way an image draws. It's metadata > that a sophisticated client can look at. The only sophisticated client in > AppKit for 10.5 is NSCell. If you need to produce an NSImage with effects > pre-rendered, draw with a cell into an image. > > A good example of template image processing occurs in the button that shows > the bookmarks collections in Safari 3.0. This is very much a stock AppKit > button. There's a single template image set on it, which is an icon of a > book. That single image appears engraved or embossed depending on whether > button is rolled over (really, on the -interiorBackgroundStyle of the cell). > > To mark an image as a template, call -[NSImage setTemplate:]. As a > convenience, in applications linked on or after 10.5, any image read off of > disk via -[NSImage imageNamed:] whose name ends in @"Template" will be marked > as a template as it is created. This makes it easy to use template images in > Interface Builder. Just make sure your image filenames end in "Template". > > One particular effect is worth calling out, because you'll see it and likely > wonder exactly what triggers it: If a template image is drawing on a raised > background and is also supposed to look on, it will draw with a blue glow. > Think of the image as a translucent gray piece of plastic cut into the > surface of the cell, with a blue backlight behind it when the cell is on. > This will happen, for example, in selected segments of an NSSegmentedControl > with NSSegmentStyleTexturedRounded and NSSegmentSwitchTrackingSelectAny > (which means that segments behave like check boxes). You cannot rely on this > glow occurring in any particular place because framework art can change, but > AppKit promises to continue to do something appropriate. > > For an NSButtonCell, a cell's -image will be processed to look 'on' if the > cell's state is NSOnState, its showsStateBy mask contains NSContentsCellMask > (which means 'use alternate image and title when on'), and it doesn't have an > alternateImage. In Interface Builder, make a 'Toggle' button and give the > button an image. This also sets up the highlightsBy mask, but it's likely to > be what you want. > > You may note that it isn't possible to both use a distinct piece of art as an > alternateImage on a button or segmented control and also get the blue glow. > This may be somewhat limiting, but should tend to make sure this effect is > only used when appropriate. This effect helps the user to distinguish between > a button that shows an action and a button that shows the state of something. > Most buttons in the OS are actions. However, it has always been hard to > distinguish those buttons that give state. The blue glow communicates state > very effectively. Look at the calendar button in the lower left corner of > iCal in 10.5. When the mini calendar pane isn't shown, the button shows an > engraved mini-calendar. The user might think of this as either an action > 'show mini-calendar' or as a state, 'mini-calendar is off'. Luckily, both > interpretations agree on the effect of clicking the button - it should show > the calendar. Once the user clicks the button, the correct interpretation > becomes very clear: The calendar ic
Re: Image Type for Button
On Sat, Jan 15, 2011 at 7:15 PM, Ken Thomases wrote: > On Jan 15, 2011, at 8:13 PM, John Joyce wrote: > > > Cannot seem to find this in the HIG. > > What type of image would give the inverted look of the built in media > types (NSQuicklookTemplate for example) when in a Textured Square Button or > Segmented control? > > > > The images appear black with a clear alpha in Interface Builder. > > > > I've tried png, tiff, pdf. > > Tried each type with clear alpha background, with black on white, vice > versa. > > No luck. > > You need to tell the framework that the is image a template image. See > -[NSImage setTemplate:]. > …which will happen automatically if the filename ends in Template (before the extension). http://developer.apple.com/library/mac/#releasenotes/Cocoa/AppKitOlderNotes.html#NSImageTemplate: Text and image effects: -[NSImage isTemplate] So far we've mostly talked about text. Images drawing in cells also have visual effects applied. For example, images are automatically dimmed out in disabled cells and darkened when pressed. This is extended in Leopard with a new metadata property, -[NSImage isTemplate]. An image is a 'template' if it is a black and clear mask that should not be presented to the user directly, but always processed into a final form. It's similar to a glyph in a font. If a cell is given a template image, it can perform much more sophisticated effects than usual, similar to those done with text. The image can be dark most of the time, white in a selected table view row, and engraved or embossed the same way text is. The template property does not affect the way an image draws. It's metadata that a sophisticated client can look at. The only sophisticated client in AppKit for 10.5 is NSCell. If you need to produce an NSImage with effects pre-rendered, draw with a cell into an image. A good example of template image processing occurs in the button that shows the bookmarks collections in Safari 3.0. This is very much a stock AppKit button. There's a single template image set on it, which is an icon of a book. That single image appears engraved or embossed depending on whether button is rolled over (really, on the -interiorBackgroundStyle of the cell). To mark an image as a template, call -[NSImage setTemplate:]. As a convenience, in applications linked on or after 10.5, any image read off of disk via -[NSImage imageNamed:] whose name ends in @"Template" will be marked as a template as it is created. This makes it easy to use template images in Interface Builder. Just make sure your image filenames end in "Template". One particular effect is worth calling out, because you'll see it and likely wonder exactly what triggers it: If a template image is drawing on a raised background and is also supposed to look on, it will draw with a blue glow. Think of the image as a translucent gray piece of plastic cut into the surface of the cell, with a blue backlight behind it when the cell is on. This will happen, for example, in selected segments of an NSSegmentedControl with NSSegmentStyleTexturedRounded and NSSegmentSwitchTrackingSelectAny (which means that segments behave like check boxes). You cannot rely on this glow occurring in any particular place because framework art can change, but AppKit promises to continue to do something appropriate. For an NSButtonCell, a cell's -image will be processed to look 'on' if the cell's state is NSOnState, its showsStateBy mask contains NSContentsCellMask (which means 'use alternate image and title when on'), and it doesn't have an alternateImage. In Interface Builder, make a 'Toggle' button and give the button an image. This also sets up the highlightsBy mask, but it's likely to be what you want. You may note that it isn't possible to both use a distinct piece of art as an alternateImage on a button or segmented control and also get the blue glow. This may be somewhat limiting, but should tend to make sure this effect is only used when appropriate. This effect helps the user to distinguish between a button that shows an action and a button that shows the state of something. Most buttons in the OS are actions. However, it has always been hard to distinguish those buttons that give state. The blue glow communicates state very effectively. Look at the calendar button in the lower left corner of iCal in 10.5. When the mini calendar pane isn't shown, the button shows an engraved mini-calendar. The user might think of this as either an action 'show mini-calendar' or as a state, 'mini-calendar is off'. Luckily, both interpretations agree on the effect of clicking the button - it should show the calendar. Once the user clicks the button, the correct interpretation becomes very clear: The calendar icon glows blue when the pane is shown. This is obviously showing state, and the user will realize that if he clicks again then the button will turn off and the calendar pane will be hidden. -Ken > The file format doesn't matter. > > Cheers, > Ken > >
Re: Image Type for Button
On Jan 15, 2011, at 8:13 PM, John Joyce wrote: > Cannot seem to find this in the HIG. > What type of image would give the inverted look of the built in media types > (NSQuicklookTemplate for example) when in a Textured Square Button or > Segmented control? > > The images appear black with a clear alpha in Interface Builder. > > I've tried png, tiff, pdf. > Tried each type with clear alpha background, with black on white, vice versa. > No luck. You need to tell the framework that the is image a template image. See -[NSImage setTemplate:]. The file format doesn't matter. 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 arch...@mail-archive.com
Image Type for Button
Hello all, Cannot seem to find this in the HIG. What type of image would give the inverted look of the built in media types (NSQuicklookTemplate for example) when in a Textured Square Button or Segmented control? The images appear black with a clear alpha in Interface Builder. I've tried png, tiff, pdf. Tried each type with clear alpha background, with black on white, vice versa. No luck. The hig only seems to recommend image dimensions. Google wasn't helping either. Thanks, John___ 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: QuickLook returning small image
Thanks, Julien. This is helpful. On Jan 15, 2011, at 2:28 PM, Julien Jalon wrote: > When requesting a thumbnail, it's up to the underlying plug-in to honor the > requested size. > > If icon == NO, Quick Look will return the plug-in's image result as is. > > If icon == YES, Quick Look will force the requested size (because it adds > icon decoration which should match the requested size) - so if you request a > 512x512 icon, you should always get a 512x512 image. When icon == YES, I do get back an image at the specific size I request. With some file types, like PDF and HTML, the larger image still looks reasonably good, but with OmniGraffle files I get a scaled-up version of the smaller image, with horrible pixelation. > Many plug-in just use a low-resolution image stored in the file as a Quick > Look thumbnail. It's totally acceptable but nowadays, "low-resolution" should > be more toward 512x512 than 128x128. Peeking into OmniGraffle's document format (optionally either a plist or a package), I see it does exactly that for both the thumbnail *and* the preview, and its low-resolution image is small. Also there is an option on a per-document basis to store no Quick Look info at all, in which case all you see is the document icon. > Previews are more complex (generally slower to generate) and are meant to be > displayed mainly in Quick Look panel but they also appear in Cover Flow, > Column view, Info window I haven't found a way to display Quick Look previews except using QLPreviewPanel. I assume there is currently no public API for displaying a preview in an arbitrary view? I want to display nice thumbnails of OmniGraffle files (actually all file types, but these in particular), so I guess I can treat .graffle as a special case and extract the preview myself from the .graffle file. The preview is stored as a PDF; if it's a multi-page PDF, I'll grab the first page. If I find no preview, I'll fall back on my regular thumbnail logic, which will give me the document icon. > and, starting with SnowLeopard, in live previews in Finder's icons. I see the preview being used in Finder's Column mode, but in Icon mode it seems to be the thumbnail. I'll report this to Omni; the thumbnail really should be bigger in case I go into Icon mode and zoom the icons to full size. This is with the latest OmniGraffle Pro. --Andy ___ 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: sending data to a view not yet displayed
Well, not sure if this is correct, but I got it to work by calling loadView on the view's controller just after it was created. // ... dvc = [[DataDetailsViewController alloc] initWithController:self]; [dvc setManagedObjectContext:[self managedObjectContext]]; [detailViewControllers addObject:dvc]; [dvc release]; [[detailViewControllers objectAtIndex:3] loadView]; ___ 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
Core Data Model One-To-Many question/help
Hi List, I am trying to learn core data and have a very basic question on how to set up a one-to-many relationship. Can someone look at the screen shots (links below) and provide some guidance. Do I have this set up correctly? CDSites CDAnnotations My Entity "CDSites" will have Many "CDAnnotations". Thanks for the help. Phil ___ 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: sending data to a view not yet displayed
> If this is iOS, -initWithNibName doesn't actually load the nib immediately, > so the outlets won't be connected until such time as the nib is loaded, which > doesn't happen until something tries to access the view. Instead, you should > initialize your outlets' data in the -viewDidLoad method. While you could > force the nib to be loaded by accessing the view property, in low-memory > situations, the view controller will unload the view behind your back, so I > would recommend doing your initialization in -viewDidLoad. > > Just a quick reply to say this isn't iOS while I mull over your response. ___ 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: sending data to a view not yet displayed
>> So I guess my question is, how do I make sure my view is able to >> receive the data I want sent to it before it is ever displayed. I hope >> that makes sense. > > > Put the initialization in the -awakeFromNib method of that view. > I moved the view swapping setup from the init to the awakeFromNib of the app controller, but it didn't make a difference. I have this in the awakeFromNib of my app controller. - (void) awakeFromNib { // … DetailsViewController *dvc; dvc = [[ProgressViewController alloc] initWithController:self]; [dvc setManagedObjectContext:[self managedObjectContext]]; [detailViewControllers addObject:dvc]; [dvc release]; dvc = [[ProgressRunViewController alloc] initWithController:self]; [dvc setManagedObjectContext:[self managedObjectContext]]; [detailViewControllers addObject:dvc]; [dvc release]; dvc = [[DataDetailsViewController alloc] initWithController:self]; [dvc setManagedObjectContext:[self managedObjectContext]]; [detailViewControllers addObject:dvc]; [dvc release]; //... } And this is the init of each of the Controllers setup in the awakeFromNib in the app controller, with of course a different nib name. - (id) init { self = [super initWithNibName:@"DataDetailsView" bundle:nil]; if (!self) { return nil; } return self; } - (id) initWithController:(AppController *) controller { [self init]; if (!self) { return nil; } appController = controller; return self; } Did I not understand your response correctly? ___ 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: sending data to a view not yet displayed
On Jan 15, 2011, at 1:49 PM, Shane wrote: > I am creating views which are being prepared for view swapping in the > init method of my apps main controller. So the view controllers exists > and each view controller's init method calls initWithNibName:. > > My problem is that, if I swap views by selecting a view so that it is > displayed, when I load my data, data is being added to my outlets and > shown on my view. > > But if I do not select the view by clicking on my interface (so the > view has not yet been displayed since I started the app), when I load > my data, then the data that I send to my outlets does not get shown in > the view when I do select it at a later time. > > So I guess my question is, how do I make sure my view is able to > receive the data I want sent to it before it is ever displayed. I hope > that makes sense. If this is iOS, -initWithNibName doesn't actually load the nib immediately, so the outlets won't be connected until such time as the nib is loaded, which doesn't happen until something tries to access the view. Instead, you should initialize your outlets' data in the -viewDidLoad method. While you could force the nib to be loaded by accessing the view property, in low-memory situations, the view controller will unload the view behind your back, so I would recommend doing your initialization in -viewDidLoad. ___ 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: sending data to a view not yet displayed
On 16/01/2011, at 8:49 AM, Shane wrote: > So I guess my question is, how do I make sure my view is able to > receive the data I want sent to it before it is ever displayed. I hope > that makes sense. Put the initialization in the -awakeFromNib method of that view. --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/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: Composing an NSImage to print
Hi Olivier, Unless I misread this, this section cannot be doing anything helpful: NSImageView *tempIm = [[NSImageView alloc] initWithFrame:frontRect]; > [tempIm setImage:[cusThumbFront image]]; > > NSData* theData = [tempIm dataWithPDFInsideRect:[tempIm bounds]]; > NSPDFImageRep* pdfRep = [NSPDFImageRep imageRepWithData:theData]; > > // Create a new image to hold the PDF representation. > NSImage* pdfImage = [[NSImage alloc] initWithSize:IMG_SIZE]; > [pdfImage addRepresentation:pdfRep]; Have you tried just using [cusThumbFront image] instead of going through this? The system cannot create data where there isn't any, so the pdfImage cannot contain any data that wasn't already in the cusThumbFrontImage. Okay, that aside, it happens I haven't implemented printing before, so forgive me if it turns out this is a non-standard way to do things. It is the subview hierarchy that is printed. If you want to put a watermark on top of an image, have a view that draws the base image and then draws the watermark image. Or, make a subview of the view that draws the base that draws the watermark. It is possible to produce an NSImage that has the watermark and still has all the quality available in the original, I just suspect it isn't the most straightforward way to do what you'd like to here. The way you'd make such an image is to subclass NSImageRep. Subclassing NSImageRep is pretty much the same as subclassing NSView. Where in NSView you override drawRect:, in NSImageRep you override -draw. The main difference between an image and a view is in the guarantees on how they scale. If you stretch a button horizontally, the text doesn't stretch out, it stays centered. An image scales… like an image (i.e. linearly). So here's how you might make an NSImageRep that drew a base image and an overlay without rasterizing anything, even though I think this isn't the best way to solve your problem. @interface CompositeImageRep : NSImageRep { NSImage *_baseImage; NSImage *_overlayImage; NSRect _overlayFrame; } - (id)initWithBaseImage:(NSImage *)baseImage overlayImage:(NSImage*)overlayImage overlayFrame:( NSRect)overlayFrame; @property (readonly) NSImage *baseImage; @property (readonly) NSImage *overlayImage; @property (readonly) NSRect overlayFrame; @end @implementation CompositeImageRep - (id)initWithBaseImage:(NSImage *)baseImage overlayImage:(NSImage*)overlayImage overlayFrame:( NSRect)overlayFrame { NSParameterAssert(baseImage != nil); self = [super init]; if (self) { { _baseImage = [baseImage retain]; _overlayImage = [overlayImage retain]; _overlayFrame = overlayFrame; [self setSize:[baseImage size]]; } } return self; } -(void)dealloc { [_baseImage release]; [_overlayImage release]; [super dealloc]; } - (BOOL)draw { NSRect bounds = (NSRect){NSZeroPoint, [self size]}; [_baseImage drawInRect:bounds fromRect:NSZeroRect operation: NSCompositeSourceOver fraction:1.0]; [_overlayImage drawInRect:_overlayFrame fromRect:NSZeroRect operation: NSCompositeSourceOver fraction:1.0]; return YES; } - (id)copyWithZone:(NSZone *)zone { CompositeImageRep *rep = [super copyWithZone:zone]; // careful - superclass uses NSCopyObject. :-( rep->_baseImage = [_baseImage retain]; rep->_overlayImage = [_baseImage retain]; rep->_overlayFrame = _overlayFrame; return rep; } @synthesize baseImage=_baseImage, overlayImage=_overlayImage, overlayFrame=_overlayFrame; @end On Tue, Jan 11, 2011 at 7:57 AM, Olivier Palliere < oliv...@sunprotectingfactory.com> wrote: > Hi Guys, > > > > I'm working on an app for my personal use that needs to print images I drag > on an NSImageView to display a thumbnail. > > > > Source images are about 500x500 at 300dpi for most. > > > > When I want to print them, I use this snippet of code from Apple's > doc: > > frontRect = NSMakeRect(0,0,500, 500); > > > > NSImageView *tempIm = [[NSImageView alloc] initWithFrame:frontRect]; > [tempIm setImage:[cusThumbFront image]]; > > NSData* theData = [tempIm dataWithPDFInsideRect:[tempIm bounds]]; > NSPDFImageRep* pdfRep = [NSPDFImageRep imageRepWithData:theData]; > > // Create a new image to hold the PDF representation. > NSImage* pdfImage = [[NSImage alloc] initWithSize:IMG_SIZE]; > [pdfImage addRepresentation:pdfRep]; > > > > When I add this image to a NSImageView and give it to a printOperation, it > is printed crystal clear with the right resolution. > > > > If I try however, to draw this image in a new one to add my borders like > this: > > > [compositeImage lockFocus]; > [pdfRep drawInRect:frontRect fromRect:NSZeroRect > operation:NSCompositeSourceOver > fraction:1.0]; > > fpath = [NSBezierPath bezierPathWithRect:frontRect]; > [fpath setLineWidth:1]; > [[NSColor blackColor] set]; > [fpath stroke]; > [compositeIm
sending data to a view not yet displayed
I am creating views which are being prepared for view swapping in the init method of my apps main controller. So the view controllers exists and each view controller's init method calls initWithNibName:. My problem is that, if I swap views by selecting a view so that it is displayed, when I load my data, data is being added to my outlets and shown on my view. But if I do not select the view by clicking on my interface (so the view has not yet been displayed since I started the app), when I load my data, then the data that I send to my outlets does not get shown in the view when I do select it at a later time. So I guess my question is, how do I make sure my view is able to receive the data I want sent to it before it is ever displayed. I hope that makes sense. Any help much appreciated. ___ 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: Converting NSImage to cmtk yeilds green images
Hi Ken, You may want to ask on the colorsync-users mailing list as well as give sample before/after images. My quick test produced some degradation, but not more than I would expect. I'm not sure if you're seeing something else or if you expect the RGB->CMYK->RGB (when it goes back to the screen) round trip to be less lossy than it is. I have some comments, but most likely they aren't enough for you. (1) Why are you using device vs calibrated? You should almost never use device color spaces. (2) You need to bracket the setCurrentContext: with +[NSGraphicsContext save/restoreGraphicsState]. You are leaving the current context pointing at your bitmap here. In addition, the context that was previously current may be deallocated. (3) The NSImage methods that start with -composite are deprecated. (4) FYI, -[NSBitmapImageRep bitmapImageRepByConvertingToColorSpace:renderingIntent:] exists. -Ken Cocoa Frameworks On Fri, Jan 14, 2011 at 2:06 PM, Ken Tozier wrote: > Hi > > I'm trying to write an NSImage category that converts an image to cmyk . It > sort of works, in that it does produce a new image, but all images have a > dark green cast to them and look sort of solarized or like negatives. Anyone > point out what I'm doing wrong? > > Thanks for any help > > - (NSImage *) cmykImage > { >NSImage *result = [[NSImage alloc] > initWithSize: [self size]]; > >NSBitmapImageRep*rep= [[NSBitmapImageRep > alloc] > >initWithBitmapDataPlanes: NULL > >pixelsWide: [self size].width > >pixelsHigh: [self size].height > >bitsPerSample: 8 > >samplesPerPixel: 4 > >hasAlpha: NO > >isPlanar: NO > >colorSpaceName: NSDeviceCMYKColorSpace > >bytesPerRow: 0 > >bitsPerPixel: 0]; > >NSGraphicsContext *context= [NSGraphicsContext > graphicsContextWithBitmapImageRep: rep]; > >[NSGraphicsContext setCurrentContext: context]; > >[context setImageInterpolation: NSImageInterpolationHigh]; > >[self compositeToPoint: NSZeroPoint operation: > NSCompositeSourceOver]; > >[result addRepresentation: rep]; > >return result; > }___ > > 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/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: QuickLook returning small image
When requesting a thumbnail, it's up to the underlying plug-in to honor the requested size. If icon == NO, Quick Look will return the plug-in's image result as is. If icon == YES, Quick Look will force the requested size (because it adds icon decoration which should match the requested size) - so if you request a 512x512 icon, you should always get a 512x512 image. Many plug-in just use a low-resolution image stored in the file as a Quick Look thumbnail. It's totally acceptable but nowadays, "low-resolution" should be more toward 512x512 than 128x128. Previews are more complex (generally slower to generate) and are meant to be displayed mainly in Quick Look panel but they also appear in Cover Flow, Column view, Info window and, starting with SnowLeopard, in live previews in Finder's icons. -- Julien On Thu, Jan 13, 2011 at 10:11 AM, aglee wrote: > On Jan 13, 2011, at 01:06 PM, Kyle Sluder wrote: > Taking a while stab here: icon==YES? > > I get the same result (size-wise) whether icon is YES or NO. > > Joar pointed out off-list that Finder might be asking for a *preview* > rather than a *thumbnail*. I totally missed that distinction and I bet it's > the explanation. > > Thanks, > --Andy > > > ___ > > 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/jjalon%40gmail.com > > This email sent to jja...@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/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: NSNotFound
On 15 Jan 2011, at 18:43, Richard Somers wrote: > NSNotFound is formally defined as NSIntegerMax. But the framework methods > returning NSNotFound are typically typed NSUInteger. > > Is there a technical reason why NSNotFound is not defined as NSUIntegerMax? 1) Because it's usable for NSInteger too. 2) By looking at these values you're breaking the abstraction barrier. NSNotFound could have *any* value, and in fact its value could change from cocoa version to cocoa version. Stop looking! Bob___ 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
NSNotFound
NSNotFound is formally defined as NSIntegerMax. But the framework methods returning NSNotFound are typically typed NSUInteger. Is there a technical reason why NSNotFound is not defined as NSUIntegerMax? --Richard Somers ___ 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: Determining whether a dictionary is mutable or not
Le 15 janv. 2011 à 13:18, Tito Ciuro a écrit : > On Jan 15, 2011, at 1:04 PM, Ken Thomases wrote: > >> On Jan 15, 2011, at 5:38 AM, Tito Ciuro wrote: >> >>> On Jan 15, 2011, at 7:36 AM, Ken Ferry wrote: >>> I'm not sure this has been made clear: It is intentional that it is difficult to determine whether a dictionary is mutable. That's because you shouldn't do it. Whether a dictionary is mutable _to_you_ is a matter of what's in the header for the method you obtained it from. Suppose that some object keeps a mutable array as its internal state. It also has an accessor that lets you look at the array as an immutable array. If you introspect it and realize its mutable, is it safe to mutate? No! It's part of the object's internal state, you cannot just mess with it. It is unsafe in general to introspect mutability. -Ken Cocoa Frameworks >>> >>> It makes sense what you're saying because introspecting an object bypassing >>> its accessors would break encapsulation. From the client's perspective this >>> is very clear: use the methods provided and don't mess with the internals. >>> Roger that. >>> >>> However, how about the other way around? Say you have the same class you >>> mentioned. Internally, it has a mutable array which one can manipulate via >>> dedicated accessors. This object has an init method which accepts an array >>> as input. The client is (should?) be free to pass an immutable or mutable >>> array with values. I see at least two ways to honor this input and >>> initialize the object: >>> >>> 1) add the input objects to the internal array (i.e. - >>> (void)addObjectsFromArray:(NSArray *)otherArray) >>> 2) assign the mutable version of the input array to the internal array >>> (i.e. internalArray = [theInputArray mutableCopy]) >>> >>> In case of #2, (perhaps mistakenly) I was attempting to check whether it >>> was necessary to mutate an already mutable array. It just seemed like the >>> right thing to do: figure out whether the input array is mutable, if it >>> isn't then make it mutable. Then proceed to set the array as the object's >>> contents. However, since this init process is called once, perhaps it just >>> makes sense to always call mutableCopy and be done regardless of the input >>> type. Would this be the right approach perhaps? >>> >>> My main concern is how to deal with this mutability/non-mutability from the >>> inside, not the outside. >> >> You should copy any state which you need to be private. >> >> What if the code which calls your init method had, in fact, passed a mutable >> array? Why in the world would you want to make that your internal state? >> That would mean that your internal state is open to manipulation from the >> outside. The caller could, after the new object is initialized, modify its >> (the caller's) mutable array. They have thus unwittingly modified the >> internal state of the new object. >> >> And, again, if you had declared your initializer to take an immutable object >> as its parameter, why would you imagine that the caller would be OK with you >> mutating it? >> >> Sharing state is always fraught with difficulties. When it comes to value >> objects, including collections, you should default to making copies. Only >> retain them (and thus share state with the provider) after careful >> consideration of the close coupling that would result. And even then, it >> makes little sense to have the behavior be conditional on the object's >> mutability. >> >> I'll also point out that code which tries to determine the mutability and >> then takes one of two different paths is more complex and error-prone than >> code which just does one straightforward thing. >> >> Regards, >> Ken > > Ken, looks like I wasn't clear enough. In general (not only in this case) I > would not retain the array unless it was immutable. Otherwise, as you well > point out, retaining a mutable one would allow external clients manipulate > the array bypassing the accessors provided, thus breaking encapsulation. And as a side note. When you need an immutable copy, don't bother to try to optimize by copying if mutable and retaining if immutable, this is already what the copy implementation does. If properly implemented (and that is the case for the Cocoa framework), [myImmutableObject copy] should simply returns [self retain]; > I understand that my original approach was flawed because I really don't need > (nor should I care) about the original state of the collection being passed: > since the class allows the data to be manipulated via accessors, the inited > data, if provided, should be copied internally regardless of the array state > being passed. That would make a private copy of the data only accessible via > the class accessors. > > I was looking for a solution where there was not a problem. > > Best regards, -
iOS: 'Random' enable/disable
This may be obvious to people, but it took me a while to figure out, so I thought I'd post it in case it saves someone a bit of time. My application is structured with a split view controller as the main interface element. The root view has a primary controller, and a second one which is pushed onto it by means of clicking a toolbar button on the detail view. When the primary controller is active, the button is enabled; when the second one is active, the button is disabled. All is good, except The application also presents a full screen modal view according to a user request, with a button to dismiss it. Very rarely, when the modal view is dismissed and the second controller is active, the button to select the second controller shows as enabled. There is no code path in the app that allows that. The answer is: if there is a memory warning delivered while the split view controller is obscured, its controllers dump their views and reload them when needed. Of course they reload them in whatever state they're defined in the nib file. Lesson: assuming that nib settings are only for application start up is wrong. ___ 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: Mapping model
Hi Amy, It might be helpful if you could post an extract from your mapping method, or the whole thing if it's short. The last time I had a problem of this kind it turned out I had made a stupid error which only became obvious after I had left the problem for a week and then returned to it with 'fresh eyes'. Cheers Matt ___ 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: Determining whether a dictionary is mutable or not
On Jan 15, 2011, at 1:04 PM, Ken Thomases wrote: > On Jan 15, 2011, at 5:38 AM, Tito Ciuro wrote: > >> On Jan 15, 2011, at 7:36 AM, Ken Ferry wrote: >> >>> I'm not sure this has been made clear: It is intentional that it is >>> difficult to determine whether a dictionary is mutable. >>> >>> That's because you shouldn't do it. Whether a dictionary is mutable >>> _to_you_ is a matter of what's in the header for the method you obtained it >>> from. >>> >>> Suppose that some object keeps a mutable array as its internal state. It >>> also has an accessor that lets you look at the array as an immutable array. >>> If you introspect it and realize its mutable, is it safe to mutate? No! >>> It's part of the object's internal state, you cannot just mess with it. >>> >>> It is unsafe in general to introspect mutability. >>> >>> -Ken >>> Cocoa Frameworks >> >> It makes sense what you're saying because introspecting an object bypassing >> its accessors would break encapsulation. From the client's perspective this >> is very clear: use the methods provided and don't mess with the internals. >> Roger that. >> >> However, how about the other way around? Say you have the same class you >> mentioned. Internally, it has a mutable array which one can manipulate via >> dedicated accessors. This object has an init method which accepts an array >> as input. The client is (should?) be free to pass an immutable or mutable >> array with values. I see at least two ways to honor this input and >> initialize the object: >> >> 1) add the input objects to the internal array (i.e. - >> (void)addObjectsFromArray:(NSArray *)otherArray) >> 2) assign the mutable version of the input array to the internal array (i.e. >> internalArray = [theInputArray mutableCopy]) >> >> In case of #2, (perhaps mistakenly) I was attempting to check whether it was >> necessary to mutate an already mutable array. It just seemed like the right >> thing to do: figure out whether the input array is mutable, if it isn't then >> make it mutable. Then proceed to set the array as the object's contents. >> However, since this init process is called once, perhaps it just makes sense >> to always call mutableCopy and be done regardless of the input type. Would >> this be the right approach perhaps? >> >> My main concern is how to deal with this mutability/non-mutability from the >> inside, not the outside. > > You should copy any state which you need to be private. > > What if the code which calls your init method had, in fact, passed a mutable > array? Why in the world would you want to make that your internal state? > That would mean that your internal state is open to manipulation from the > outside. The caller could, after the new object is initialized, modify its > (the caller's) mutable array. They have thus unwittingly modified the > internal state of the new object. > > And, again, if you had declared your initializer to take an immutable object > as its parameter, why would you imagine that the caller would be OK with you > mutating it? > > Sharing state is always fraught with difficulties. When it comes to value > objects, including collections, you should default to making copies. Only > retain them (and thus share state with the provider) after careful > consideration of the close coupling that would result. And even then, it > makes little sense to have the behavior be conditional on the object's > mutability. > > I'll also point out that code which tries to determine the mutability and > then takes one of two different paths is more complex and error-prone than > code which just does one straightforward thing. > > Regards, > Ken Ken, looks like I wasn't clear enough. In general (not only in this case) I would not retain the array unless it was immutable. Otherwise, as you well point out, retaining a mutable one would allow external clients manipulate the array bypassing the accessors provided, thus breaking encapsulation. I understand that my original approach was flawed because I really don't need (nor should I care) about the original state of the collection being passed: since the class allows the data to be manipulated via accessors, the inited data, if provided, should be copied internally regardless of the array state being passed. That would make a private copy of the data only accessible via the class accessors. I was looking for a solution where there was not a problem. Best regards, -- Tito ___ 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: Determining whether a dictionary is mutable or not
On Jan 15, 2011, at 5:38 AM, Tito Ciuro wrote: > On Jan 15, 2011, at 7:36 AM, Ken Ferry wrote: > >> I'm not sure this has been made clear: It is intentional that it is >> difficult to determine whether a dictionary is mutable. >> >> That's because you shouldn't do it. Whether a dictionary is mutable >> _to_you_ is a matter of what's in the header for the method you obtained it >> from. >> >> Suppose that some object keeps a mutable array as its internal state. It >> also has an accessor that lets you look at the array as an immutable array. >> If you introspect it and realize its mutable, is it safe to mutate? No! >> It's part of the object's internal state, you cannot just mess with it. >> >> It is unsafe in general to introspect mutability. >> >> -Ken >> Cocoa Frameworks > > It makes sense what you're saying because introspecting an object bypassing > its accessors would break encapsulation. From the client's perspective this > is very clear: use the methods provided and don't mess with the internals. > Roger that. > > However, how about the other way around? Say you have the same class you > mentioned. Internally, it has a mutable array which one can manipulate via > dedicated accessors. This object has an init method which accepts an array as > input. The client is (should?) be free to pass an immutable or mutable array > with values. I see at least two ways to honor this input and initialize the > object: > > 1) add the input objects to the internal array (i.e. - > (void)addObjectsFromArray:(NSArray *)otherArray) > 2) assign the mutable version of the input array to the internal array (i.e. > internalArray = [theInputArray mutableCopy]) > > In case of #2, (perhaps mistakenly) I was attempting to check whether it was > necessary to mutate an already mutable array. It just seemed like the right > thing to do: figure out whether the input array is mutable, if it isn't then > make it mutable. Then proceed to set the array as the object's contents. > However, since this init process is called once, perhaps it just makes sense > to always call mutableCopy and be done regardless of the input type. Would > this be the right approach perhaps? > > My main concern is how to deal with this mutability/non-mutability from the > inside, not the outside. You should copy any state which you need to be private. What if the code which calls your init method had, in fact, passed a mutable array? Why in the world would you want to make that your internal state? That would mean that your internal state is open to manipulation from the outside. The caller could, after the new object is initialized, modify its (the caller's) mutable array. They have thus unwittingly modified the internal state of the new object. And, again, if you had declared your initializer to take an immutable object as its parameter, why would you imagine that the caller would be OK with you mutating it? Sharing state is always fraught with difficulties. When it comes to value objects, including collections, you should default to making copies. Only retain them (and thus share state with the provider) after careful consideration of the close coupling that would result. And even then, it makes little sense to have the behavior be conditional on the object's mutability. I'll also point out that code which tries to determine the mutability and then takes one of two different paths is more complex and error-prone than code which just does one straightforward thing. Regards, 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 arch...@mail-archive.com
Re: Determining whether a dictionary is mutable or not
Hi Ken, On Jan 15, 2011, at 7:36 AM, Ken Ferry wrote: > I'm not sure this has been made clear: It is intentional that it is > difficult to determine whether a dictionary is mutable. > > That's because you shouldn't do it. Whether a dictionary is mutable _to_you_ > is a matter of what's in the header for the method you obtained it from. > > Suppose that some object keeps a mutable array as its internal state. It > also has an accessor that lets you look at the array as an immutable array. > If you introspect it and realize its mutable, is it safe to mutate? No! > It's part of the object's internal state, you cannot just mess with it. > > It is unsafe in general to introspect mutability. > > -Ken > Cocoa Frameworks It makes sense what you're saying because introspecting an object bypassing its accessors would break encapsulation. From the client's perspective this is very clear: use the methods provided and don't mess with the internals. Roger that. However, how about the other way around? Say you have the same class you mentioned. Internally, it has a mutable array which one can manipulate via dedicated accessors. This object has an init method which accepts an array as input. The client is (should?) be free to pass an immutable or mutable array with values. I see at least two ways to honor this input and initialize the object: 1) add the input objects to the internal array (i.e. - (void)addObjectsFromArray:(NSArray *)otherArray) 2) assign the mutable version of the input array to the internal array (i.e. internalArray = [theInputArray mutableCopy]) In case of #2, (perhaps mistakenly) I was attempting to check whether it was necessary to mutate an already mutable array. It just seemed like the right thing to do: figure out whether the input array is mutable, if it isn't then make it mutable. Then proceed to set the array as the object's contents. However, since this init process is called once, perhaps it just makes sense to always call mutableCopy and be done regardless of the input type. Would this be the right approach perhaps? My main concern is how to deal with this mutability/non-mutability from the inside, not the outside. Thanks for the help, -- Tito ___ 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: NSSegmentedControl Label
On 14 Jan 2011, at 23:35, Kyle Sluder wrote: > On Fri, Jan 14, 2011 at 1:17 PM, Shawn Bakhtiar > wrote: >> Don't listen to the naysayers... You can do whatever you want. > > Sure, but koko asked how he could tell an NSSegmentedCell to draw its > image and its text. It's apparent that the authors of NSSegmentedCell > did not implement this, because why implement something that the HIG > authors are going to discourage people from using anyway? The HIG says - a segmented control can contain either icons or text, but not a mixture of both. The Segmented control programmin guide says - Although it is possible to set both a label and an image for a segment, a segment should have one or the other. It is supported in IB and NSSegmentedCell advertises the appropriate methods. Segmented controls often mix text and image based segments (the iCal day, week, month navigator). If you want to bend the HIG a bit you certainly can. Regards Jonathan Mitchell Developer Mugginsoft LLP http://www.mugginsoft.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/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: Mutable to-many relationship not observable
On Jan 14, 2011, at 5:23 AM, Remco Poelstra wrote: > I add the observer as follows: > [[DigiDevicesManager sharedDigiDevicesManager] addObserver:self > forKeyPath:@"digiDevices" options:NSKeyValueObservingOptionOld context:nil]; > It's superclass is NSObject and I did not disable automatic notifications. > > If mutate the array (from inside the observed object) with [self > {will/did}change..] then everything works fine. Which will/didChange... methods do you use, when you've tested the manual notifications? Also, what does your -observeValueForKeyPath:ofObject:change:context: method look like? My suspicion is that you're using will/didChangeValueForKey: and your observe... method is expecting the value of the NSKeyValueChangeKindKey to be NSKeyValueChangeSetting. Instead, the automatic notifications from the mutating indexed accessors is more akin to what's generated by will/didChange:valuesAtIndexes:forKey:, and NSKeyValueChangeKindKey will be one of NSKeyValueChangeInsertion, NSKeyValueChangeRemoval, or NSKeyValueChangeReplacement. Regards, 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 arch...@mail-archive.com