What are the best macros to use to know when compiling is for Mac OS X v.s. iOS?

2011-12-30 Thread lbland
hi-

What are the best macros to use to know when compiling is for Mac OS X v.s. iOS?

thanks!-

-lance

___

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 make a global contextual menu item

2011-12-30 Thread Adil Saleem
Hi,

Is it possible to create a global (which is available during all applications) 
contextual menu item ? If so, how can we create it.
It's just like a global hot-key, the only difference is that instead of a 
hot-key combination i want to have a menu item available.


Thanks
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: What are the best macros to use to know when compiling is for Mac OS X v.s. iOS?

2011-12-30 Thread KappA
Hello,

In short, it's probably best to use the TARGET_OS_IPHONE macro.

I used to use TARGET_OS_MAC when writing mac-specific code, but found that
even on iOS this was turned on making it a bit unreliable (or making you
redefine things in your own code)...

So it's probably a better idea to just stick to using the
TARGET_OS_IPHONE macro
as you can check it against both environments.

See this post:
http://stackoverflow.com/questions/3181321/which-conditional-compile-to-use-to-switch-between-mac-and-iphone-specific-code

Of course, if anyone on the list has a better solution, I'm all ears as
well.

Thanks,
Kappa

On Fri, Dec 30, 2011 at 11:44 AM, lbland lbl...@vvi.com wrote:

 hi-

 What are the best macros to use to know when compiling is for Mac OS X
 v.s. iOS?

 thanks!-

 -lance

 ___

 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/rejekted%40gmail.com

 This email sent to rejek...@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: What are the best macros to use to know when compiling is for Mac OS X v.s. iOS?

2011-12-30 Thread Conrad Shultz
http://developer.apple.com/library/mac/#documentation/developertools/conceptual/cross_development/Using/using.html

See the section on conditionally compiling for different SDKs.

(Sent from my iPad.)

--
Conrad Shultz

On Dec 30, 2011, at 8:44, lbland lbl...@vvi.com wrote:

 hi-
 
 What are the best macros to use to know when compiling is for Mac OS X v.s. 
 iOS?
 
 thanks!-
 
 -lance
 
 ___
 
 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/conrad%40synthetiqsolutions.com
 
 This email sent to con...@synthetiqsolutions.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: What are the best macros to use to know when compiling is for Mac OS X v.s. iOS?

2011-12-30 Thread lbland
hi-

On Dec 30, 2011, at 1:16 PM, Conrad Shultz wrote:

 http://developer.apple.com/library/mac/#documentation/developertools/conceptual/cross_development/Using/using.html

So...

__MAC_OS_X_VERSION_MAX_ALLOWED

is better than:

TARGET_OS_IPHONE

??

... ack! ack!

thanks!-

-lance

___

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 a global contextual menu item

2011-12-30 Thread Nick Zitzmann

On Dec 30, 2011, at 11:05 AM, Adil Saleem wrote:

 Hi,
 
 Is it possible to create a global (which is available during all 
 applications) contextual menu item ?

Not really, because there is a bit of fragmentation here. There are two 
different ways to make a CM item available in other applications:
1. By creating a Mac OS X software service
2. By using the CM plug-in API

The former will appear in CMs in Cocoa apps starting in Snow Leopard and later, 
if the user turned them on in the Keyboard preference pane. The latter will be 
loaded into all apps in Leopard and earlier, but will not be loaded into Cocoa 
apps starting in Snow Leopard and later, but I think they're still used by 
Carbon apps.

 If so, how can we create it.

Search the developer documentation for information on how to create a service. 
To make a CM plug-in, try searching for the ContextualMenuHelper source code.

Nick Zitzmann
http://www.chronosnet.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


Mouse up events ignored when sandboxing is turned on?

2011-12-30 Thread Nick Zitzmann
I tried searching and did not see anyone else having this problem. I tried 
turning on sandboxing in my LSUIElement application that normally does not 
activate, and found that, for some strange reason, the app receives mouse down 
events, but never receives mouse up events while tracking the mouse if the 
window was not active when it was clicked. Because the app never receives the 
event, and the app uses NSTableView (which does its own event tracking instead 
of using -mouseUp:), then NSTableView gets stuck waiting for something that's 
never going to happen.

With event tracing turned on, if I turn off sandboxing, or if I make the window 
active first, then it works correctly:

2011-12-30 12:30:05.974 MyApp[54520:b03] Received event: LMouseDown at: 
1818.0,158.0 time: 241491984611000 flags: 0x180 win: 16938 ctxt: 2c113 data: 
8176,1
2011-12-30 12:30:05.974 MyApp[54520:b03] In Application: NSEvent: 
type=LMouseDown loc=(78,937) time=241492.0 flags=0x180 win=0x0 winNum=16938 
ctxt=0x0 evNum=8176 click=1 buttonNumber=0 pressure=1
2011-12-30 12:30:05.974 MyApp[54520:b03] In Window: NSEvent: 
type=LMouseDown loc=(78,937) time=241492.0 flags=0x180 win=0x10143f3d0 
winNum=16938 ctxt=0x0 evNum=8176 click=1 buttonNumber=0 pressure=1
2011-12-30 12:30:05.976 MyApp[54520:b03] timeout = 62766937794.023842 seconds, 
mask = 1005c, dequeue = 1, mode = NSEventTrackingRunLoopMode
2011-12-30 12:30:05.980 MyApp[54520:b03] Received event: LMouseUp at: 
1818.0,158.0 time: 241491990904000 flags: 0x180 win: 16938 ctxt: 2c113 data: 
8176,1
2011-12-30 12:30:05.998 MyApp[54520:b03] timeout = 62766937794.001602 seconds, 
mask = , dequeue = 1, mode = kCFRunLoopDefaultMode

But once I turn on sandboxing, this is all I get before the application freezes:

2011-12-30 12:20:25.816 MyApp[54446:b03] Received event: LMouseDown at: 
1826.0,463.0 time: 24091180850 flags: 0x180 win: 16929 ctxt: 1e9df data: 
8155,1
2011-12-30 12:20:25.816 MyApp[54446:b03] In Application: NSEvent: 
type=LMouseDown loc=(86,331) time=240911.8 flags=0x180 win=0x0 winNum=16929 
ctxt=0x0 evNum=8155 click=1 buttonNumber=0 pressure=1
2011-12-30 12:20:25.816 MyApp[54446:b03] In Window: NSEvent: 
type=LMouseDown loc=(86,331) time=240911.8 flags=0x180 win=0x102959ae0 
winNum=16929 ctxt=0x0 evNum=8155 click=1 buttonNumber=0 pressure=1
2011-12-30 12:20:25.818 MyApp[54446:b03] timeout = 62766938374.181313 seconds, 
mask = 1005c, dequeue = 1, mode = NSEventTrackingRunLoopMode

The really strange thing is, this works as expected when sandboxing is turned 
off. It also works as expected if the window was active. But I can't ship the 
application with sandboxing on unless I can figure out how to fix or work 
around this. Has anyone seen this before, and if so, then how do I make this 
work?

Nick Zitzmann
http://www.chronosnet.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: AVPlayerLayer on Lion will only play one movie then zaps super layer

2011-12-30 Thread Michael Crawford
Little more information.

I created a custom view so that I could monitor -[NSView setWantsLayer:] and 
found that there are no calls change the layer backed state of the view to 
false.  The views layer simply disappears in that it is set to nil after the 
movie plays once.

-Michael

On Dec 29, 2011, at 9:07 AM, Michael Crawford wrote:

 I'm creating a simple menu-drive movie player and have run into a problem 
 with AVPlayerLayer.  The first time I attach a player with a movie the 
 playback is fine.  When a second movie is selected from the menu, I never 
 receive a status of -[AVPlayerLayer readyForDisplay] set to true.  If I 
 ignore this status the player will play but I only get audio playback (no 
 video).  Investigating the status of the view and associated layers involved 
 shows that the layer for the layer-backed (not hosted) view becomes nil after 
 playing the first movie.
 
 I have no idea how this is happening.  I've included the relevant snippets 
 below because I'm probably looking right at the problem and not seeing it.  
 Hopefully someone out that has a little more experience with AVFoundation and 
 can give me a clue.
 
 I'm using ARC.
 
 
 @interface JTVMovieViewController : NSViewController
 {
AVPlayerLayer* __strong playerLayer;
 }
 
 @property (assign) IBOutlet idJTVMoviewViewDelegate delegate;
 @property (strong) IBOutlet NSButton* homeButton;
 @property (strong) IBOutlet NSView* playerView;
 
 - (void)awakeFromNib
 {
playerLayer = [AVPlayerLayer layer];
playerLayer.frame = self.playerView.bounds;
playerLayer.videoGravity = AVLayerVideoGravityResizeAspect;
[playerLayer addObserver:self
  forKeyPath:kReadyForDisplayKey
 options:NSKeyValueObservingOptionNew 
 context:KVOPlayerLayerContext];
[self.playerView.layer addSublayer:playerLayer];
 }
 
 - (void)observeValueForKeyPath:(NSString*)keyPath
  ofObject:(id)object
change:(NSDictionary*)change
   context:(void*)context
 {
if ( context == KVOMoviePlaylistContext )
{
[self startPlayingNewPlayer:[self.moviePlaylist selection]];
}
else if ( context == KVOPlayerLayerContext )
{
NSLog(@Player layer %@ ready for display.,
  playerLayer.readyForDisplay ? @is : @is not);
 
if ( YES == playerLayer.readyForDisplay )
{
[playerLayer.player play];
}
}
 }
 
 - (void)startPlayingNewPlayer:(AVPlayer*)player
 {
[playerLayer setPlayer:player];
 
if ( YES == playerLayer.readyForDisplay )
{
[player play];
}
 
[self.delegate controllerDidBeginVideoPlayback:self];
 }
 
 - (void)stopPlayback
 {
[[playerLayer player] pause];
[[playerLayer player] seekToTime:kCMTimeZero]; // reset player
[playerLayer setPlayer:nil];
 }
 
 (lldb) po [self playerView]
 (NSView *) $2 = 0x00010bf83310 NSView: 0x10bf83310
 (lldb) po [[self playerView] layer]
 (id) $3 = 0x00010bf833d0 _NSViewBackingLayer:0x10bf833d0; position = 
 CGPoint (0 0); bounds = CGRect (0 0; 1920 1080); delegate = NSView: 
 0x10bf83310; backgroundFilters = (
 ); filters = (
 ); shadowColor = (null); anchorPoint = CGPoint (0 0)
 (lldb) po [[[self playerView] layer] sublayers]
 (id) $4 = 0x00010bf0 CALayerArray 0x10bf0(
 AVPlayerLayer:0x10bf84b50; position = CGPoint (960 540); bounds = CGRect (0 
 0; 1920 1080); 
 )
 
 (lldb) c
 Process 96211 resuming
 2011-12-29 08:35:33.421 JTVideoPlayer[96211:503] Player layer is ready for 
 display.
  here is where I stop playback from the UI
 2011-12-29 08:36:35.289 JTVideoPlayer[96211:503] Player layer is not ready 
 for display.
 (lldb) po [self playerView]
 (NSView *) $13 = 0x00010bf83310 NSView: 0x10bf83310
 (lldb) po [[self playerView] layer]
 (id) $14 = 0x nil
 (lldb) po [playerLayer superlayer]
 (id) $15 = 0x nil
 (lldb) 
 
 -Michael
 ___
 
 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/michaelacrawford%40me.com
 
 This email sent to michaelacrawf...@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/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: AVPlayerLayer on Lion will only play one movie then zaps super layer

2011-12-30 Thread Michael Crawford
I have a working solution.

In the end I had to recycle everything but the AVAsset instances.  Between each 
movie run, I must destroy the AVPlayerItem, the AVPlayer, the AVPlayerLayer, 
and the parent NSView since the backing layer that results from -[NSView 
setWantsLayer:] disappears without so much a whimper (no exceptions in 
Objective-C or C++ land), once the movie playback completes.

If this is mentioned in the programming guide for AVFoundation, I missed it 
completely.

Painful lesson.

-Michael

On Dec 30, 2011, at 9:44 PM, Michael Crawford wrote:

 Little more information.
 
 I created a custom view so that I could monitor -[NSView setWantsLayer:] and 
 found that there are no calls change the layer backed state of the view to 
 false.  The views layer simply disappears in that it is set to nil after the 
 movie plays once.
 
 -Michael
 
 On Dec 29, 2011, at 9:07 AM, Michael Crawford wrote:
 
 I'm creating a simple menu-drive movie player and have run into a problem 
 with AVPlayerLayer.  The first time I attach a player with a movie the 
 playback is fine.  When a second movie is selected from the menu, I never 
 receive a status of -[AVPlayerLayer readyForDisplay] set to true.  If I 
 ignore this status the player will play but I only get audio playback (no 
 video).  Investigating the status of the view and associated layers involved 
 shows that the layer for the layer-backed (not hosted) view becomes nil 
 after playing the first movie.
 
 I have no idea how this is happening.  I've included the relevant snippets 
 below because I'm probably looking right at the problem and not seeing it.  
 Hopefully someone out that has a little more experience with AVFoundation 
 and can give me a clue.
 
 I'm using ARC.
 
 
 @interface JTVMovieViewController : NSViewController
 {
   AVPlayerLayer* __strong playerLayer;
 }
 
 @property (assign) IBOutlet idJTVMoviewViewDelegate delegate;
 @property (strong) IBOutlet NSButton* homeButton;
 @property (strong) IBOutlet NSView* playerView;
 
 - (void)awakeFromNib
 {
   playerLayer = [AVPlayerLayer layer];
   playerLayer.frame = self.playerView.bounds;
   playerLayer.videoGravity = AVLayerVideoGravityResizeAspect;
   [playerLayer addObserver:self
 forKeyPath:kReadyForDisplayKey
options:NSKeyValueObservingOptionNew 
context:KVOPlayerLayerContext];
   [self.playerView.layer addSublayer:playerLayer];
 }
 
 - (void)observeValueForKeyPath:(NSString*)keyPath
 ofObject:(id)object
   change:(NSDictionary*)change
  context:(void*)context
 {
   if ( context == KVOMoviePlaylistContext )
   {
   [self startPlayingNewPlayer:[self.moviePlaylist selection]];
   }
   else if ( context == KVOPlayerLayerContext )
   {
   NSLog(@Player layer %@ ready for display.,
 playerLayer.readyForDisplay ? @is : @is not);
 
   if ( YES == playerLayer.readyForDisplay )
   {
   [playerLayer.player play];
   }
   }
 }
 
 - (void)startPlayingNewPlayer:(AVPlayer*)player
 {
   [playerLayer setPlayer:player];
 
   if ( YES == playerLayer.readyForDisplay )
   {
   [player play];
   }
 
   [self.delegate controllerDidBeginVideoPlayback:self];
 }
 
 - (void)stopPlayback
 {
   [[playerLayer player] pause];
   [[playerLayer player] seekToTime:kCMTimeZero]; // reset player
   [playerLayer setPlayer:nil];
 }
 
 (lldb) po [self playerView]
 (NSView *) $2 = 0x00010bf83310 NSView: 0x10bf83310
 (lldb) po [[self playerView] layer]
 (id) $3 = 0x00010bf833d0 _NSViewBackingLayer:0x10bf833d0; position = 
 CGPoint (0 0); bounds = CGRect (0 0; 1920 1080); delegate = NSView: 
 0x10bf83310; backgroundFilters = (
 ); filters = (
 ); shadowColor = (null); anchorPoint = CGPoint (0 0)
 (lldb) po [[[self playerView] layer] sublayers]
 (id) $4 = 0x00010bf0 CALayerArray 0x10bf0(
 AVPlayerLayer:0x10bf84b50; position = CGPoint (960 540); bounds = CGRect (0 
 0; 1920 1080); 
 )
 
 (lldb) c
 Process 96211 resuming
 2011-12-29 08:35:33.421 JTVideoPlayer[96211:503] Player layer is ready for 
 display.
  here is where I stop playback from the UI
 2011-12-29 08:36:35.289 JTVideoPlayer[96211:503] Player layer is not ready 
 for display.
 (lldb) po [self playerView]
 (NSView *) $13 = 0x00010bf83310 NSView: 0x10bf83310
 (lldb) po [[self playerView] layer]
 (id) $14 = 0x nil
 (lldb) po [playerLayer superlayer]
 (id) $15 = 0x nil
 (lldb) 
 
 -Michael
 ___
 
 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/michaelacrawford%40me.com
 
 This email sent to michaelacrawf...@me.com
 
 ___
 
 Cocoa-dev mailing 

Re: viewWillAppear not called with UINavigationController containment

2011-12-30 Thread Curt Clifton
On Dec 27, 2011, at 5:51 AM, Roland King wrote:

   // tell each of the controllers we're adding that they are being added 
 and prepare the ones being removed for removal
   for( UIViewController *controller in appearingControllers )
   [ self addChildViewController:controller ];
   [ disappearingControllers makeObjectsPerformSelector:@selector( 
 willMoveToParentViewController: ) withObject:nil ];
 
   [ appearingControllers makeObjectsPerformSelector:@selector( 
 didMoveToParentViewController: ) withObject:self ];
   [ disappearingControllers makeObjectsPerformSelector:@selector( 
 removeFromParentViewController ) ];
 
   // get the views in order
   NSArray *newViews = [ viewControllers valueForKey:@view ];
 
   // views then added to our view

That looks about like what we're doing successfully. The only difference I see 
is that we're adding/removing views between the paired view controller calls. 
In the example below, both self and slice are UIViewController subclasses.

// removing

[slice willMoveToParentViewController:nil];
if ([slice isViewLoaded]  slice.view.superview == view)
[slice.view removeFromSuperview];
[slice removeFromParentViewController];

...

// adding

[self addChildViewController:slice];
[view addSubview:slice.view];
[slice didMoveToParentViewController:self];

HTH.

Cheers,

Curt

___

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 the RSS Feed of a site

2011-12-30 Thread Kevin Vavelin
Hi everyone !
I develop an application for my uni (SUPINFO), and i need to get the RSS feed 
of every labs they have. I don't know if i have to use NSURL or if we have 
something better in CocoaTouch 'cause my application is for iPhone.

Can anyone help me ?

Thanks a lot in advance.___

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


dns_sd and double nat

2011-12-30 Thread Curtis Jones
I've been researching this issue for a while and can't find a solution - I'm 
hoping someone here can help, or at least confirm my fate.

I need to perform port mapping (UPnP / NAT-PMP) from within a Cocoa 
application. I've found several open source libraries in addition to dns_sd 
that can accomplish this.

At the moment I'm not able to use dns_sd because it complains in double-nat'ed 
environments. I don't expect it to perform port mapping on the outer of the 
two NAT's; only the closer one; the default gateway. But because it detects 
the double-nat, it refuses to proceed. I'd really like to be able to tell it 
that I understand it's objections, but I'd really like it to proceed anyway.

I dug into the Bonjour source code and found the offending line of code, but 
unless I misunderstood, it looks nothing short of replacing mDNSResponder with 
a new build would resolve the issue - which isn't an acceptable course of 
action for me.

Is there any way to make Bonjour ignore its double-nat objections?

Left field here: would it be crazy to include an mDNSResponder build with the 
application? Can multiple instances run without bothering each other?

Thanks for your help.

--
Curtis Jones
curtis.jo...@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: How to update preview in NSPrintPanel?

2011-12-30 Thread Luc Van Bogaert

On 26 Dec 2011, at 02:44, Quincey Morris wrote:

 On Dec 25, 2011, at 14:05 , Luc Van Bogaert wrote:
 
 I'm adding a custom user setting to a NSPrintPanel by adding an accessory 
 view controller for a view that contains just one control (a checkbox) and 
 which is loaded from a nib file. The checkbox's value has a binding to the 
 view controller's representedObject.printSettings.checkboxvalue keypath. 
 (The representedObject is a NSPrintInfo object).
 
 I have been able to verify that this binding works correctly.
 
 One thing I haven't gotten to work yet, is to automatically update the 
 preview in the print panel when I chance the state of the checkbox. The 
 preview updates itself correctly when I change one of the built-in 
 settings, and it even correctly represents my own custom setting. But, how 
 can I trigger an automatic update when I just change my own custom setting? 
 
 I assume I should implement the  keyPathsForValuesAffectingPreview 
 protocol method in my accessory view controller, which I did, but so far 
 without success. Here's my implementation:
 
 - (NSSet *)keyPathsForValuesAffectingPreview
 {
return [NSSet setWithObjects:
[NSString 
 stringWithFormat:@representedObject.printSettings.checkboxvalue],
nil];
 }
 
 The immediate problem is that binding through a mutable dictionary like this 
 (printSettings) isn't KVO compliant. Properties with values that are mutable 
 objects are generally a problem for KVC/KVO, since it's really designed 
 around the idea that property values are immutable objects like NSString and 
 NSNumber.
 
 The secondary problem is that you're trying, simultaneously, to use 2 
 different ways to get the accessory panel to update automatically, and both 
 ways aren't working. If your binding was working, then 
 'keyPathsForValuesAffectingPreview' wouldn't be necessary. If you had a 
 working 'keyPathsForValuesAffectingPreview', then I suspect you'd find that 
 the checkbox still wouldn't change -- not because it wasn't updating, but 
 because the change wouldn't be propagated.
 
 I think the simplest approach is to add a checkboxvalue property to the 
 view controller, bind the checkbox to File's Owner.checkboxvalue, and then 
 make this property KVO-compliant:
 
 1. The getter can just return 
 self.representedObject.printSettings.checkboxvalue.
 
 2. The setter can just change 
 self.representedObject.printSettings.checkboxvalue.
 
 3. The view controller needs to keep track of the current print settings 
 object by observing its own representedObject.printSettings keypath.
 
 4. Whenever the print settings object changes, the view controller needs to 
 observe the checkboxvalue key of the new object and stop observing the same 
 key of the old object.
 
 5. Whenever the observed checkboxvalue changes, transfer the new value to 
 self.checkboxvalue. Note that this starts a messaging loop between the 2 
 checkboxvalue properties, but the KVO machinery prevents this from being an 
 infinite loop. You can short circuit the remaining minor duplication of 
 effort, if you wish, by having your setter check the dictionary property 
 value to avoid re-setting it to the existing value.
 
 

I'm afraid I still haven't got this nailed down completely. Please try to 
follow the below explanations of what I've been doing, and correct me where 
nesseccary. Thanks!

At this point, I have only implemented the first two points of your above list. 
Using the checkbox in my accessory view, I can now have the print panel preview 
update itself according the checkbox state, so that's working fine. However, ...

I haven't been able to set the checkbox's state to ON, when opening the print 
panel. I've tried creating the view controller first and then sending 
[viewcontroller setCheckBoxValue:YES], but that doesn't seem to work, so I 
suspect I'm still missing some important stuff (I assume point 3 and 
following..)

These are my current accessor methods:

- (BOOL)checkBoxValue
{
return self representedObject] printSettings] 
valueForKey:kCheckBoxValue] boolValue];
}

- (void)setCheckBoxValue:(BOOL)checkBoxValue
{
[[[self representedObject] printSettings] setValue:[NSNumber 
numberWithBool:checkBoxValue] 
forKey:kCheckBoxValue];
}


** Point 3: why exactly would this be required?

I assume I could add this in -awakefromnib:

[self addObserver:self 
   forKeyPath:@representedObject.printSettings 
  options:NSKeyValueObservingOptionOld | 
NSKeyValueObservingOptionNew 
  context:self];

and implement this in the view controller :

- (void)observeValueForKeyPath:(NSString *)keyPath 
  ofObject:(id)object 
change:(NSDictionary *)change
   context:(void *)context
{
if ([keyPath isEqualToString:@representedObject.printSettings]) {
NSLog(@%@, @the printSettings object has changed);
}
}


Re: How to update preview in NSPrintPanel?

2011-12-30 Thread Quincey Morris
On Dec 28, 2011, at 05:05 , Luc Van Bogaert wrote:

 I haven't been able to set the checkbox's state to ON, when opening the print 
 panel. I've tried creating the view controller first and then sending 
 [viewcontroller setCheckBoxValue:YES], but that doesn't seem to work, so I 
 suspect I'm still missing some important stuff (I assume point 3 and 
 following..)

Parts 3-5 are the machinery that transfers the value from the printSettings 
dictionary to the view controller property. This is only necessary if you have 
code that sets the dictionary value directly; if you only use the initial 
dictionary value (i.e. the value at the time the checkbox is loaded from its 
nib) and/or only use 'setCheckboxValue' in the the view controller, you 
shouldn't need 3-5.

So, I'm guessing that the above problem is a small timing issue about when 
things happen. The first step would be to check each individual step of setting 
the initial YES. (I'd use the debugger, but you can NSLog instead if you 
prefer.) Check that view controller really isn't nil. In the setter, check that 
representedObject and printSettings really aren't nil. After returning from the 
setter, check immediately that the getter returns the value you just set. Etc.

 These are my current accessor methods:
 
 - (BOOL)checkBoxValue
 {
 return self representedObject] printSettings] 
 valueForKey:kCheckBoxValue] boolValue];
 }
 
 - (void)setCheckBoxValue:(BOOL)checkBoxValue
 {
 [[[self representedObject] printSettings] setValue:[NSNumber 
 numberWithBool:checkBoxValue] 
 forKey:kCheckBoxValue];
 }
 
 
 ** Point 3: why exactly would this be required?

As I said already, you may not need 3-5 after all, but for completeness:

 I assume I could add this in -awakefromnib:
 
 [self addObserver:self 
forKeyPath:@representedObject.printSettings 
   options:NSKeyValueObservingOptionOld | 
 NSKeyValueObservingOptionNew 
   context:self];
 
 and implement this in the view controller :
 
 - (void)observeValueForKeyPath:(NSString *)keyPath 
   ofObject:(id)object 
 change:(NSDictionary *)change
context:(void *)context
 {
 if ([keyPath isEqualToString:@representedObject.printSettings]) {
 NSLog(@%@, @the printSettings object has changed);

I meant keep track of in the sense of store in an ivar, so:

currentPrintSettings = self representedObject] printSettings];

 }
 }
 
 But, I'm not sure where to remove 'self' as an observer. I'm doubting that 
 -dealloc is the right place for thisn but for now I have implemented it 
 there:  
 
 [self removeObserver:self 
   forKeyPath:@representedObject.printSettings];
 

This seems like the right place to do it.

 
 
 ** Point 4: this is even getting a little harder for me…
 

Adding the next piece, the above becomes:

if ([keyPath isEqualToString:@representedObject.printSettings]  
currentPrintSettings != [[self representedObject] printSettings]) {
[currentPrintSettings removeObserver: self forKeyPath: kCheckboxValue];
currentPrintSettings = [[self representedObject] printSettings];
[currentPrintSettings addObserver: self forKeyPath: kCheckBoxValue 
options: 0 context: self];
}


 Where should I remove self as an observer for the first print settings 
 object? Also in -dealloc ?

Yup, but you're removing the observer from 'currentPrintSettings'.

 
 ** Point 5: now I'm definitely loosing track ;-)

Adding the last piece:

} else if ([keyPath isEqualToString:kCheckBoxValue]) {
[self setCheckBoxValue: [self checkBoxValue]]; // the point being to 
trigger a KVO notification of the view's property
}

and changing the setter to short-circuit the loop:

- (void)setCheckBoxValue:(BOOL)checkBoxValue
{
if (!checkBoxValue != ![self checkBoxValue])) // (the right way to 
compare 2 BOOLs)
[[[self representedObject] printSettings] setValue:[NSNumber 
numberWithBool:checkBoxValue] 
forKey:kCheckBoxValue];
}

(Code written in mail, so I may have overlooked some details.)


___

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: viewWillAppear not called with UINavigationController containment

2011-12-30 Thread Zac Bowling
I created a sample project this year at WWDC to help diagnose UIViewController 
containment that may be useful.  

https://github.com/zbowling/ContainerTest

It hosts a view controllers and just NSLogs a ton of events that happen like 
viewWillAppear and rotation calls. I wrote it to track down a bug with rotation 
callbacks with view controller containment. 

Should help I hope.  

-- 
Zac Bowling


___

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


Static variables reset inside CFPlugin code

2011-12-30 Thread Grandinetti Philip
I'm loading and creating a CFplugin using Core Foundation and running into a 
strange behavior where all the static variables defined throughout my code get 
reset to their initialization values when running code inside plugin. For 
example, I define a static variable and functions in a file foo.c

static int foo = 0;
void setFoo(void) { foo = 42;}
void printFoo(void) {fprintf(stderr, foo is %d\n,foo);}
then I install and call the plugin code using

printFoo();// - prints 0
setFoo();  // - sets foo to 42
printFoo();// - prints 42

PluginInterfaceRef *iunknown = CFPlugInInstanceCreate(kCFAllocatorDefault, 
factoryID, kMyPluginTypeUUID);

printFoo();   // - prints 42
which looks okay, but inside the factory function, called by 
CFPlugInInstanceCreate,...

void *myFactory(CFAllocatorRef allocator, CFUUIDRef typeID) {
if(!CFEqual(typeID, kMyPluginTypeUUID)) return NULL;
MyPluginRef result = MyPluginCreate(typeID);
printFoo();   // - prints 0  ??
return result;
}
printFoo() returns 0, and not 42.

I'm using Xcode 4.2.1, and all the functions appear to be running in the main 
thread.

Any ideas why this is happening, and suggestions for making static variables 
available inside the plugin?


___

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: RaiseMan Exception

2011-12-30 Thread Tommy Grav

On Dec 29, 2011, at 4:42 PM, Ken Thomases wrote:

 On Dec 29, 2011, at 3:14 PM, Todd Heberlein wrote:
 
 (1) Add one Person object
 (2) wait 30-60 seconds.
 
 crash.
 
 No clicking on the Edit menu. No clicking away to another application.
 
 On Dec 29, 2011, at 2:52 PM, Todd Heberlein wrote:
 
 The exception is from the default template code:
 
  - (NSData *)dataOfType:(NSString *)typeName error:(NSError **)outError
 
 The frames stack is:
  0 __pthread_kill
  9 _objc_exception_destructor
  10 -[RMDocument dataOfType:error:]  -- exception 
 thrown here
  11 -[NSDocument writeToURL:ofType:error:]
  39 NSApplicationMain
  40 main
 
 Any ideas why I'm getting the exception?
 
 Any idea why [NSDocument writeToURL:ofType:error:] is being called?
 
 This is probably Lion's Auto Save feature triggering a save because the 
 document has been dirtied.  As Jens pointed out, you haven't shown the code, 
 but I suppose that part may not be done yet if the tutorial you're following 
 hasn't gotten to that point, yet.
 
 The book may need to be updated for Lion.  You can probably fix things by 
 just returning nil from -dataOfType:error:.
 
 Regards,
 Ken

I did that example some weeks ago and got a similar error. If I remember 
correctly there is an outlet to the undo/redo part that you have not set right 
that is causing the error (although it looks like it is an autosave error).

Cheers
  Tommy



___

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