Re: Drawing same text and graphics in different CGContextRef

2023-09-22 Thread David Duncan via Cocoa-dev


> On Sep 22, 2023, at 12:44 PM, JPH  wrote:
> 
> Hi David,
> 
> Trying  to understand the mechanism  you suggest  ( I am not familiar with 
> the concept of context pushing - poping :(I   )
> 
> NSGraphicsContext  * newcontext= 
> [NSGraphicsContex  
> graphicsContextWithCGContext:theprintContext flipped:YES] // theprintContext 
> obtained from PMSessionGetCGGraphicsContext(printSession, )
> [newcontext saveGraphicsState]; //Saves the current graphics state and 
> creates a new graphics state on the top of the stack.
>myDrawMethod( newcontext.CGContext)
> [NSGraphicsContext  
> restoreGraphicsState;]
> 
> Is this correct ?

You want NSGraphicsContext.currentContext (I had expected API similar to UIKit 
without looking it up, but it looks like you just have to save the current 
context, set your current context, and restore it afterwards).

> 
> All the best
> JP
> 
> 
> 
> 
> 
> 
>  
>a  graphic context created by myself  ( hence not the supplied on  by the 
> printing framework ) 
> 
>> Le 22 sept. 2023 à 17:59, David Duncan > <mailto:david.dun...@apple.com>> a écrit :
>> 
>> 
>> 
>>> On Sep 22, 2023, at 11:12 AM, JPH via Cocoa-dev >> <mailto:cocoa-dev@lists.apple.com>> wrote:
>>> 
>>> I am facing the following  problems  in drawing text  and graphics in  
>>> CGContextRef of an NSview and Printing framework:
>>> 
>>> 1) drawing text  using:  [finalString drawInRect:textBox 
>>> withAttributes:attributes];
>>> Works nicely in my sub-classed NSViews  in  a  CGContextRef obtained in  
>>> the drawRect :  method with   CGContextRef viewCtx= [[NSGraphicsContext 
>>> currentContext] CGContext];
>>> But draws nothing in a print context obtained  
>>> PMSessionGetCGGraphicsContext(printSession, ); //( geometry is 
>>> perfectly previewed,Pdf’ed and printed except texts .. )
>>> 
>>> 2) filling a bezier path with a pattern Color
>>> 
>>> NSImage* nsPatImage= [[NSImage alloc] initWithCGImage:cgPatImage 
>>> size:NSZeroSize];
>>> NSColor* patternColor= [NSColor colorWithPatternImage:nsPatImage];
>>> [patternColor setFill];
>>> [bezierPath fill];
>>> 
>>> Works like a charm in the graphic context of NSView  and print nothing in a 
>>> print context.
>>> 
>>> I suspect this has something to do with the notion of  « Current context » 
>>> , as the context in NSView is explicitly the « currentContext »
>>> But not sure if  the printing  context is the « current  one » in the usual 
>>> print sequence ;
>> 
>> Correct. The current context is an AppKit concept, and you are working below 
>> AppKit in this code sequence – so you need to ensure the context is made 
>> current yourself. So you need to create an NSGraphicsContext, push it, and 
>> pop it, around your drawing code that relies on the current context. Since 
>> you pass the CGContext to myDrawMethod:, you could do this inside that 
>> method.
>> 
>>> err=   PMSessionBeginPageNoDialog(printSession, format )
>>> ctx =  PMSessionGetCGGraphicsContext(printSession, )
>>> [myDrawMethode: ctx] // [finalString drawInRect:textBox 
>>> withAttributes:attributes]; draws nothing in the printing context 
>>> PMSessionEndPageNoDialog(printSession);
>>> 
>>> I would appreciate any advice or suggestion regarding these points
>>> King regards
>>> JP
>>> 
>>> 
>>> 
>>> 
>>> 
>>> ___
>>> 
>>> Cocoa-dev mailing list (Cocoa-dev@lists.apple.com 
>>> <mailto: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 
>>> <http://lists.apple.com/>
>>> 
>>> Help/Unsubscribe/Update your Subscription:
>>> https://lists.apple.com/mailman/options/cocoa-dev/david.duncan%40apple.com
>>> 
>>> This email sent to david.dun...@apple.com
>> 
> 

___

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

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

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

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


Re: Drawing same text and graphics in different CGContextRef

2023-09-22 Thread David Duncan via Cocoa-dev


> On Sep 22, 2023, at 11:12 AM, JPH via Cocoa-dev  
> wrote:
> 
> I am facing the following  problems  in drawing text  and graphics in  
> CGContextRef of an NSview and Printing framework:
> 
> 1) drawing text  using:  [finalString drawInRect:textBox 
> withAttributes:attributes];
> Works nicely in my sub-classed NSViews  in  a  CGContextRef obtained in  the 
> drawRect :  method with   CGContextRef viewCtx= [[NSGraphicsContext 
> currentContext] CGContext];
> But draws nothing in a print context obtained  
> PMSessionGetCGGraphicsContext(printSession, ); //( geometry is perfectly 
> previewed,Pdf’ed and printed except texts .. )
> 
> 2) filling a bezier path with a pattern Color
> 
> NSImage* nsPatImage= [[NSImage alloc] initWithCGImage:cgPatImage 
> size:NSZeroSize];
> NSColor* patternColor= [NSColor colorWithPatternImage:nsPatImage];
> [patternColor setFill];
> [bezierPath fill];
> 
> Works like a charm in the graphic context of NSView  and print nothing in a 
> print context.
> 
> I suspect this has something to do with the notion of  « Current context » , 
> as the context in NSView is explicitly the « currentContext »
> But not sure if  the printing  context is the « current  one » in the usual 
> print sequence ;

Correct. The current context is an AppKit concept, and you are working below 
AppKit in this code sequence – so you need to ensure the context is made 
current yourself. So you need to create an NSGraphicsContext, push it, and pop 
it, around your drawing code that relies on the current context. Since you pass 
the CGContext to myDrawMethod:, you could do this inside that method.

> err=   PMSessionBeginPageNoDialog(printSession, format )
> ctx =  PMSessionGetCGGraphicsContext(printSession, )
> [myDrawMethode: ctx] // [finalString drawInRect:textBox 
> withAttributes:attributes]; draws nothing in the printing context 
> PMSessionEndPageNoDialog(printSession);
> 
> I would appreciate any advice or suggestion regarding these points
> King regards
> JP
> 
> 
> 
> 
> 
> ___
> 
> Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)
> 
> Please do not post admin requests or moderator comments to the list.
> Contact the moderators at cocoa-dev-admins(at)lists.apple.com
> 
> Help/Unsubscribe/Update your Subscription:
> https://lists.apple.com/mailman/options/cocoa-dev/david.duncan%40apple.com
> 
> This email sent to david.dun...@apple.com

___

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

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

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

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


Re: CALayer shadows and CGContext clip rect

2023-01-03 Thread David Duncan via Cocoa-dev
While you may have solved your problem, your general approach is not one that 
would be recommended – CALayers are not meant to be drawn into a context, but 
rather added to a layer tree to be rendered by the system. For what you are 
doing you would likely have less issue and better performance drawing your 
shadows with AppKit or CoreGraphics directly instead of using CoreAnimation as 
an intermediary.

> On Jan 1, 2023, at 7:23 PM, David Young via Cocoa-dev 
>  wrote:
> 
> On Thu, Dec 15, 2022 at 08:59:24PM -0600, David Young via Cocoa-dev wrote:
>> Is it possible that a CGContext clip path will clip a shadow cast inside
>> the clip path, if the CALayer whose content cast the shadow is fully
>> outside of the clip path?  Any ideas why?
> 
> Just in case it helps somebody in the future: the answer seems to be
> "yes."  If I enlarge the frame of my sublayer (the layer whose drawn
> content actually casts the shadow) to enclose the entire shadow, then
> the shadow will not be clipped, even though I have set the shadow offset
> & opacity & radius on the superlayer.
> 
> I tried leaving the frame of the inner CALayer alone while enlarging
> the frame of the superlayer so that it enclosed the whole shadow.  That
> didn't help: the shadow was still clipped.
> 
> Dave
> 
> -- 
> David Young
> dyo...@pobox.comUrbana, IL(217) 721-9981
> ___
> 
> Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)
> 
> Please do not post admin requests or moderator comments to the list.
> Contact the moderators at cocoa-dev-admins(at)lists.apple.com
> 
> Help/Unsubscribe/Update your Subscription:
> https://lists.apple.com/mailman/options/cocoa-dev/david.duncan%40apple.com
> 
> This email sent to david.dun...@apple.com

___

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

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

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

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


Re: iOS UINavigation background removal.

2022-01-28 Thread David Duncan via Cocoa-dev


> On Jan 28, 2022, at 11:50 AM, Alex Zavatone  wrote:
> 
> Awesome.  Thank you, David.  
> 
> 
> I stumbled across this too while going through Apple documentation.  What’s 
> scary is that I have no idea why it works.
> 
> self.navigationController!.navigationBar.barStyle = .default
> self.navigationController!.navigationBar.isTranslucent = false
> self.navigationController!.navigationBar.titleTextAttributes = 
> [.foregroundColor: UIColor.white]
>   self.navigationController?.navigationBar.backgroundImage(for: .default)
> navigationController?.navigationBar.setBackgroundImage(UIImage(), 
> for: .default)

This stuff is pre-iOS 13 appearance customization. Using the new stuff will 
disable it.

> 
> let navBar = self.navigationController!.navigationBar
> let standardAppearance = UINavigationBarAppearance()
> standardAppearance.configureWithOpaqueBackground()
> standardAppearance.backgroundImage = UIImage()
> 
> navBar.standardAppearance = standardAppearance
> navBar.scrollEdgeAppearance = standardAppearance

With iOS 13 the navigation bar now has multiple appearance states. The 
scrollEdgeAppearance is when your bar is at the edge of a scroll view (top for 
a navigation bar, bottom for tab & toolbar). This configures the bar to use the 
same appearance state (in this case, a solid color background, using 
UIColor.systemBackgroundColor). In context the setting of backgroundImage 
doesn’t do anything (it defaults to nil and empty images have identical 
behavior).

By setting standardAppearance == scrollEdgeAppearance it in turn disables the 
“bar becomes transparent at the top” behavior introduced for large titles in 
iOS 13 and extended to all bar in iOS 15.

> 
> 
> Thanks again David.  You’re on my Christmas list.
> 
> Alex Zavatone
> 
>> On Jan 28, 2022, at 1:30 PM, David Duncan > <mailto:david.dun...@apple.com>> wrote:
>> 
>> UINavigationBarAppearance *appearance = [UINavigationBarAppearance new];
>> [appearance configureWithTransparentBackground];
>> navigationItem.standardAppearance = appearance;
>> 
>> Thats the simplest per-item way to do it. This does imply you adopt the new 
>> appearance APIs introduced in iOS 13.
>> 
>>> On Jan 28, 2022, at 11:03 AM, Alex Zavatone via Cocoa-dev 
>>> mailto:cocoa-dev@lists.apple.com>> wrote:
>>> 
>>> Hi there.  I’m in the middle of trying to find out how the hell to remove a 
>>> background from a UINavigationBar and it’s not easy.  You’d think that you 
>>> could get a UInavigationBar.navigationitem.background and remove it from a 
>>> superview or set its alpha to 0, but it’s not that easy.
>>> 
>>> Does anyone have any clue how to get a reference to the background once it 
>>> has been set so that it can be set to 0 alpha or removed from the 
>>> superview?  
>>> 
>>> Thanks in advance and happy Friday.  Apple sure has ways to make things 
>>> that should be simple very obscure and extremely deifficult to handle.  
>>> 
>>> Cheers, 
>>> Alex Zavatone
>>> ___
>>> 
>>> Cocoa-dev mailing list (Cocoa-dev@lists.apple.com 
>>> <mailto: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 
>>> <http://lists.apple.com/>
>>> 
>>> Help/Unsubscribe/Update your Subscription:
>>> https://lists.apple.com/mailman/options/cocoa-dev/david.duncan%40apple.com 
>>> <https://lists.apple.com/mailman/options/cocoa-dev/david.duncan%40apple.com>
>>> 
>>> This email sent to david.dun...@apple.com
>> 
> 

___

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

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

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

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


Re: iOS UINavigation background removal.

2022-01-28 Thread David Duncan via Cocoa-dev
UINavigationBarAppearance *appearance = [UINavigationBarAppearance new];
[appearance configureWithTransparentBackground];
navigationItem.standardAppearance = appearance;

Thats the simplest per-item way to do it. This does imply you adopt the new 
appearance APIs introduced in iOS 13.

> On Jan 28, 2022, at 11:03 AM, Alex Zavatone via Cocoa-dev 
>  wrote:
> 
> Hi there.  I’m in the middle of trying to find out how the hell to remove a 
> background from a UINavigationBar and it’s not easy.  You’d think that you 
> could get a UInavigationBar.navigationitem.background and remove it from a 
> superview or set its alpha to 0, but it’s not that easy.
> 
> Does anyone have any clue how to get a reference to the background once it 
> has been set so that it can be set to 0 alpha or removed from the superview?  
> 
> Thanks in advance and happy Friday.  Apple sure has ways to make things that 
> should be simple very obscure and extremely deifficult to handle.  
> 
> Cheers, 
> Alex Zavatone
> ___
> 
> Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)
> 
> Please do not post admin requests or moderator comments to the list.
> Contact the moderators at cocoa-dev-admins(at)lists.apple.com
> 
> Help/Unsubscribe/Update your Subscription:
> https://lists.apple.com/mailman/options/cocoa-dev/david.duncan%40apple.com
> 
> This email sent to david.dun...@apple.com

___

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

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

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

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


Re: Accessibility UIContentSizeCategory or current accessibility font setting

2021-10-18 Thread David Duncan via Cocoa-dev


> On Oct 18, 2021, at 10:51 AM, Alex Zavatone  wrote:
> 
> 
> 
>> On Oct 18, 2021, at 11:31 AM, David Duncan  wrote:
>> 
>> In general it's also preferred that you look at the traitCollection of the 
>> most relevant view for this information – there are contexts for which the 
>> content size category may not match the global value (and there is API on 
>> UIView to restrict the overall range that you can apply as well). This also 
>> means you can just use traitCollectionDidChange as your notification.
> 
> Is that issued when the program or screen first starts up?  I was using that 
> a few weeks ago for other accessibility settings, but wasn’t sure if it’s 
> issued when the font first appears, because there is no change.

Generally trait collection values should be reasonably correct at 
initialization time, anytime they change after that will send a 
traitCollectionDidChange call.

> 
> Thanks
> Alex Zavatone
> 
> 

___

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

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

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

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


Re: Accessibility UIContentSizeCategory or current accessibility font setting

2021-10-18 Thread David Duncan via Cocoa-dev
In general its also preferred that you look at the traitCollection of the most 
relevant view for this information – there are contexts for which the content 
size category may not match the global value (and there is API on UIView to 
restrict the overall range that you can apply as well). This also means you can 
just use traitCollectionDidChange as your notification.

> On Oct 17, 2021, at 12:50 PM, Matt Jacobson via Cocoa-dev 
>  wrote:
> 
> Hey Alex,
> 
>> On Oct 17, 2021, at 2:51 PM, Alex Zavatone via Cocoa-dev 
>>  wrote:
>> 
>> We’ve got a situation where we need to check the current accessibility font 
>> size enum and apply custom settings to some attributed fonts.  I’ve seen 
>> that there is a way to check the current dynamic text size using SwiftUI, 
>> but I haven’t seen how to do it using UIKit.
>> 
>> I’ve seen that UIContentSizeCategory exists, but no idea how to see what the 
>> current value is.
>> 
>> Is anyone aware how to do this?  TIA.
> 
> Have you tried this?
> 
>   [UIApp preferredContentSizeCategory]
> 
> (Don’t forget to observe changes: UIContentSizeCategoryDidChangeNotification.)
> 
> 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:
> https://lists.apple.com/mailman/options/cocoa-dev/david.duncan%40apple.com
> 
> This email sent to david.dun...@apple.com

___

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

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

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

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


Re: Scaling a UIImage

2020-11-02 Thread David Duncan via Cocoa-dev


> On Nov 2, 2020, at 3:20 PM, Carl Hoefs  wrote:
> 
> Okay. It was my understanding that -TIFFRepresentation was the only way to 
> get serializable image data bytes... What is a more efficient way to do this?

If you want serializable data bytes, sure, but thats not what you appear to be 
doing in the code you sent – you appear to want a bitmap representation. 
Presumably you go on to do something other than serialize it (as I imagine you 
want to draw it in some way).

In general if you want something you can draw, you can get a 
-CGImageForProposedRect:context:hints, and if you need an NSBitmapRep you can 
use -bestRepresentationForRect:context:hints:. But assuming your trying to get 
that NSImage somewhere other than into (say) an NSImageView, there may be 
better APIs or pathways to that solution.

> -Carl
> 
> 
>> On Nov 2, 2020, at 3:09 PM, David Duncan > <mailto:david.dun...@apple.com>> wrote:
>> 
>> Also any code using -TIFFRepresentation for any reason other than to get 
>> actual TIFF data is likely suspect. There are absolutely more efficient ways 
>> to do this.
> 

___

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

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

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

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


Re: Scaling a UIImage

2020-11-02 Thread David Duncan via Cocoa-dev


> On Nov 2, 2020, at 2:59 PM, Carl Hoefs via Cocoa-dev 
>  wrote:
> 
> How can I correctly scale a UIImage from 3264x2448 down to 640x480 pixels?
> 
> 
> I have an iOS app that interacts with a macOS server process. The iOS app 
> takes a 3264x2448 camera image, scales it to 640x480 pixels, and makes a JPEG 
> representation of it to send to the server:
> 
>  NSData *dataObj = UIImageJPEGRepresentation(origImage,0.5);
> 
> The server reads the bytes, and creates an NSImage:
> 
>  NSImage *theImage = [[NSImage alloc] initWithData:imageData];
>  NSBitmapImageRep *imageRep = [[NSBitmapImageRep alloc] 
> initWithData:[theImage TIFFRepresentation]];

Do you specifically need an NSBitmapImageRep? What is your next step here.

Also any code using -TIFFRepresentation for any reason other than to get actual 
TIFF data is likely suspect. There are absolutely more efficient ways to do 
this.

But which way you should do depends on your next step...

> 
> But at this point, imageRep.pixelsWide=1280 and imageRep.pixelsHigh=960!

You got 1280x960 because your on a 2x device and your resizing code didn’t 
specify a scale for the image (you passed 0.0, which means to use “native” 
scale).

> 
> If I write theImage to disk and look at it with Preview, it displays onscreen 
> as 640x480 but Preview's Inspector Tool shows it to be 1280x960.
> 
> On the iOS app side, here's the UIImage category method I'm using to scale 
> the image:
> 
> + (UIImage *)imageWithImage:(UIImage *)image 
>   scaledToSize:(CGSize)newSize 
> {
>UIGraphicsBeginImageContextWithOptions(newSize, NO, 0.0);

Explicitly pass 1 here.

>[image drawInRect:CGRectMake(0, 0, newSize.width, newSize.height)];
>UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
>UIGraphicsEndImageContext();
>return newImage;
> }
> 
> Any suggestions?
> -Carl
> 
> ___
> 
> Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)
> 
> Please do not post admin requests or moderator comments to the list.
> Contact the moderators at cocoa-dev-admins(at)lists.apple.com
> 
> Help/Unsubscribe/Update your Subscription:
> https://lists.apple.com/mailman/options/cocoa-dev/david.duncan%40apple.com
> 
> This email sent to david.dun...@apple.com

___

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

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

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

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


Re: Throttling drawing to vertical refresh

2020-10-23 Thread David Duncan via Cocoa-dev

> On Oct 23, 2020, at 8:54 AM, Andreas Falkenhahn  
> wrote:
> 
> Thanks, but once again, I still need a throttle because I obviously don't 
> want to call -setNeedsDisplay as often as the CPU permits, thereby causing 
> 100% CPU load. I still need some timer mechanism that only calls 
> -setNeedsDisplay every once in a while. So should I setup a timer based on 
> the monitor's refresh frequency rate that calls -setNeedsDisplay in intervals 
> of the monitor's vertical refresh rate or how is that supposed to be 
> implemented?
> 
> On 19.10.2020 at 01:22 David Duncan wrote:
> 
>> On Oct 18, 2020, at 2:37 AM, Andreas Falkenhahn via Cocoa-dev
>>  wrote:
> 
>> Not quite. AppKit throttle view refresh to 60fps but it certainly
>> won't throttle code that changes the gfx more often than that, i.e. 
>> something like this
> 
>>   for(;;) view.layer.contents = (id) getNextFrame();
> 
>> will hog the CPU. So I need some external timing mechanism to set
>> layer.contents not more often than necessary. I need to see if CADisplayLink 
>> can do that…
> 

It isn’t likely that code like "for(;;) view.layer.contents = (id) 
getNextFrame()” will actually work in a typical GUI based application. In 
particular, this setup prevents Core Animation from doing its “commit” phase, 
and so nothing will appear on screen (or if it does, it will appear by side 
effect, such as by doing this on a background thread and the main thread going 
a commit at effectively random intervals relative to this).

So yes, you should run a timer. But at the same time I would expect your code 
to know what the appropriate timing for calling “getNextFrame()” should be. If 
that method can literally be called at any time to generate a newly advanced 
frame, then just pick an upper limit and call -setNeedsDisplay as mentioned 
previously. This will allow you to effectively match what the built in commit 
logic can handle.

If you have precise timing needs, you can use a CVDisplayLink[Ref] to manage 
the timing. If you don’t, a simple NSTimer running at some target frequency 
should be plenty.
___

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

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

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

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


Re: Problem in the creation of Graphics context(NSGraphicsContext)

2020-03-04 Thread David Duncan via Cocoa-dev
You’ll need to explain how you are creating the NSBitmapImageRep (what methods 
your calling, what parameters your passing, etc) that you pass to this method 
before anyone can explain why this might be going wrong for you.

> On Mar 3, 2020, at 10:19 PM, Sravan Kumar Lakkimsetti via Cocoa-dev 
>  wrote:
> 
> Hi,
> 
> 
> 
> In our product we use
> https://developer.apple.com/documentation/appkit/nsgraphicscontext/1529827-graphicscontextwithbitmapimagere?language=objc
> to create Graphics Context for drawing on top of image.
> 
> 
> 
> This particular API returns null in some cases. One particular case is
> troubling us. Would like to know why this happens and how to resolve
> 
> 
> 
> Here is the problem.
> 
> There are two monitors attached to Mac. Main display is retina display and
> secondary display is non-retina display. The application is moved from main
> display(retina display) to secondary display(non-retina display). In this
> case our application redraws the GUI(to use higher resolution images) In
> this process we are creating graphics context using the above api. This api
> returns null if the main display is retina and secondary display is
> non-retina.
> 
> 
> 
> It would be helpful if anyone can suggest on how to identify why this api
> returns null
> 
> 
> 
> Thanks
> 
> Sravan
> ___
> 
> Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)
> 
> Please do not post admin requests or moderator comments to the list.
> Contact the moderators at cocoa-dev-admins(at)lists.apple.com
> 
> Help/Unsubscribe/Update your Subscription:
> https://lists.apple.com/mailman/options/cocoa-dev/david.duncan%40apple.com
> 
> This email sent to david.dun...@apple.com

___

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

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

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

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


Re: UIView block-based methods

2019-11-11 Thread David Duncan via Cocoa-dev


> On Nov 9, 2019, at 12:09 PM, Carl Hoefs via Cocoa-dev 
>  wrote:
> 
> I'm trying to keep some older iOS code going, but I'm getting a deprecation 
> warning on many UIView class methods:
> 
> +beginAnimations:context:
> +setAnimationBeginsFromCurrentState:
> +setAnimationDuration:
> +commitAnimations
> etc.
> 
> Xcode 11.2.1 says: "'beginAnimations:context:' is deprecated: first 
> deprecated in iOS 13.0 - Use the block-based animation API instead"
> 
> What is this 'block-based animation API’?

+[UIView animateWithDuration:animations:] and the like. 

> -Carl
> 
> ___
> 
> Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)
> 
> Please do not post admin requests or moderator comments to the list.
> Contact the moderators at cocoa-dev-admins(at)lists.apple.com
> 
> Help/Unsubscribe/Update your Subscription:
> https://lists.apple.com/mailman/options/cocoa-dev/david.duncan%40apple.com
> 
> This email sent to david.dun...@apple.com

___

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

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

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

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


Re: Subclassing NSCollectionViewFlowLayout

2019-10-21 Thread David Duncan via Cocoa-dev


> On Oct 21, 2019, at 3:26 AM, Arved von Brasch via Cocoa-dev 
>  wrote:
> 
> Hello list,
> 
> Thanks to someone on the list who provided me with a clue, I found that if I 
> add this to my NSCollectionViewItem subclass:
> 
> override func viewWillAppear() {
>super.viewWillAppear()
>view.removeConstraints(view.constraints)

Don’t do this – you don’t know what constraints may be attached to the view 
that you don’t know about.

>view.addConstraint(NSLayoutConstraint.init(item: view, attribute: 
> .width, relatedBy: .greaterThanOrEqual, toItem: nil, attribute: 
> .notAnAttribute, multiplier: 1, constant: view.frame.size.width))
>view.addConstraint(NSLayoutConstraint.init(item: view, attribute: 
> .height, relatedBy: .greaterThanOrEqual, toItem: nil, attribute: 
> .notAnAttribute, multiplier: 1, constant: view.frame.size.height))

This doesn’t really make a whole lot of sense – this is basically saying 
“whatever frame you have at this point, you will never be smaller than” which 
kinda defeats the whole purpose.

>}
> 
> the Collection View loads as expected and all the items appear at the proper 
> size regardless of window resizes. However, I do end up with a large number 
> of NSAutoresizingMaskLayoutConstraint clash errors.  Not quite sure how I’m 
> going to resolve this yet, but I thought I’d post it in case anyone else 
> follows in my footsteps.

Not too surprising, since the constraints you made are in direct conflict with 
these auto resizing mask constraints (since the auto resizing mask constraints 
basically tell the auto layout engine what the frame size will be).

> 
> Cheers,
> Arved
> 
> 
>> On 2019-10-20, at 21:54, Arved von Brasch  wrote:
>> 
>> Hello Cocoa List,
>> 
>> I’m in the process of porting a hobby project to up-to-date Swift so it can 
>> be used on Catalina (and I can upgrade my work machine - still looking for a 
>> QuickTime 7 Pro replacement, though).  I’ve encountered a phenomenon 
>> subclassing NSCollectionViewFlowLayout that I haven’t been able to resolve.
>> 
>> I have a Core Data backed NSArrayController feeding data to a 
>> NSCollectionView (still using XIBs, as that made the porting easier). That 
>> all works fine, although was surprisingly tricky to get going.  I 
>> implemented a NSCollectionViewFlowLayout subclass to provide a left 
>> justified layout. I then implemented the NSCollectionViewDelegateFlowLayout 
>> function sizeForItemAt: to provide custom sizes for my items.  This all 
>> works as intended during testing when the collection view is first loaded.  
>> However, if I resize the enclosing window, all the items reduce in size to 
>> what appears to be a single pixel and I can’t work out where the tiny size 
>> is coming from. My output of sizeForItemAt always seems to have sensible 
>> values, and I can’t see an obvious place for where else the collection view 
>> would be getting sizes from.
>> 
>> I’m only implementing an init function, to set the estimatedItemSize, 
>> sectionInset and spacing values, and then overriding 
>> layoutAttributesForElements, as that seems to be all that’s required for my 
>> use case. I do not have any headers or footers or sections in my scenario, 
>> so the Array Controller is pretty simple too, although it acts as the Data 
>> Source and Delegate for the Collection View.
>> 
>> Can anyone give me pointers for what I am screwing up? My web searches for 
>> this only return a meagre set of results which don’t help much.
>> 
>> Kind regards,
>> Arved
> 
> ___
> 
> Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)
> 
> Please do not post admin requests or moderator comments to the list.
> Contact the moderators at cocoa-dev-admins(at)lists.apple.com
> 
> Help/Unsubscribe/Update your Subscription:
> https://lists.apple.com/mailman/options/cocoa-dev/david.duncan%40apple.com
> 
> This email sent to david.dun...@apple.com

___

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

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

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

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


Re: Alerts in Xcode 11

2019-09-30 Thread David Duncan via Cocoa-dev
Instead of creating a new window and a root view controller in order to present 
your alert, just use (assuming self is a UIViewController) self.present(, animated:  completion: …)

> On Sep 30, 2019, at 5:48 PM, Doug Hardie  wrote:
> 
> Not sure how to do that.  It's not in any view controller as it is used in 
> virtually all of the various view controllers.  That's why I wanted it as a 
> function.
> 
> -- Doug
> 
>> On 30 September 2019, at 14:44, David Duncan  wrote:
>> 
>> What happens if you present it over your normal view controller hierarchy 
>> instead of using another window?
>> 
>> Has your application adopted UIWindowScene?
>> 
>>> On Sep 30, 2019, at 5:36 PM, Doug Hardie via Cocoa-dev 
>>>  wrote:
>>> 
>>> I have some code that presents an alert to the user with information they 
>>> need, and an OK button to clear it.  It works fine in the previous Xcode 
>>> versions.  However, after upgrading to 11, it now displays the alert and 
>>> then immediately clears it.  This happens both in the simulator and on a 
>>> real device.  I have played around with the code and can't figure out how 
>>> to make it leave the alert on the screen.  This is in Swift.  It is a 
>>> function that is called from numerous places in the app.
>>> 
>>> func NotificationAlert (_ msg1: String, _ msg2: String) {
>>>  let ErrorAlert = UIAlertController(title: msg1, message: msg2, 
>>> preferredStyle: .alert)
>>>  let dismiss = UIAlertAction(title: "Ok", style: .default, handler: nil)
>>>  ErrorAlert.addAction(dismiss)
>>>  ErrorAlert.presentInOwnWindow(animated: true, completion: nil)
>>> }
>>> 
>>> extension UIAlertController {
>>>  func presentInOwnWindow(animated: Bool, completion: (() -> Void)?) {
>>>  let alertWindow = UIWindow(frame: UIScreen.main.bounds)
>>>  alertWindow.rootViewController = UIViewController()
>>>  alertWindow.windowLevel = UIWindow.Level.alert + 1;
>>>  alertWindow.makeKeyAndVisible()
>>>  alertWindow.rootViewController?.present(self, animated: animated, 
>>> completion: completion)
>>>  }
>>> }
>>> 
>>> 
>>> -- Doug
>>> 
>>> ___
>>> 
>>> Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)
>>> 
>>> Please do not post admin requests or moderator comments to the list.
>>> Contact the moderators at cocoa-dev-admins(at)lists.apple.com
>>> 
>>> Help/Unsubscribe/Update your Subscription:
>>> https://lists.apple.com/mailman/options/cocoa-dev/david.duncan%40apple.com
>>> 
>>> This email sent to david.dun...@apple.com
>> 
> 

___

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

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

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

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


Re: Alerts in Xcode 11

2019-09-30 Thread David Duncan via Cocoa-dev
What happens if you present it over your normal view controller hierarchy 
instead of using another window?

Has your application adopted UIWindowScene?

> On Sep 30, 2019, at 5:36 PM, Doug Hardie via Cocoa-dev 
>  wrote:
> 
> I have some code that presents an alert to the user with information they 
> need, and an OK button to clear it.  It works fine in the previous Xcode 
> versions.  However, after upgrading to 11, it now displays the alert and then 
> immediately clears it.  This happens both in the simulator and on a real 
> device.  I have played around with the code and can't figure out how to make 
> it leave the alert on the screen.  This is in Swift.  It is a function that 
> is called from numerous places in the app.
> 
> func NotificationAlert (_ msg1: String, _ msg2: String) {
>let ErrorAlert = UIAlertController(title: msg1, message: msg2, 
> preferredStyle: .alert)
>let dismiss = UIAlertAction(title: "Ok", style: .default, handler: nil)
>ErrorAlert.addAction(dismiss)
>ErrorAlert.presentInOwnWindow(animated: true, completion: nil)
> }
> 
> extension UIAlertController {
>func presentInOwnWindow(animated: Bool, completion: (() -> Void)?) {
>let alertWindow = UIWindow(frame: UIScreen.main.bounds)
>alertWindow.rootViewController = UIViewController()
>alertWindow.windowLevel = UIWindow.Level.alert + 1;
>alertWindow.makeKeyAndVisible()
>alertWindow.rootViewController?.present(self, animated: animated, 
> completion: completion)
>}
> }
> 
> 
> -- Doug
> 
> ___
> 
> Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)
> 
> Please do not post admin requests or moderator comments to the list.
> Contact the moderators at cocoa-dev-admins(at)lists.apple.com
> 
> Help/Unsubscribe/Update your Subscription:
> https://lists.apple.com/mailman/options/cocoa-dev/david.duncan%40apple.com
> 
> This email sent to david.dun...@apple.com

___

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

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

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

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


Re: Pausing an animation

2019-09-17 Thread David Duncan via Cocoa-dev


> On Sep 17, 2019, at 1:19 PM, Gabriel Zachmann via Cocoa-dev 
>  wrote:
> 
> I have a layer with two animations.
> 
> I would like to pause this animation occasionally .
> To do so, I set layer.speed = 0.0;
> 
> In the past, this has worked (with slightly different animations).
> However, in this case, the layer seems to just disappear. 
> (the layer occupies the whole screen, and when I set speed-0, the screen is 
> black)
> 
> Does anyone have an idea what might be the reason why it doesn't work?
> Are there properties that do not work with speed = 0?

Setting just the speed will often return you to the “beginning of time” for 
your CAMediaTiming compliant object (CALayer and CAAnimation the most common 
compliant objects).

 = ( - beginTime) * speed + timeOffset

So if you want to pause a layer, you also need to set the timeOffset to a value 
that matches the current value of 

QA1673 has a proper implementation for doing this 
>

> 
> Thanks a lot in advance.
> 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:
> https://lists.apple.com/mailman/options/cocoa-dev/david.duncan%40apple.com
> 
> This email sent to david.dun...@apple.com

___

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

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

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

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


Re: CABasicAnimation does not animate bounds.origin of a layer

2019-09-16 Thread David Duncan via Cocoa-dev


> On Sep 14, 2019, at 6:25 AM, Gabriel Zachmann via Cocoa-dev 
>  wrote:
> 
> Maybe, I haven't understood how the animation of the bounds property works,
> or the bounds property of a CALayer itself ,
> or I am making a stupid mistake.
> 
> Here is my code:
> 
>CALayer * imgLayer = [CALayer layer];
>imgLayer.contents= (__bridge id) imageRef;
>imgLayer.delegate= nil;
>imgLayer.opacity = 1.0;  
>imgLayer.anchorPoint  = CGPointMake( 0.0, 0.0 );
>imgLayer.zPosition   = -1.0;   
> 
>CABasicAnimation * anim = [CABasicAnimation animationWithKeyPath: 
> @"bounds"];
>anim.timingFunction = [CAMediaTimingFunction functionWithName: 
> kCAMediaTimingFunctionLinear];
>anim.duration  = 5;// sec
>anim.autoreverses  = YES;
>anim.repeatCount  = 100;  // = 
> forever
> 
>NSRect from_rect = NSMakeRect( 100.0, 100.0, 200.0, 200.0 );
>anim.fromValue= [NSValue valueWithRect: from_rect ];
>NSRect to_rect = NSMakeRect( 200.0, 200.0, 300.0, 300.0 );
>anim.toValue = [NSValue valueWithRect: to_rect ];
> 
>[imgLayer addAnimation: anim forKey: @"myBoundsAnim"];
> 
> 
> What I am seeing is that the image gets scaled (from  200 to 300 
> width/height) which is fine,
> but it always sits in the lower left corner of the screen (I am working under 
> macOS).
> 
> I want the lower left corner of the image to be animated , too.
> (Eventually, the animation will be a bit more complex, but for now I am just 
> trying to understand this.)
> 
> What am I missing? or going wrong?
> 
> I guess I could achieve the effect by animating the position property of the 
> layer,
> but I'd rather prefer to understand what is going on.
> I have also re-read the "Core Animation Basics" , but it doesn't explain the 
> meaning of bounds.origin.
> In the drawings, it's always (0,0).

The bounds origin is the origin of the coordinate system for sublayers of that 
layer, and thus changing the bounds origin moves sublayers around. However, 
contents are affected by the contentsGravity of a layer, and the default 
gravity is “Resize” and so the image will be scaled to fill the layer.

If you want the image to move, you should animate the position of the layer, 
not the bounds.origin.

> 
> Thanks a lot in advance for any insights.
> 
> 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:
> https://lists.apple.com/mailman/options/cocoa-dev/david.duncan%40apple.com
> 
> This email sent to david.dun...@apple.com

___

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

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

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

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


Re: UiView as slider with inertia

2018-10-01 Thread David Duncan
Yea, Jonathan’s recommendation is probably best. You would configure the 
collection view to scroll horizontally and just vend cells that are the 
numbers. You can probably configure UICollectionViewFlowLayout to do most of 
the heavy lifting for you, and perhaps just do a subclass to override 
targetContentOffset: as Jonathan recommended.

And if you end up needing more customization, constructing a 
UICollectionViewLayout subclass for this should be similarly straightforward, 
if you really need to, but I suspect subclassing will be easiest.

> On Oct 1, 2018, at 3:38 AM, Eric E. Dolecki  wrote:
> 
> Have an example? Sounds interesting - but I need the control to work like a
> UIScrollView in a way (the content can go off to the left and right and not
> flow)
> 
>|  visible  |
>|  |
> 0  1  2  |  3  4  *5*  6  7  |  8  9
>|  |
> 
> 
> 
> On Mon, Oct 1, 2018 at 2:34 AM Jonathan Hull  wrote:
> 
>> What you want is UICollectionView.  Make the numbers your cells, and use
>> -targetContentOffset(forProposedContentOffset:, withScrollingVelocity:) to
>> provide the snapping behavior.
>> 
>>> On Sep 30, 2018, at 8:46 PM, Eric Dolecki  wrote:
>>> 
>>> I've been tasked with coming up with a few horizontal sliders that are
>> really sequential numbers with the selected value in the middle of the
>> screen. They want drag and release with inertia and also rubber banding on
>> the ends. Values snap into place. 0 1 2 3 4 5 ...
>>> 
>>> Does anyone have something like this to save me some time? I'm assuming
>> uipangesturerecognizer and some uikit dynamics.
>>> 
>>> Thanks!!
>>> Eric
>>> 
>>> Sent from my iPhone X.
>>> ___
>>> 
>>> Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)
>>> 
>>> Please do not post admin requests or moderator comments to the list.
>>> Contact the moderators at cocoa-dev-admins(at)lists.apple.com
>>> 
>>> Help/Unsubscribe/Update your Subscription:
>>> https://lists.apple.com/mailman/options/cocoa-dev/jhull%40gbis.com
>>> 
>>> This email sent to jh...@gbis.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:
> https://lists.apple.com/mailman/options/cocoa-dev/david.duncan%40apple.com
> 
> This email sent to david.dun...@apple.com

___

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

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

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

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


Re: Bothersome "NSView-Encapsulated-Layout-Height" constraint?

2018-08-31 Thread David Duncan


> On Aug 30, 2018, at 6:38 PM, Demitri Muna  wrote:
> 
> 
> On Aug 30, 2018, at 9:23 PM, Quincey Morris 
>  wrote:
> 
>> “Encapsulated layout height” sounds like one of the constraints that IB adds 
>> to your layout when it’s under-constrained at design time. Are you adding 
>> the other constraints at run time?
> 
> I’m not adding any constraints at run time. IB isn’t reporting anything as 
> under-constrained. I tried to add a height constraint to the NSTableCellView, 
> but that constraint is greyed out (and I found would have conflicted with the 
> NSView-Encapsulated-Layout-Height anyway).

The “NSView-Encapsulated-Layout” constraints are constraints that are added to 
represent views that are not laying out with auto layout but still need to be 
represented in the solution. Beyond that, I’m not familiar with the area that 
you are trying to resolve. HTH.

> 
> Thanks,
> Demitri
> 
> ___
> 
> Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)
> 
> Please do not post admin requests or moderator comments to the list.
> Contact the moderators at cocoa-dev-admins(at)lists.apple.com
> 
> Help/Unsubscribe/Update your Subscription:
> https://lists.apple.com/mailman/options/cocoa-dev/david.duncan%40apple.com
> 
> This email sent to david.dun...@apple.com

___

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

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

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

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


Re: problem getting CALayer to draw an image

2018-04-05 Thread David Duncan

> On Apr 5, 2018, at 10:53 AM, James Walker <jam...@frameforge3d.com> wrote:
> 
> I have a generic NSView that contains some subviews, and I'd like to add a 
> background image.  I tried code like this:
> 
> NSImage* backgroundImage = [NSImage imageNamed: @"blueprint controls.png"];
> CALayer* holderLayer = [CALayer layer];
> _throttleHolder.layer = holderLayer;
> _throttleHolder.wantsLayer = YES;
> holderLayer.zPosition = 4.0f;
> holderLayer.contents = backgroundImage;
> holderLayer.hidden = NO;
> holderLayer.bounds = NSRectToCGRect( _throttleHolder.bounds );
> [holderLayer setNeedsDisplay];

You don’t need to call -setNeedsDisplay here, and it may be what is destroying 
your content (when a layer displays, its stores the result of drawing in 
contents – you don’t want that since you are setting the contents directly).

Overall however, I think AppKit has an NSView method (something like 
updateLayer I think) that you want to override to do this. The layer’s geometry 
should already be set by AppKit and you should not modify it if I recall 
correctly. Geometry includes things such as center/bounds/frame and hidden.

> 
> But no background image shows up.  On the other hand, if I add the line
> 
> holderLayer.backgroundColor = CGColorGetConstantColor( kCGColorWhite );
> 
> then I get a white background, so apparently the layer is there and capable 
> of drawing.  And yes, I have made sure that backgroundImage is not nil.
> 
> At this point, it probably would have been quicker to just go ahead and 
> subclass NSView, but I'm curious about what dumb mistake I'm making.
> ___
> 
> Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)
> 
> Please do not post admin requests or moderator comments to the list.
> Contact the moderators at cocoa-dev-admins(at)lists.apple.com
> 
> Help/Unsubscribe/Update your Subscription:
> https://lists.apple.com/mailman/options/cocoa-dev/david.duncan%40apple.com
> 
> This email sent to david.dun...@apple.com

--
David Duncan

___

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

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

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

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


Re: UITabBarItem selection Voice over speaks number apart from accessibility label,value

2018-04-05 Thread David Duncan
Can you file a bug with a complete sample and report the bug# back to the list?

It isn’t immediately obvious to me where the numbers you report are coming 
from, or why accessibility would speak them, but I can take a look once I have 
a sample in front of me.

> On Apr 5, 2018, at 4:37 AM, Devarshi Kulshreshtha 
> <devarshi.bluec...@gmail.com> wrote:
> 
> I am programmatically assigning bar button items to  UITabBar using below
> code:
> 
> -(void)setupTabs {
>UIImage *icon1 = [[UIImage imageNamed:@"Icon1"]
> imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate];
>UITabBarItem *option1 = [[UITabBarItem alloc] initWithTitle:@"Option1"
> image: icon1 selectedImage: icon1];
> 
>UIImage *icon2 = [[UIImage imageNamed:@"Icon2"]
> imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate];
>UITabBarItem *option2 = [[UITabBarItem alloc] initWithTitle:@"Option2"
> image: icon2 selectedImage: icon2];
> 
>UIImage *icon3 = [[UIImage imageNamed:@"Icon3"]
> imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate];
>UITabBarItem *option3 = [[UITabBarItem alloc] initWithTitle:@"Option3"
> image: icon3 selectedImage: icon3];
> 
>UIImage *icon4 = [[UIImage imageNamed:@"Icon4"]
> imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate];
>UITabBarItem *option4 = [[UITabBarItem alloc] initWithTitle:@"Option4"
> image: icon4 selectedImage: icon4];
> 
>self.tabBar.items = @[option1, option2, option3, option4];
> }
> 
> Problem is - when I am tapping on respective tab bar item after enabling
> Accessibility - Voice Over it is stating the tab bar title as well as
> number 104 for first tab, 204 for second tab and so on.
> 
> I have tried explicitly setting the accessibilityValue, accessibilityLabel,
> etc for items but it is always speaking the number after title.
> 
> Any ideas on how to stop voice over from speaking that number after title?
> 
> Thanks
> 
> 
> 
> -- 
> Thanks,
> 
> Devarshi
> ___
> 
> Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)
> 
> Please do not post admin requests or moderator comments to the list.
> Contact the moderators at cocoa-dev-admins(at)lists.apple.com
> 
> Help/Unsubscribe/Update your Subscription:
> https://lists.apple.com/mailman/options/cocoa-dev/david.duncan%40apple.com
> 
> This email sent to david.dun...@apple.com

--
David Duncan

___

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

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

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

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


Re: dequeueReusableCellWithIdentifier bad performance in case of less number of cells?

2018-01-10 Thread David Duncan

> On Jan 10, 2018, at 3:48 AM, Devarshi Kulshreshtha 
> <devarshi.bluec...@gmail.com> wrote:
> 
> I had a discussion with my colleagues regarding use
> of dequeueReusableCellWithIdentifier, few of them are under assumption that
> if there are less number of cells it is better to directly alloc init a
> UITableViewCell in place of using dequeueReusableCellWithIdentifier. They
> are saying that since at a time almost all the cells will be displayed
> there is no need to use dequeueReusableCellWithIdentifier because it
> degrades performance in comparison to alloc init, in such scenarios. My
> understanding is that there is no any performance cost as such and behind
> the scenes dequeueReusableCellWithIdentifier is doing the same thing
> (allocating and initializing) if a cell cannot be reused.
> 
> Is there any way I can compare the performance of using
> dequeueReusableCellWithIdentifier versus using directly alloc init and
> share with them to come to a conclusion? Please suggest.

The overhead of calling dequeueReusableCellWithIdentifier: should be extremely 
minimal. The static/short table case is actually more likely to be a case where 
breaking the standard pattern is only going to lead to future maintenance 
headaches vs achieving any significant performance improvements.

If you want to measure the difference, you would probably just call alloc/init 
vs dequeue in a tight loop and measure the total time taken. If you find a case 
that seems problematic, it would be worth a bug report.

> 
> -- 
> Thanks,
> 
> Devarshi
> ___
> 
> Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)
> 
> Please do not post admin requests or moderator comments to the list.
> Contact the moderators at cocoa-dev-admins(at)lists.apple.com
> 
> Help/Unsubscribe/Update your Subscription:
> https://lists.apple.com/mailman/options/cocoa-dev/david.duncan%40apple.com
> 
> This email sent to david.dun...@apple.com

--
David Duncan

___

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

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

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

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


Re: unable to update UI on main thread in 10.13

2017-10-27 Thread David Duncan


> On Oct 27, 2017, at 7:17 AM, sqwarqDev <sqwarq...@icloud.com> wrote:
> 
> 
>> On 27 Oct 2017, at 21:11, David Duncan <david.dun...@apple.com> wrote:
>> 
>> In your background task which attributed string are you modifying? From the 
>> looks of your ‘updateUI’ function it seems like you are modifying the one 
>> that NSTextView provides, which is likely to actually be an instance of 
>> NSTextStorage and sending callbacks to the NSTextView to update itself – 
>> which would trigger drawing on your background thread.
>> 
>> In general however, I would recommend a different approach to your 
>> processing – have your background task work on its own local mutable 
>> attributed string, then signal that string back to the main thread when it 
>> is done. This should also allow you to avoid the time you use to poll the 
>> completion of this work (since you’ll be told specifically when the work is 
>> finished, rather than having to check a progress flag).
>> 
> 
> Thanks for the reply, David.
> 
> Hmm, interesting that you say that. The ‘superAttributedString’ was precisely 
> meant to avoid the problem you’re suggesting in my last code refactor. It’s 
> declared in the ViewController as global var. The textview isn’t supposed to 
> know anything about it till it gets sent it in the last line of the updateUI 
> func. 
> 
> What made you think that it comes from the textview?

You said you subclassed NSTextView, so I think that biased my thinking that 
this was all code on that class, but looking again that seems obviously in 
error. That said, I’m not otherwise certain how your code would get the text 
view manipulated on a secondary thread.

> 
> 
> 
> 
> 
>>> On Oct 27, 2017, at 7:03 AM, sqwarqDev <sqwarq...@icloud.com> wrote:
>>> 
>>> I have a subclass of NSTextView which I'm trying to update in my UI. When 
>>> the user clicks a button in the main UI, I run a bunch of processes in the 
>>> background, save their output to an attributed string, then update the 
>>> textview's textstorage on the main thread using 
>>> performSelector(onMainThread:). 
>>> 
>>> @IBAction func profileAction(_ sender: Any)
>>> {
>>> >> it's all done with repeat timer >...
>>> this_timer = Timer.scheduledTimer(timeInterval: 1.0, target: 
>>> self, selector: #selector(self.myRepeatFunc),userInfo: nil, repeats: true)
>>> this_timer.fire()
>>> }
>>> 
>>> 
>>> @objc func myRepeatFunc() 
>>> {
>>> if stuffIsDone == true 
>>> {
>>> this_timer.invalidate()
>>> self.scanBtn.isEnabled = true
>>> self.profileBtn.isEnabled = true
>>> self.historyBtn.isEnabled = true
>>> performSelector(onMainThread: #selector(updateUI), with: nil, 
>>> waitUntilDone: false)
>>> }
>>> }
>>> 
>>> 
>>> @objc func updateUI()
>>> {
>>> 
>>> let zeroAttributesString = NSMutableAttributedString(string: "")
>>> 
>>> self.profilerTextView.textStorage?.setAttributedString(zeroAttributesString)
>>> 
>>> self.profilerTextView.textStorage?.setAttributedString(self.superAttributedString)
>>> }
>>> 
>>> 
>>> This works absolutely fine in both 10.11 and 10.12; however, on 10.13 I get 
>>> the dreaded "This application is modifying the autolayout engine from a 
>>> background thread after the engine was accessed from the main thread. This 
>>> can lead to engine corruption and weird crashes." message.
>>> 
>>> I've tried swapping out performSelector(onMainThread:) for 
>>> DispatchQueue.main.async to no avail. I still get the same error. I've 
>>> tried using Xcode 9's 'Main Thread Checker' diagnostic tool, but even 
>>> though I have 'Pause on issues' selected, it never pauses and just lets my 
>>> code run. I've also tried symbolic breakpoints on [NSView setFrame] and 
>>> _AssertAutolayoutOnAllowedThreadsOnly from the stack trace. Neither stop my 
>>> code. 
>>> 
>>> I'm out of ideas, and the rubber duck has come up short. Any advice much 
>>> appreciated (stack trace follows):
>>> 
>>> This application is modifying the autolayout engine from a background 
>>> thread after the engine was accessed from the main thread. This can lead to 
>>> engine corruption and weird crashes.
>&

Re: unable to update UI on main thread in 10.13

2017-10-27 Thread David Duncan
   0x7fff4cf70e33 -[NSClipView 
> _updateOverhangSubviewsIfNeeded] + 839
>   12  AppKit  0x7fff4d04050d -[NSClipView 
> _reflectDocumentViewFrameChange] + 692
>   13  AppKit  0x7fff4cfaa1b0 -[NSView 
> _postFrameChangeNotification] + 83
>   14  AppKit  0x7fff4cfa47bb -[NSView 
> setFrameSize:] + 2061
>   15  AppKit  0x7fff4d03a23b 
> -[NSTextView(NSPrivate) _setFrameSize:forceScroll:] + 1081
>   16  AppKit  0x7fff4d039d3a -[NSTextView 
> setFrameSize:] + 143
>   17  AppKit  0x7fff4d0392ac -[NSTextView 
> setConstrainedFrameSize:] + 635
>   18  UIFoundation0x7fff72e25084 
> -[NSLayoutManager(NSPrivate) _resizeTextViewForTextContainer:] + 938
>   19  UIFoundation0x7fff72f392d6 
> _resizeTextViewsIfNeeded + 285
>   20  UIFoundation0x7fff72e29ea2 
> _NSFastFillAllLayoutHolesForGlyphRange + 1851
>   21  UIFoundation0x7fff72e6890b 
> -[NSLayoutManager lineFragmentRectForGlyphAtIndex:effectiveRange:] + 39
>   22  AppKit  0x7fff4d1071de -[NSTextView 
> _extendedGlyphRangeForRange:maxGlyphIndex:drawingToScreen:] + 509
>   23  AppKit  0x7fff4d0d69fc -[NSTextView 
> drawRect:] + 1807
>   24  AppKit  0x7fff4d82ee3d 
> _NSViewDrawRect + 83
>   25  AppKit  0x7fff4d83c0d4 
> -[NSView(NSInternal) 
> _recursive:displayRectIgnoringOpacity:inGraphicsContext:shouldChangeFontReferenceColor:]
>  + 1578
>   26  AppKit  0x7fff4d83baa4 
> -[NSView(NSInternal) 
> _recursive:displayRectIgnoringOpacity:inContext:shouldChangeFontReferenceColor:]
>  + 56
>   27  AppKit  0x7fff4d0ce374 
> __46-[NSView(NSLayerKitGlue) drawLayer:inContext:]_block_invoke + 289
>   28  AppKit  0x7fff4d0cdf08 
> -[NSView(NSLayerKitGlue) _drawViewBackingLayer:inContext:drawingHandler:] + 
> 1577
>   29  AppKit  0x7fff4d0cd8d9 
> -[NSView(NSLayerKitGlue) drawLayer:inContext:] + 77
>   30  AppKit  0x7fff4d272cbc -[NSTextView 
> drawLayer:inContext:] + 114
>   31  AppKit  0x7fff4d1ef863 
> -[_NSBackingLayerContents drawLayer:inContext:] + 165
>   32  QuartzCore  0x7fff5aa50b76 -[CALayer 
> drawInContext:] + 281
>   33  AppKit  0x7fff4d1ef44d 
> -[_NSTiledLayer drawTile:inContext:] + 634
>   34  AppKit  0x7fff4d1ef179 
> -[_NSTiledLayerContents drawLayer:inContext:] + 181
>   35  QuartzCore  0x7fff5aa50b76 -[CALayer 
> drawInContext:] + 281
>   36  AppKit  0x7fff4d1ef0b9 
> -[NSTileLayer drawInContext:] + 166
> 
> 
> 
> TIA
> 
> 
> Best
> 
> 
> 
> Phil
> @sqwarq
> ___
> 
> Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)
> 
> Please do not post admin requests or moderator comments to the list.
> Contact the moderators at cocoa-dev-admins(at)lists.apple.com
> 
> Help/Unsubscribe/Update your Subscription:
> https://lists.apple.com/mailman/options/cocoa-dev/david.duncan%40apple.com
> 
> This email sent to david.dun...@apple.com

--
David Duncan

___

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

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

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

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


Re: Converting a Storyboard into separate NIBs.

2017-06-19 Thread David Duncan

> On Jun 19, 2017, at 3:37 PM, Charles Srstka <cocoa...@charlessoft.com> wrote:
> 
>> On Jun 19, 2017, at 4:29 PM, Alex Zavatone <z...@mac.com> wrote:
>> 
>> From line 153 of UIViewController.h: 
>> 
>>  As a convenience, the default init method will do this for you,
>>  and specify nil for both of this methods arguments.) In the specified NIB, 
>> the File's Owner proxy should
>>  have its class set to your view controller subclass, with the view outlet 
>> connected to the main view. If you
>>  invoke this method with a nil nib name, then this class' -loadView method 
>> will attempt to load a NIB whose
>>  name is the same as your view controller's class.
>> 
>> The pearl is here:
>> 
>> If you
>>  invoke this method with a nil nib name, then this class' -loadView method 
>> will attempt to load a NIB whose
>>  name is the same as your view controller's class.
> 
> The documentation begs to differ, though:

AppKit vs UIKit – your both right for the respective frameworks you are 
speaking to.

> 
> https://developer.apple.com/documentation/appkit/nsviewcontroller/1434405-loadview
> 
>> Prior to OS X v10.10, the loadView() method did not provide well-defined 
>> behavior if the nibName property’s value was nil. In macOS 10.10 and later, 
>> however, you get correct behavior without specifying a nib name as long as 
>> the nib file’s name is the same as that of the view controller. For example, 
>> if you have a view controller subclass called MyViewController and a nib 
>> file with the same name, you can employ the convenient initialization 
>> pattern [[MyViewController alloc] init].
> 
> The AppKit release notes agree:
> 
> https://developer.apple.com/library/content/releasenotes/AppKit/RN-AppKitOlderNotes/index.html#10_10ViewController
> 
>> loadView: would previously not have well defined behavior if there was a 
>> "nil" nibName. On 10.10 and later, if nibName is nil NSViewController will 
>> automatically try to load a nib with the same name as the classname. This 
>> allows a convenience of doing [[MyViewController alloc] init] (which has a 
>> nil nibName) and having it automatically load a nib with the name 
>> "MyViewController”.
> 
> The sense I get from these methods is that it might have kinda, sorta, 
> accidentally worked in the past, but it shouldn’t be relied on.
> 
> Reading through those release notes reminded me of *another* caveat I’d 
> forgotten; the functionality only correctly parses Swift class names in 
> *10.11* and higher. Otherwise, it’ll be looking for MyProjectName.Foo.xib 
> instead of Foo.xib like it should. So, if you’re using Swift, better to 
> restrict usage of this feature to El Cap or better.
> 
> Charles
> 
> ___
> 
> Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)
> 
> Please do not post admin requests or moderator comments to the list.
> Contact the moderators at cocoa-dev-admins(at)lists.apple.com
> 
> Help/Unsubscribe/Update your Subscription:
> https://lists.apple.com/mailman/options/cocoa-dev/david.duncan%40apple.com
> 
> This email sent to david.dun...@apple.com

--
David Duncan

___

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

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

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

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


Re: Unable to extract JPEG from PHAsset

2017-06-17 Thread David Duncan

> On Jun 16, 2017, at 7:31 AM, Glen Huang <hey...@gmail.com> wrote:
> 
> Hi,
> 
> I'm trying to extract the JPEG data from a PHAsset. I did it like this:
> 
>let fetchOptions = PHFetchOptions()
>fetchOptions.sortDescriptors = [NSSortDescriptor(key: 
> "creationDate", ascending: true)]
>let assets = PHAsset.fetchAssets(with: fetchOptions)
>jpg(for: assets[0])
> 
> where jpg(for:) is
> 
>func jpg(for asset: PHAsset) {
>let size = CGSize(width: 100, height: 100)
>PHImageManager.default().requestImage(for: asset, targetSize: size, 
> contentMode: .aspectFit, options: nil) { image, info in
>if let image = image {
>let jpg = UIImageJPEGRepresentation(image, 0.8)!
>}
>}
>}
> 
> It works in the simulator running iOS 11, but fails on iPhone 5S every time 
> with
> 
> fatal error: unexpectedly found nil while unwrapping an Optional value
> 
> And the thing caused that error was the bang after the 
> UIImageJPEGRepresentation function.
> 
> I'm using Xcode 9 beta, Swift 4, new build system, and the phone runs iOS 
> 10.3.2
> 
> Any idea why that happens and how I can extract the JPEG data from PHAsset? 

There is no obvious reason why this should fail, but the usual debugging things 
apply – what are the quality of image? (image.CGImage can still be nil, even if 
image is not). Does UIImageJPEGRepresentation() fail in any other situations? 
Can you reproduce this without using PHAsset?

> 
> Thank you.
> ___
> 
> Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)
> 
> Please do not post admin requests or moderator comments to the list.
> Contact the moderators at cocoa-dev-admins(at)lists.apple.com
> 
> Help/Unsubscribe/Update your Subscription:
> https://lists.apple.com/mailman/options/cocoa-dev/david.duncan%40apple.com
> 
> This email sent to david.dun...@apple.com

--
David Duncan

___

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

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

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

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


Re: Does file-mapping a memory allocation work around RAM limits?

2017-05-04 Thread David Duncan

> On May 3, 2017, at 11:51 PM, Rick Mann <rm...@latencyzero.com> wrote:
> 
>> 
>> On May 3, 2017, at 23:27 , Doug Hill <cocoa...@breaqz.com> wrote:
>> 
>> 
>>> On May 3, 2017, at 6:21 PM, Rick Mann <rm...@latencyzero.com> wrote:
>>> 
>>> Our iOS app works with very large data buffers (hundreds of MB). As you can 
>>> imagine, we run into issues at times.
>>> 
>>> I saw some sample code that used this technique, and it got me wondering if 
>>> this actually works around the 600 MB limitation of some iOS devices (which 
>>> begs another question: doss the large iPad Pro with 3GB of RAM also limit 
>>> apps to 600 MB?).
>>> 
>>> -- 
>>> Rick Mann
>>> rm...@latencyzero.com
>> 
>> The limits of mmap should be the limits of the file system. Well, 
>> technically it’s limited by the size_t parameter which I guess is OS 
>> specific. But these days it should be what the VFS can handle.
>> 
>> I just tried out this code snippet:
>> 
>> http://www.linuxquestions.org/questions/programming-9/mmap-tutorial-c-c-511265/
>>  
>> <http://www.linuxquestions.org/questions/programming-9/mmap-tutorial-c-c-511265/>
>> 
>> and set the size of the mapped file to 32GB Works fine on a Mac with 16GB of 
>> RAM.
>> 
>> It is SLOOWW however. You have to move all that data across a bus 
>> after all. If you need to load 3GB of data from your file, I recommend 
>> making it happen on a background thread. And make some lights blink and play 
>> a happy tune while the user waits.
>> 
>> Not sure what the limitation on some iOS devices you’re referring to. Is it 
>> dependent on the installed RAM? Are there other artificial limits?
> 
> Yeah, at least on 1 GB iOS devices, apps are limited to 600 MB (even if 
> there's more available). I think there are subtleties to that (e.g. maybe 
> texture memory isn't counted), I'm not sure.

iOS tracks memory per-process primarily in 3 buckets – Dirty, Resident, and 
Virtual. The hierarchy is also in that order, all Dirty memory is Resident, and 
all Resident memory is Virtual. Virtual just means that address space is 
allocated – there is a hard limit on this that is below the theoretical address 
space (significantly so in the case of iOS), in the 2-4GB range (may vary by 
device installed memory, but I don’t recall). Resident memory is memory that 
has physical RAM allocated to it and so the CPU can manipulate it. This is the 
600MB limit that you mentioned (at least on 1GB devices, again I don’t recall 
if it is different or what it is on larger devices). Dirty memory is memory 
that has been written to. Because iOS does not have a demand paging memory 
system, this memory typically has no where to go if you hit the Resident memory 
limits.

This is where mmap() comes into play – it allows you to create a Virtual 
allocation, whose Resident memory is backed by a file, just like in a demand 
paged system. So you can write to that memory, and if your app uses too much 
memory, the OS can attempt to recover by writing it to disk on your behalf 
(turning Resident-Dirty memory into Virtual). Sweet right?

But remember that hard Virtual limit I mentioned earlier – that means that if 
you try to mmap() too much you end up running out of Virtual memory, and you’ll 
likely get abort()’d by some subsystem attempting to allocate memory.

And so even though iOS is a 64-bit OS, due to other performance considerations, 
the virtual address space is more akin to a 32-bit OS. This is of course an 
implementation detail that can be expanded in the future, but something to keep 
in mind if you plan to use mmap() a lot.

From the sounds of what our app does, keeping around a single mmap()’s scratch 
space may be reasonable. You probably still want to keep it at a modest size, 
but it should help you process those large data buffers without getting your 
app killed.
--
David Duncan

___

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

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

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

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

Re: Question about the Main Thread

2017-04-25 Thread David Duncan

> On Apr 25, 2017, at 7:51 AM, Dave <d...@looktowindward.com> wrote:
> 
> Mac Project.
> 
> Hi All, 
> 
> I’m using performSelector: withObject: afterDelay: in order to postpone 
> further processing until after the current method/run loop as expired, this 
> puts the request at the End of the Queue, my question is, is there anyway of 
> putting it at the head of the Queue so it gets processing before other 
> requests?


Nope, and even if there was there would be no guarantee that something else 
wouldn’t come behind you and insert itself ahead (or many such things). Your 
best bet is to consider the request simple queued, with no specific timing in 
relation to other requests to do the same.
--
David Duncan

___

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

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

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

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

Re: Unicode filenames with Apple File System and UIManagedDocument

2017-03-29 Thread David Duncan

> On Mar 22, 2017, at 2:25 PM, davel...@mac.com wrote:
> 
>> 
>> On Mar 22, 2017, at 2:00 PM, David Duncan <david.dun...@apple.com> wrote:
>> 
>>> 
>>> On Mar 22, 2017, at 4:15 AM, davel...@mac.com wrote:
>>> 
>>>> 
>>>> On Mar 22, 2017, at 5:05 AM, Alastair Houghton 
>>>> <alast...@alastairs-place.net> wrote:
>>>> 
>>>> On 21 Mar 2017, at 20:49, Quincey Morris 
>>>> <quinceymor...@rivergatesoftware.com> wrote:
>>>>> 
>>>>> On Mar 20, 2017, at 14:23 , davel...@mac.com wrote:
>>>>>> 
>>>>>> "iOS HFS Normalized UNICODE names , APFS now treats all file[ name]s as 
>>>>>> a bag of bytes on iOS . We are requesting that Applications developers 
>>>>>> call the correct Normalization routines to make sure the file name 
>>>>>> contains the correct representation."
>>>>> 
>>>>> I’ve been letting this simmer for a couple of days now, and I’ve come to 
>>>>> the conclusion that it’s — sincere apologies to the unnamed Apple 
>>>>> engineer who wrote it — as dumb as dirt.
>>>>> 
>>>>> — It’s not a "bag of bytes”, because bags of stuff are generally 
>>>>> understood as unordered sets, and I doubt that’s what’s intended. It has 
>>>>> to be a sequence of bytes.
>>>> 
>>>> In the context of filesystems (and specifically filenames), the phrases 
>>>> “bag of bytes” and “bunch of bytes” have a fairly specific meaning.  The 
>>>> point is that the filesystem doesn’t inspect the bytes it’s given, and 
>>>> doesn’t care what they represent (about the only exception is that it 
>>>> probably doesn’t support embedded NULs).  It isn’t suggesting that the 
>>>> names are treated as an unordered set of bytes (that’d just be silly).  
>>>> It’s just expressing the fact that the filesystem doesn’t care what they 
>>>> are - it may compare them, and if it does so, it will use binary ordering 
>>>> (not some other collation sequence) and won’t worry about things like case 
>>>> or encoding at all.
>>>> 
>>>>> — It’s not just a string, it has to be a string in a known encoding. 
>>>>> Otherwise, how could you ever mount an external drive on a different 
>>>>> computer? The encoding has to be pre-specified for APFS, or it has to be 
>>>>> stored in metadata on each volume.
>>>> 
>>>> Agreed, that’s where the “bunch of bytes” approach falls down.
>>>> 
>>>>> — It’s not just going to be a string of known encoding, it’s going to be 
>>>>> Unicode. That’s going to be true even if the fact is specified in volume 
>>>>> metadata and it’s theoretically possible to create APFS volumes with 
>>>>> non-Unicode file names. Anything other than Unicode would, at this point, 
>>>>> be a crime against humanity.
>>>> 
>>>> If I’d designed APFS, it probably would use Unicode names (and it’d store 
>>>> the version of Unicode it used in the filesystem header, to avoid having 
>>>> to hard-code it).
>>>> 
>>>> But I didn’t design it - Dominic Giampaolo and his team did - and we still 
>>>> don’t have that much information about how APFS works.  I’m sure they had 
>>>> their reasons for whatever decision they’ve made here.
>>>> 
>>>>> Is *that* the bottom line? I doubt it. I don’t believe the above quoted 
>>>>> statement can be correct. I could believe that normalization is being 
>>>>> moved out of the file system code, but it would have to be moved to 
>>>>> (e.g.) the Cocoa frameworks, still “downstream” of the file-handling 
>>>>> APIs. It can’t go upstream of the public APIs without breaking an API 
>>>>> contract that has existed for the 16+ years since OS X 10.0.
>>>> 
>>>> This is a tricky area.  The problem with what we have at the moment 
>>>> (-fileSystemRepresentation) is that it *assumes* HFS+ semantics.  That 
>>>> isn’t always going to be correct for existing non-HFS+ filesystems, let 
>>>> alone in the future.  Of course, if you’re using the NSURL or NSString 
>>>> methods, rather than calling the BSD or C library APIs yourself, this is 
>>>> all hidden from you anyway (you certainly shouldn’t, IMO, be required to 
>>>> do anything unusual at Cocoa l

Re: Unicode filenames with Apple File System and UIManagedDocument

2017-03-29 Thread David Duncan
ver rules govern the 
>> filesystem mounted at Baz.  And remember, not every filesystem will be using 
>> a well known encoding - macOS already has code to add and remove percent 
>> escapes (I kid you not) for this very reason.
>> 
>> I’d like to hear what Dominic has to say (at least what he *can* say) about 
>> this, since he’s likely in a position to shed some light on it - or at least 
>> to take on board that we’re worrying about it.  At the very least it’d be 
>> nice to see some more detail about APFS published somewhere *soon*...
>> 
>> Kind regards,
>> 
>> Alastair.
>> 
>> --
>> http://alastairs-place.net
> 
> 
> I think it should be taken care of by NSURL so developers don’t need to worry 
> about it but that doesn’t appear to be the case, but, at this point I just 
> want to know what the correct thing to do is. And maybe it does (which means 
> there was a bug in the APFS conversion), but I can’t tell for certain.
> 
> I’ve uploaded different versions to TestFlight for the person to try but at 
> this point the original version of my app and each of these different 
> versions all allow the user to open files created on iOS 10.3 with Arabic 
> names but none of them seem to allow the user to open files that were created 
> on 10.2 unless the files are renamed to English. So either NSURL takes care 
> of it and there was a bug in the APFS conversion or we do need to do 
> something additional when sending NSStrings to the NSURL methods. I realize 
> is isn’t official support channels but it would be really nice to hear from 
> Apple. I’ll probably use one of my DTS incidents to ask when I have time to 
> submit the request sometime this week. I’ll certainly report back if I get a 
> definitive answer.

So there was another explanation posted on the bug that I’m not certain you 
got, but which I think may explain.

Basically the concept is that since APFS doesn’t normalize file names, if you 
store file names in some other storage (say in your preferences) then what 
could happen is this:

10.2: File is saved with a file name handed to the file system in NFC form. 
File system converts the file name to NFD. You store it as NFC.
10.3: File system is converted to APFS, and the file name is NFD. You try to 
look up the file as NFC, and it fails.

This would also mean that newly created files on APFS are always accessible, 
even via the “same” name, because the file system stored the filename as you 
presented it. Its only files whose name you stored in a different form from the 
system that are inaccessible via those old names.

> 
> Thanks,
> Dave Reed
> 
> 
> ___
> 
> Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)
> 
> Please do not post admin requests or moderator comments to the list.
> Contact the moderators at cocoa-dev-admins(at)lists.apple.com
> 
> Help/Unsubscribe/Update your Subscription:
> https://lists.apple.com/mailman/options/cocoa-dev/david.duncan%40apple.com
> 
> This email sent to david.dun...@apple.com

--
David Duncan

___

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

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

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

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

Re: Unicode filenames with Apple File System and UIManagedDocument

2017-03-23 Thread David Duncan
I just want to remind everyone I’m *not* a file system’s engineer – I’m just 
trying to help Dave (and anyone else caught in this) make sure their app can 
find their files.

> On Mar 23, 2017, at 1:53 AM, Alastair Houghton <alast...@alastairs-place.net> 
> wrote:
> 
> On 22 Mar 2017, at 18:00, David Duncan <david.dun...@apple.com> wrote:
>> 
>> So there was another explanation posted on the bug that I’m not certain you 
>> got, but which I think may explain.
>> 
>> Basically the concept is that since APFS doesn’t normalize file names, if 
>> you store file names in some other storage (say in your preferences) then 
>> what could happen is this:
>> 
>> 10.2: File is saved with a file name handed to the file system in NFC form. 
>> File system converts the file name to NFD. You store it as NFC.
>> 10.3: File system is converted to APFS, and the file name is NFD. You try to 
>> look up the file as NFC, and it fails.
> 
> This is going to cause problems, though, when things migrate from HFS+ to 
> APFS, because the HFS normalisation *isn’t* a standard one.  In particular, 
> it certainly *isn’t* NFD for the current version of Unicode.

Yes, that is the crux of Dave’s issue – HFS+ => APFS only translated the file 
names (from UTF-16 to UTF-8), it did not re-normalize them.

> The only obvious solution for that would be to have the HFS+ to APFS 
> migration tool *re-normalise* the filenames (maybe it does?), but that’s 
> bound to break things in the (presumably quite common) case where the 
> filename stored in e.g. a plist was originally obtained from the filesystem.

Arguably there is no way for the file system converter to know how it should 
renormalize file names. This is akin to case sensitive vs case insensitive file 
systems. If you ran a converter from a case insensitive file system to a case 
sensitive one, you could preserve the capitalization during the conversion, but 
file lookups that used the wrong case would fail after the conversion. But the 
converter can’t know you want to look up “foo” via “FOO” or “Foo” to do any 
kind of normalization. The difference here is that for the most part unicode 
normalization is invisible to the developer.

> 
> Kind regards,
> 
> Alastair.
> 
> --
> http://alastairs-place.net
> 

--
David Duncan


___

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

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

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

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

Re: Unicode filenames with Apple File System and UIManagedDocument

2017-03-06 Thread David Duncan

> On Mar 6, 2017, at 2:05 PM, davel...@mac.com wrote:
> 
>> 
>> On Mar 6, 2017, at 12:37 PM, Chris Ridd <chrisr...@mac.com> wrote:
>> 
>> 
>>> On 6 Mar 2017, at 13:28, davel...@mac.com wrote:
>>> 
>>> I have an iOS app (Attendance2) written in Objective-C. One of my users 
>>> upgraded to the public 10.3 iOS beta and reported he could no longer open 
>>> his documents (I have a subclass of UIManagedDocument so they are Core Data 
>>> files stored in the package/directory format that UIManagedDocument uses). 
>>> I didn’t notice any issues with my test device using the developer beta of 
>>> 10.3. He changed the file names from Arabic to Roman and then he said he 
>>> could open them.
>>> 
>>> Everything I do with NSString is via UTF8 (and it worked fine with Arabic 
>>> letters for this person before updating to the 10.3 beta) so I don’t think 
>>> I’m doing anything wrong.
>>> 
>>> Any suggestions?
>> 
>> If that iOS beta has upgraded the user’s filesystem to APFS, then it may be 
>> an iOS bug that you need to report.
>> 
>> Chris
> 
> I'm assuming the public beta upgraded to APFS (as I believe I read the 
> developer betas upgraded to APFS). I'm trying to figure out if this an Apple 
> bug (i.e., either APFS isn't handling his Arabic filenames correctly or 
> perhaps something went wrong in the upgrade from HFS+ to APFS) or if perhaps 
> it is a bug in my app (I doubt since all I'm doing is taking the NSString 
> they enter and using it as the filename).
> 
> Is there anything else we could try to see which one of those it likely is? 
> I'm going to ask him to create a new file and use an Arabic name and see if 
> that works (i.e., was it just an issue with existing files in Arabic).

I would highly recommend you file a bug that includes enough of your code to 
reproduce the issue now. You can update it later if you determine it is your 
issue.

> 
> Thanks,
> Dave Reed
> 
> 
> ___
> 
> Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)
> 
> Please do not post admin requests or moderator comments to the list.
> Contact the moderators at cocoa-dev-admins(at)lists.apple.com
> 
> Help/Unsubscribe/Update your Subscription:
> https://lists.apple.com/mailman/options/cocoa-dev/david.duncan%40apple.com
> 
> This email sent to david.dun...@apple.com

--
David Duncan

___

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

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

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

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

Re: NSGradient & NSTextField’s focus ring

2017-02-20 Thread David Duncan

> On Feb 20, 2017, at 1:44 PM, Yilei He <lionhy...@gmail.com> wrote:
> 
> My whole view's code:
> import Cocoa
> 
> class GradientBackgroundView: NSView {
> 
> 
> override func draw(_ dirtyRect: NSRect) {
> let gradient = NSGradient(colors: [
> NSColor(calibratedWhite: 0.96, alpha: 1),
> NSColor(calibratedWhite: 0.84, alpha: 1)
> ])
> 
> gradient?.draw(in: dirtyRect, angle: 270)

This is your problem, you need to use the view.bounds here, not the dirtyRect. 
The dirtyRect is a subregion of the bounds that needs to be redrawn, but your 
code is basically doing the equivalent of drawing the entire view into whatever 
dirtyRect you happen to get.

> 
> let path = NSBezierPath()
> path.move(to: NSPoint(x: 0, y: 0))
> path.line(to: NSPoint(x: dirtyRect.maxX, y: 0))
> NSColor.darkGray.setStroke()
> path.stroke()
> }
> 
> }
> 
> Cheers
> Yilei He
> 
> On 21 Feb 2017, 04:18 +1100, David Duncan <david.dun...@apple.com>, wrote:
>> 
>>> On Feb 20, 2017, at 2:41 AM, Yilei He <lionhy...@gmail.com> wrote:
>>> 
>>> Hi
>>> 
>>> In my UI design, I have a custom NSView which only draws a NSGradient in 
>>> draw(in:) method. I also have a NSTextField next to this custom view. Every 
>>> time when text field is focused, the focus ring animates and leave a set of 
>>> mark(animation tracks) on the custom view.
>> 
>> Can you share your draw(in:) implementation?
>> 
>>> 
>>> After I tested this for a while, I found that the focus ring only leaves 
>>> marks on gradient.
>>> 
>>> Can anyone give a solution to remove the mark?
>>> 
>>> Thanks
>>> Yilei He
>>> 
>>> 
>>> ___
>>> 
>>> Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)
>>> 
>>> Please do not post admin requests or moderator comments to the list.
>>> Contact the moderators at cocoa-dev-admins(at)lists.apple.com
>>> 
>>> Help/Unsubscribe/Update your Subscription:
>>> https://lists.apple.com/mailman/options/cocoa-dev/david.duncan%40apple.com
>>> 
>>> This email sent to david.dun...@apple.com
>> 
>> --
>> David Duncan
>> 

--
David Duncan


___

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

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

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

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


Re: NSGradient & NSTextField’s focus ring

2017-02-20 Thread David Duncan

> On Feb 20, 2017, at 2:41 AM, Yilei He <lionhy...@gmail.com> wrote:
> 
> Hi
> 
> In my UI design, I have a custom NSView which only draws a NSGradient in 
> draw(in:) method. I also have a NSTextField next to this custom view. Every 
> time when text field is focused, the focus ring animates and leave a set of 
> mark(animation tracks) on the custom view.

Can you share your draw(in:) implementation?

> 
> After I tested this for a while, I found that the focus ring only leaves 
> marks on gradient.
> 
> Can anyone give a solution to remove the mark?
> 
> Thanks
> Yilei He
> 
> 
> ___
> 
> Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)
> 
> Please do not post admin requests or moderator comments to the list.
> Contact the moderators at cocoa-dev-admins(at)lists.apple.com
> 
> Help/Unsubscribe/Update your Subscription:
> https://lists.apple.com/mailman/options/cocoa-dev/david.duncan%40apple.com
> 
> This email sent to david.dun...@apple.com

--
David Duncan


___

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

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

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

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


Re: UINavigationBar content margins in UIPresentationController subclass

2017-01-03 Thread David Duncan
The most relevant looking bug I can find seems to involve pushing & popping 
view controllers. That said, setting the preferredContentSize on the navigation 
controller directly should always work.

Alternatively you could use your own container view controller instead.

> On Dec 7, 2016, at 10:42 AM, Daniel Stenmark <dstenm...@opentable.com> wrote:
> 
> Thanks, David.  Unfortunately, UINavigationController isn’t currently an 
> option as it doesn’t reliably bubble up preferredContentSize changes, which 
> we have a strong dependency on and is fairly dynamic in our use case.  As of 
> 10.0, it only seems to adapt and forward the very first preferredContentSize 
> mutation, silencing the rest.  I’ve been told this is currently filed as a 
> Radar (though, if you can confirm that’s NOT the case, I’d be more than happy 
> to file a new one!).
> 
> Is there another way I can work around this limitation in the meantime?
> 
> Dan
> 
>> On Dec 7, 2016, at 10:35 AM, David Duncan <david.dun...@apple.com 
>> <mailto:david.dun...@apple.com>> wrote:
>> 
>> 
>>> On Dec 7, 2016, at 10:28 AM, Daniel Stenmark <dstenm...@opentable.com 
>>> <mailto:dstenm...@opentable.com>> wrote:
>>> 
>>> The UINavigationBar is in the UIPresentationController’s containerView, 
>>> which is a subview of the current UIWindow and does NOT have a view 
>>> controller in its hierarchy.  Is there a particular reason for 
>>> UINavigationBar to have this dependency for correct layout?  Is there a 
>>> ‘right’ way to work around this aside from manual/artificial padding?
>> 
>> Only view controllers know the proper calculation for the padding to be used 
>> by the bars. Typically a solution to your issue would be to wrap the 
>> presenting view controller in a UINavigationController rather than making 
>> the navigation bar part of the presentation itself.
>> 
>>> 
>>> Dan
>>> 
>>>> On Dec 7, 2016, at 10:01 AM, David Duncan <david.dun...@apple.com 
>>>> <mailto:david.dun...@apple.com>> wrote:
>>>> 
>>>> Its unclear to me at least, but where in the view hierarchy is the 
>>>> UINavigationBar? If it isn’t in a view that is ultimately backed by a view 
>>>> controller, then it won’t have the correct information to do its layout.
>>>> 
>>>>> On Nov 7, 2016, at 12:42 PM, Daniel Stenmark <dstenm...@opentable.com 
>>>>> <mailto:dstenm...@opentable.com>> wrote:
>>>>> 
>>>>> I have a UIPresentationController subclass with a UINavigationBar 
>>>>> embedded in the container view.  However, when setting the 
>>>>> rightBarButtonItem, the spacing I usually expect from the item to the 
>>>>> screen isn't there.
>>>>> 
>>>>> http://imgur.com/LHcqhyd<http://imgur.com/a/610al> 
>>>>> <http://imgur.com/LHcqhyd%3Chttp://imgur.com/a/610al%3E>
>>>>> 
>>>>> Anyone have an idea where I might be going wrong here?  The relevant code 
>>>>> for the presentation controller is as follows:
>>>>> 
>>>>> @objc public protocol SheetPresentationControllerDelegate : class {
>>>>>   func sheetPresentationControllerWillDismiss(_ 
>>>>> sheetPresentationController: SheetPresentationController)
>>>>> }
>>>>> 
>>>>> open class SheetPresentationController: UIPresentationController {
>>>>> 
>>>>> 
>>>>> 
>>>>>   fileprivate let dimmedView: UIView = {
>>>>>   let result = UIView()
>>>>>   result.backgroundColor = .black
>>>>>   result.alpha = 0
>>>>>   result.autoresizingMask = [.flexibleWidth, .flexibleHeight]
>>>>>   return result
>>>>>   }()
>>>>> 
>>>>> 
>>>>> 
>>>>>   fileprivate let topView: UIView = {
>>>>>   let result = UIView()
>>>>>   result.backgroundColor = .white
>>>>>   return result
>>>>>   }()
>>>>> 
>>>>> 
>>>>> 
>>>>>   fileprivate let navigationBar: UINavigationBar = {
>>>>>   let result = UINavigationBar()
>>>>>   result.backgroundColor = .white
>>>>>   result.items = [UINavigationItem()]
>>>>>   return result
>>>>>   }()
>>>>> 
>>>>> 
>>>

Re: Animating autolayout constraint changes for subviews

2016-12-30 Thread David Duncan

> On Dec 30, 2016, at 11:50 AM, Doug Hill <cocoa...@breaqz.com> wrote:
> 
> 
>> On Dec 30, 2016, at 11:38 AM, David Duncan <david.dun...@apple.com> wrote:
>> 
>> 
>>> On Dec 28, 2016, at 4:14 PM, Doug Hill <cocoa...@breaqz.com> wrote:
>>> 
>>> Hi Ken,
>>> 
>>> The exact behavior is that the label will resize to the new size 
>>> immediately and reflow the text, then the container view will animate it's 
>>> size change. It would be nice if both the label and the container view 
>>> animate at the same time.
>>> Also, as I mentioned, a button will exhibit the same behavior, probably 
>>> because it has a UILabel inside it to show the button text.
>> 
>> Labels (and other content provided via -drawRect:) will almost universally 
>> behave this way without additional work on your part, as the content is 
>> redrawn instantly at the final size. At best you might get an animation 
>> where the content resizes into place, but more often than not, it will pop 
>> in some undesirable way. Generally the only way to get good animations with 
>> drawn content is to snapshot in some way and execute an custom animation 
>> from the old to the new content (snapshotting isn’t necessarily literal here 
>> – it can just mean creating a new label with the new content as one example).
> 
> David,
> 
> Thanks for the info. I’m curious what system views with content are 
> animatable. I guess UIImageView works for the snapshots. But anything with a 
> label is out. I’ll do some tests and see what works.

They are all “animatable”, but the results are not necessarily well defined. 
Most system controls use combinations of image views and labels for images and 
text content, so the resizing animations are often going to be based on how 
-drawRect: content resizes.

> 
> Doug Hill

--
David Duncan


___

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

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

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

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

Re: Animating autolayout constraint changes for subviews

2016-12-30 Thread David Duncan

> On Dec 28, 2016, at 4:14 PM, Doug Hill <cocoa...@breaqz.com> wrote:
> 
> Hi Ken,
> 
> I uploaded a sample project here:
> 
> https://github.com/djfitz/TestAutolayoutAnimations
> 
> I tried to strip this down to what is needed to show the behavior I see.
> 
> My code to actually do the animation is this:
> 
> - (IBAction)animateIt:(id)sender
> {
>   static BOOL small = NO;
> 
>   if( small )
>   {
>   [self.view layoutIfNeeded];
> 
>   self.containerWidthConstraint.constant = 
> self.view.frame.size.width;
> 
>   [UIView animateWithDuration:1 animations:
>   ^{
>   [self.view layoutIfNeeded];
>   }];
>   }
>   else
>   {
>   [self.view layoutIfNeeded];
> 
>   self.containerWidthConstraint.constant = 
> self.view.frame.size.width / 2;
> 
>   [UIView animateWithDuration:1 animations:
>   ^{
>   [self.view layoutIfNeeded];
>   }];
>   }
> 
>   small = !small;
> }
> 
> 'container view' has one subview which is a UILabel. The label is pinned to 
> the superview edges via autolayout constraints. (e.g. trailing, leading, top, 
> bottom edges all pinned to superview edges.)
> 
> I tried a few different variations, including leaving out the first 
> layoutIfNeeded (which some people say should be done, others not).
> 
> The exact behavior is that the label will resize to the new size immediately 
> and reflow the text, then the container view will animate it's size change. 
> It would be nice if both the label and the container view animate at the same 
> time.
> Also, as I mentioned, a button will exhibit the same behavior, probably 
> because it has a UILabel inside it to show the button text.

Labels (and other content provided via -drawRect:) will almost universally 
behave this way without additional work on your part, as the content is redrawn 
instantly at the final size. At best you might get an animation where the 
content resizes into place, but more often than not, it will pop in some 
undesirable way. Generally the only way to get good animations with drawn 
content is to snapshot in some way and execute an custom animation from the old 
to the new content (snapshotting isn’t necessarily literal here – it can just 
mean creating a new label with the new content as one example).

> 
> Thanks again for any ideas.
> 
> Doug Hill
> 
> 
>> On Dec 28, 2016, at 12:50 PM, Ken Thomases <k...@codeweavers.com> wrote:
>> 
>> On Dec 28, 2016, at 1:55 PM, Doug Hill <cocoa...@breaqz.com> wrote:
>>> 
>>> I can now animate my constraint changes but I notice that subviews aren't 
>>> animated. For example, I have a single view with a width constraint, and 
>>> this view has a label as a subview that expands to the size of it's parent 
>>> view via edge constraints.
>>> I can change the width constraint constant of the parent view at runtime 
>>> and it animates very well. However, the subviews jump into place 
>>> immediately then the parent view animates into place. I see the same 
>>> behavior with a button as a subview.
>> 
>> Show exactly how you're animating the constraint changes.  Are you really 
>> animating the change of the constraint or are you doing a layoutIfNeeded 
>> within an animation context?  Even if the former, are you calling any 
>> methods that force layout (layoutIfNeeded or similar)?  If so, where/when?
>> 
>> 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:
> https://lists.apple.com/mailman/options/cocoa-dev/david.duncan%40apple.com
> 
> This email sent to david.dun...@apple.com

--
David Duncan


___

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

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

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

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

Re: My app only shows a black screen in the recent apps list

2016-12-30 Thread David Duncan

> On Dec 27, 2016, at 3:52 AM, Andreas Falkenhahn <andr...@falkenhahn.com> 
> wrote:
> 
> On 25.12.2016 at 16:57 David Duncan wrote:
> 
>>> On Dec 23, 2016, at 9:05 AM, Andreas Falkenhahn <andr...@falkenhahn.com> 
>>> wrote:
> 
>>> Further examinations have shown that the issue might be related to the
>>> fact that my app has the "UIApplicationExitsOnSuspend" flag set to YES.
>>> When removing this flag, it seems to work correctly. When activating it
>>> again, however, iOS shows the image from the last run of the app with
>>> "UIApplicationExitsOnSuspend" set to NO. Really does smell like an iOS
>>> bug.
> 
>> This is actually probably the expected behavior in that case, and
>> all due to the fact that the app *exits* when you leave it.
> 
> I'm not sure. As I said, it also happens quite often that the image alternates
> when just browsing through the recent apps list. Sometimes the launch image is
> shown, sometimes a screenshot - but without me leaving the recent apps list!

This is rather the nature of undefined behavior though – when in the task 
switcher we try to update your image, but may suspend the application at some 
point. But since you aren’t necessarily in the background, we may not *kill* 
the application. The application being unable to respond in time for a snapshot 
is what may result in the snapshot behaving oddly, and a suspended application 
may not respond in a timely fashion.

> This is really weird behaviour. I close my app, wait 10 seconds so that it
> is really gone and then open the recent apps list and browse through it:
> Sometimes the launch image is shown for my app, sometimes a screenshot,
> in one and the same instance of the recent apps list, i.e. without exiting
> the recent apps list and reopening it again. That doesn't really make sense 
> to me…

Honestly, just remove UIApplicationExistsOnSuspend. Its simply not a behavior 
that is expected of modern iOS applications.
--
David Duncan


___

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

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

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

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

Re: My app only shows a black screen in the recent apps list

2016-12-25 Thread David Duncan

> On Dec 23, 2016, at 9:05 AM, Andreas Falkenhahn <andr...@falkenhahn.com> 
> wrote:
> 
> Further examinations have shown that the issue might be related to the
> fact that my app has the "UIApplicationExitsOnSuspend" flag set to YES.
> When removing this flag, it seems to work correctly. When activating it
> again, however, iOS shows the image from the last run of the app with
> "UIApplicationExitsOnSuspend" set to NO. Really does smell like an iOS
> bug.

This is actually probably the expected behavior in that case, and all due to 
the fact that the app *exits* when you leave it.

Basically because your app is exiting, you are racing against the OS’s ability 
to snapshot it. That snapshot does not happen within your process, so sometimes 
we capture what is there when you suspend (we snapshot before you exit) and 
sometimes black (you exist before we snapshot). Sometimes we detect this and 
can go back to your launch image, but not always.

But the practical reality is that ExitOnSuspend is really not the expected path 
for new applications, but rather a compatibility path for old ones. I would 
recommend against using it in new applications both because it goes against the 
design of the OS (that apps are always “there” and their lifetime is managed by 
the system) and because it goes against user expectation (that you can task 
switch quickly and come back to the app exactly as it was).

> 
> On 23.12.2016 at 14:35 Andreas Falkenhahn wrote:
> 
>> On 22.12.2016 at 21:58 David Duncan wrote:
> 
>>> Do you do anything special when going into the background? The
>>> snapshot is taken shortly after your application is placed in the
>>> background, so if your view hierarchy changes that is what will actually be 
>>> snapshotted.
> 
>> No, I'm actually not doing anything when the app is shutdown. All
>> respective delegate methods are completely empty. I should add
>> that the actual drawing is done by a worker thread, but of course
>> this thread calls dispatch_sync() when exchanging the layer's
>> contents to the new image, e.g.
> 
>> dispatch_sync(dispatch_get_main_queue(), ^{
>> myView.layer.contents = (id) myImage;
>> });
> 
>> So it could probably happen that this code is executed even after
>> iOS runs methods like applicationWillResignActive() but certainly
>> not at the same time because I use dispatch_sync() to change the
>> layer's contents on the main thread.
> 
>> Upon closer observation, the behaviour is actually really strange.
>> Now that I've added launch images (not a storyboard) the black screen
>> is gone but the launch image is shown instead. But not always!
>> Sometimes there's also a snapshot of my app. And what makes the
>> confusion complete is the fact that iOS sometimes even alternates (!)
>> between those two images when cycling through the recent apps list,
>> e.g. when cycling through the recent apps list by swiping to the left
>> my app shows the launch image. Then, without leaving the recent
>> apps list, I'm cycling through the list again, but this time by swiping
>> to the right, and suddenly my app shows the correct snapshot from
>> the last frame it drew! This is really confusing. Smells like an
>> iOS bug to me because why would it alternate between the launch image
>> and a snapshot without me ever leaving the recent apps list? 
> 
> 
> 
> -- 
> Best regards,
> Andreas Falkenhahnmailto:andr...@falkenhahn.com
> 

--
David Duncan


___

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

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

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

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

Re: My app only shows a black screen in the recent apps list

2016-12-22 Thread David Duncan
Inline

--
David Duncan @ My iPhone

> On Dec 22, 2016, at 4:49 PM, Alex Zavatone <z...@mac.com> wrote:
> 
> In that case, would it make sense when the app will enter background, to take 
> a snapshot of the main window, then put that image layer  over your main 
> window so that you can guarantee that the image you desire is what the OS 
> will take a snapshot of?

In this case the desired image is whatever was last displayed if I understand 
Andreas correctly. So the real question is what prevents that from displaying.
> 
> I like this approach because it is very easy to QA.  You can output the image 
> to a known file and you can see exactly what image should be captured by the 
> OS.  
> 
> Then when the app will enter foreground, set the hidden of that layer to YES 
> and void the contents.
> 
> Even if you don't use this approach, it may be helpful in seeing why the OS 
> is taking a lovely black image instead of the one you desire.  You could even 
> create a new window that holds this image and which is only displayed when 
> the app is about to enter the background and is dismissed when i comes back.
> 
> Andreas, I am suspecting that the custom CGImage code might be causing this 
> by getting in the way of what the OS expects.  What format does the OS 
> require before taking the screenshot?

Unlikely. If you can see it onscreen, the OS can capture it. It has more 
privileges than you do :). 

The technique Andreas is using is basically the same one UIImageView uses so it 
should be petty robust. 

>  Maybe making sure that the OS can access your custom view's image content in 
> the format it expects is what would fix this.  (I'm expecting you're on iOS), 
> can you make a UIimage from your window's top level view that is a 
> viewController and put it in a UIImageView using imageWithCGImage?  If you 
> can, is it black?  The CGImage is the underlying Quartz image data, not an 
> image to itself.   Also, what about the context, is it in the middle of 
> drawing?   Is there a way to access the CGImageRef of what you're drawing?  
> 
> CGImageRef cgImage = CGBitmapContextCreateImage(context);
> 
> Apologies if I'm rambling.  I'm tragically low on coffee.
> 
> Cheers,
> - Alex Zavatone
> 
>> On Dec 22, 2016, at 2:58 PM, David Duncan wrote:
>> 
>> Do you do anything special when going into the background? The snapshot is 
>> taken shortly after your application is placed in the background, so if your 
>> view hierarchy changes that is what will actually be snapshotted.
>> 
>>> On Dec 22, 2016, at 4:05 AM, Andreas Falkenhahn <andr...@falkenhahn.com> 
>>> wrote:
>>> 
>>> When opening the recent apps list by pressing the home button twice
>>> my app only shows a black screen instead of an image of the app's
>>> look the last time it was closed. How can I fix this?
>>> 
>>> My app's view hierarchy is Window => ViewController.View => ContentView.
>>> The graphics are drawn by a platform-independent renderer into a
>>> pixel buffer which is then converted into CGImage which is then
>>> set as the content view's layer for every new frame like this:
>>> 
>>>   contentView.layer.contents = (id) myImage;
>>> 
>>> This works fine but in the recent apps list my app is always just
>>> shown as a black screen which is rather ugly. How can I fix this
>>> please?
>>> 
>>> -- 
>>> Best regards,
>>> Andreas Falkenhahn  mailto:andr...@falkenhahn.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:
>>> https://lists.apple.com/mailman/options/cocoa-dev/david.duncan%40apple.com
>>> 
>>> This email sent to david.dun...@apple.com
>> 
>> --
>> David Duncan
>> 
>> 
>> ___
>> 
>> Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)
>> 
>> Please do not post admin requests or moderator comments to the list.
>> Contact the moderators at cocoa-dev-admins(at)lists.apple.com
>> 
>> Help/Unsubscribe/Update your Subscription:
>> https://lists.apple.com/mailman/options/cocoa-dev/zav%40mac.com
>> 
>> This email sent to z...@mac.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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

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


Re: My app only shows a black screen in the recent apps list

2016-12-22 Thread David Duncan
Do you do anything special when going into the background? The snapshot is 
taken shortly after your application is placed in the background, so if your 
view hierarchy changes that is what will actually be snapshotted.

> On Dec 22, 2016, at 4:05 AM, Andreas Falkenhahn <andr...@falkenhahn.com> 
> wrote:
> 
> When opening the recent apps list by pressing the home button twice
> my app only shows a black screen instead of an image of the app's
> look the last time it was closed. How can I fix this?
> 
> My app's view hierarchy is Window => ViewController.View => ContentView.
> The graphics are drawn by a platform-independent renderer into a
> pixel buffer which is then converted into CGImage which is then
> set as the content view's layer for every new frame like this:
> 
> contentView.layer.contents = (id) myImage;
> 
> This works fine but in the recent apps list my app is always just
> shown as a black screen which is rather ugly. How can I fix this
> please?
> 
> -- 
> Best regards,
> Andreas Falkenhahn  mailto:andr...@falkenhahn.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:
> https://lists.apple.com/mailman/options/cocoa-dev/david.duncan%40apple.com
> 
> This email sent to david.dun...@apple.com

--
David Duncan


___

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

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

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

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


Re: Is it safe to assume that viewDidLoad() is only ever called once on iOS 8.0+?

2016-12-19 Thread David Duncan

> On Dec 18, 2016, at 2:51 AM, Andreas Falkenhahn <andr...@falkenhahn.com> 
> wrote:
> 
> I do not use Interface Builder or Storyboards to create my GUI
> but I do it manually. Currently, I'm setting up all controls
> in viewDidLoad() of my UIViewController.
> 
> So I'm doing stuff like this in viewDidLoad():
> 
>UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
>...
>[self.view addSubview:button];
> 
> The actual positioning is then done in viewDidLayoutSubviews(),
> depending on the device's orientation.
> 
> According to my research, iOS versions before v6 purged views
> on low-memory conditions but AFAIU this is no longer done starting
> with v6. My app targets iOS 8.0 and up so can I rely on viewDidLoad()
> being called only once?
> 
> The reason why I'm asking is that I retain some controls in
> viewDidLoad() because I need them later. I release those controls
> in dealloc(). Now, if viewDidLoad() could be called more than
> once, I'd leak memory. But since viewDidUnload() is deprecated
> anyway, I think it is safe to assume viewDidLoad() is only called
> once because otherwise Apple would have to provide viewDidUnload()
> as well... but still, I'd be glad if somebody could just confirm
> my observations. Thanks.

Assuming you never set a view controller’s view to nil, it is safe to assume 
that viewDidLoad is always called no more than once per view controller 
instance.

> 
> -- 
> Best regards,
> Andreas Falkenhahn  mailto:andr...@falkenhahn.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:
> https://lists.apple.com/mailman/options/cocoa-dev/david.duncan%40apple.com
> 
> This email sent to david.dun...@apple.com

--
David Duncan


___

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

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

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

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

Re: Releasing modal view controller properly

2016-12-17 Thread David Duncan

> On Dec 17, 2016, at 8:07 AM, Andreas Falkenhahn <andr...@falkenhahn.com> 
> wrote:
> 
> I'm not using ARC so I need to take care of releasing objects manually.
> I'm creating and presenting a modal UIViewController like this:
> 
>MyViewController *vc = [[MyViewController alloc] init];
> 
>vc.modalPresentationStyle = UIModalPresentationFormSheet;
>vc.preferredContentSize = CGRectMake(320, 320);
> 
>[self presentViewController:vc animated:YES completion:nil]
>[vc release];
> 
> When touching the modal view's close button my code does the following:
> 
>[[self presentingViewController] dismissViewControllerAnimated:YES 
> completion:nil];
> 
> Unfortunately, the app crashes right after the modal view has completed
> its transition animation.
> 
> When I disable the line "[vc release]", I don't get any crashes and it
> works fine. Can anybody explain why? I was expecting that 
> presentViewController()
> retained the view controller so that it is safe for me to release it
> right after making the call to presentViewController() because I don't
> need it any longer but apparently, there's something wrong in my code
> but I don't see it…

The code you’ve presented is fine, so the issue is likely to be elsewhere.

> 
> -- 
> Best regards,
> Andreas Falkenhahn  mailto:andr...@falkenhahn.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:
> https://lists.apple.com/mailman/options/cocoa-dev/david.duncan%40apple.com
> 
> This email sent to david.dun...@apple.com

--
David Duncan


___

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

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

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

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

Re: Accessing pointer structure members inside block function

2016-12-13 Thread David Duncan

> On Dec 13, 2016, at 8:20 AM, Andreas Falkenhahn <andr...@falkenhahn.com> 
> wrote:
> 
> What is the recommended way of accessing pointer structure members inside
> a block function?
> 
> Consider the following code:
> 
>obj->width = 320;
>obj->height = 240;
> 
>dispatch_async(dispatch_get_main_queue(), ^{
>printf("WIDTH: %d HEIGHT: %d\n", obj->width, obj->height);
>});
> 
>obj->width = 640;
>obj->height = 480;
> 
> I *always* want the block function to use the variable values at the
> time of the *declaration* of the block function, not at the time of
> its execution, i.e. obj->width and ->height should always be 320 and 240,
> respectively, in the block function above.
> 
> What is the recommended way of doing this? Should I just assign them
> to temporary variables whose values are never changed, e.g.
> 
>obj->width = 320;
>obj->height = 240;
> 
>tmpwidth = obj->width;
>tmpheight = obj->height;
> 
>dispatch_async(dispatch_get_main_queue(), ^{
>printf("WIDTH: %d HEIGHT: %d\n", tmpwidth, tmpheight);
>});
> 
>obj->width = 640;
>obj->height = 480;
> 
> Or is there a nicer solution? I'm asking because the temporary variable
> solution can become quite ugly if there are many variables…

You would need to assign them to some temporary. Keep in mind that you are 
capturing a pointer here and with all pointers, nothing stops the backing 
memory from changing. That said, assuming your struct is amenable, your 
solution doesn’t necessarily need to look that bad, such as:

typeof(*obj) copy = *obj;
dispatch_async(… ^{
print(…, copy.width, copy.height)
}

> 
> -- 
> Best regards,
> Andreas Falkenhahn  mailto:andr...@falkenhahn.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:
> https://lists.apple.com/mailman/options/cocoa-dev/david.duncan%40apple.com
> 
> This email sent to david.dun...@apple.com

--
David Duncan


___

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

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

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

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

Re: UINavigationBar content margins in UIPresentationController subclass

2016-12-07 Thread David Duncan

> On Dec 7, 2016, at 11:22 AM, Daniel Stenmark <dstenm...@opentable.com> wrote:
> 
>> The most relevant looking bug I can find seems to involve pushing & popping 
>> view controllers. That said, setting the preferredContentSize on the 
>> navigation controller directly should always work.
> 
> Setting preferredContentSize directly on the navigation controller works as 
> expected.  I’m more referring to the ability for navigation controllers to 
> catch the preferredContentSize changes of their child controllers, and then 
> use that observed size to automatically update their own preferredContentSize 
> (which I’d expect would just add the height of the navigation controller’s 
> UINavigationBar to the child’s observed size).  Is that expected to work 
> (i.e. is there currently a bug), or is the current lack of 
> preferredContentSize forwarding by design?

The only bug I’ve found is basically “navigation controller’s preferred content 
size will never shrink”. If that isn’t what you are seeing, you should file 
your own bug.

> 
>> Alternatively you could use your own container view controller instead.
> 
> Hmm, interesting.  Are you suggesting that the presentation controller have 
> view controller property, add the view controller’s root view to the 
> presentation controller’s container view, and then do all the presentation 
> work in the view controller’s root view?

You would basically do the same thing you might otherwise do if you were using 
a UINavigationController – wrap your view controller in your container and go 
from there. If the only reason you needed presentation is for the navigation 
bar, then you wouldn’t need presentation controllers at all at that point.

> 
> Dan

--
David Duncan

___

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

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

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

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

Re: UINavigationBar content margins in UIPresentationController subclass

2016-12-07 Thread David Duncan

> On Dec 7, 2016, at 10:28 AM, Daniel Stenmark <dstenm...@opentable.com> wrote:
> 
> The UINavigationBar is in the UIPresentationController’s containerView, which 
> is a subview of the current UIWindow and does NOT have a view controller in 
> its hierarchy.  Is there a particular reason for UINavigationBar to have this 
> dependency for correct layout?  Is there a ‘right’ way to work around this 
> aside from manual/artificial padding?

Only view controllers know the proper calculation for the padding to be used by 
the bars. Typically a solution to your issue would be to wrap the presenting 
view controller in a UINavigationController rather than making the navigation 
bar part of the presentation itself.

> 
> Dan
> 
>> On Dec 7, 2016, at 10:01 AM, David Duncan <david.dun...@apple.com 
>> <mailto:david.dun...@apple.com>> wrote:
>> 
>> Its unclear to me at least, but where in the view hierarchy is the 
>> UINavigationBar? If it isn’t in a view that is ultimately backed by a view 
>> controller, then it won’t have the correct information to do its layout.
>> 
>>> On Nov 7, 2016, at 12:42 PM, Daniel Stenmark <dstenm...@opentable.com 
>>> <mailto:dstenm...@opentable.com>> wrote:
>>> 
>>> I have a UIPresentationController subclass with a UINavigationBar embedded 
>>> in the container view.  However, when setting the rightBarButtonItem, the 
>>> spacing I usually expect from the item to the screen isn't there.
>>> 
>>> http://imgur.com/LHcqhyd<http://imgur.com/a/610al> 
>>> <http://imgur.com/LHcqhyd%3Chttp://imgur.com/a/610al%3E>
>>> 
>>> Anyone have an idea where I might be going wrong here?  The relevant code 
>>> for the presentation controller is as follows:
>>> 
>>> @objc public protocol SheetPresentationControllerDelegate : class {
>>>   func sheetPresentationControllerWillDismiss(_ 
>>> sheetPresentationController: SheetPresentationController)
>>> }
>>> 
>>> open class SheetPresentationController: UIPresentationController {
>>> 
>>> 
>>> 
>>>   fileprivate let dimmedView: UIView = {
>>>   let result = UIView()
>>>   result.backgroundColor = .black
>>>   result.alpha = 0
>>>   result.autoresizingMask = [.flexibleWidth, .flexibleHeight]
>>>   return result
>>>   }()
>>> 
>>> 
>>> 
>>>   fileprivate let topView: UIView = {
>>>   let result = UIView()
>>>   result.backgroundColor = .white
>>>   return result
>>>   }()
>>> 
>>> 
>>> 
>>>   fileprivate let navigationBar: UINavigationBar = {
>>>   let result = UINavigationBar()
>>>   result.backgroundColor = .white
>>>   result.items = [UINavigationItem()]
>>>   return result
>>>   }()
>>> 
>>> 
>>> 
>>>   open var title: String? {
>>>   get {
>>>   return self.navigationBar.topItem?.title
>>>   }
>>>   set {
>>>   self.navigationBar.topItem?.title = newValue
>>>   }
>>>   }
>>> 
>>> 
>>> 
>>>   open var titleView: UIView? {
>>>   get {
>>>   return self.navigationBar.topItem?.titleView
>>>   }
>>>   set {
>>>   self.navigationBar.topItem?.titleView = newValue
>>>   }
>>>   }
>>> 
>>> 
>>> 
>>>   open weak var sheetDelegate: SheetPresentationControllerDelegate?
>>> 
>>> 
>>> 
>>>   fileprivate dynamic func dismiss(_ sender: NSObject) {
>>>   self.presentingViewController.dismiss(animated: true, completion: nil)
>>>   }
>>> 
>>> 
>>> 
>>>   override open func presentationTransitionWillBegin() {
>>>   super.presentationTransitionWillBegin()
>>> 
>>> 
>>> 
>>>   guard let containerView = self.containerView else {
>>>   return
>>>   }
>>> 
>>> 
>>> 
>>>   containerView.addSubview(self.dimmedView)
>>>   self.dimmedView.frame = CGRect(origin: .zero, size: 
>>> containerView.bounds.size)
>>> 
>>> 
>>> 
>>>   let gestureRecognizer = UITapGestureRecognizer(target: self, action: 
>>> #selector(dismiss))
>>>   self.dimmedView.addGestureRecognizer(gestureRecognizer)
>>> 
>>> 
>>> 
>>

Re: UINavigationBar content margins in UIPresentationController subclass

2016-12-07 Thread David Duncan
ainerView?.bounds.width ?? 0, 
> height: self.navigationBar.intrinsicContentSize.height)
> 
> 
> 
>self.presentedView?.frame = self.frameOfPresentedViewInContainerView
>}
> }
> 
> Dan
> ___
> 
> Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)
> 
> Please do not post admin requests or moderator comments to the list.
> Contact the moderators at cocoa-dev-admins(at)lists.apple.com
> 
> Help/Unsubscribe/Update your Subscription:
> https://lists.apple.com/mailman/options/cocoa-dev/david.duncan%40apple.com
> 
> This email sent to david.dun...@apple.com

--
David Duncan


___

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

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

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

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

Re: iOS 9: Adding CALayer to self.view.layer causes EXC_BAD_ACCESS

2016-12-06 Thread David Duncan

> On Dec 6, 2016, at 11:51 AM, Doug Hill <cocoa...@breaqz.com> wrote:
> 
> I've wondered about this before, but maybe some Objective-C runtime experts 
> know.
> 
> Does writing directly to the ivar backing a property bypass the ARC features 
> of the property. For example, will a strong property be retained if you write 
> directly to the ivar?

Yes, under ARC assigning to a strong ivar and assigning via a strong property 
are identical with respect to the resulting retain count semantics (otherwise 
typically constructed ARC-based setter methods wouldn’t work).

> 
> If not, that's your problem.
> 
> Doug
> 
>> On Dec 6, 2016, at 11:44 AM, Carl Hoefs <newsli...@autonomy.caltech.edu 
>> <mailto:newsli...@autonomy.caltech.edu>> wrote:
>> 
>> I get the following crash in my iOS 9 app simply by adding a CALayer to the 
>> current view controller's self.view.layer and then dismissing the current 
>> view controller. Simplified code:
>> 
>>   @property (strong,nonatomic) CALayer *layer;
>>   .  .  .
>>   _layer = [[CALayer alloc] init];
>>   [_layer setDelegate: self];
>>   [self.view.layer addSublayer:_layer];
>> 
>> Upon dismissing the VC:
>> 
>>   [self dismissViewControllerAnimated:YES completion:nil];
>> 
>> The following exception occurs:
>> 
>> (lldb) bt
>> * thread #1: tid = 0x121bd, 0x22c2c68a libobjc.A.dylib`objc_retain + 10, 
>> queue = 'com.apple.main-thread', stop reason = EXC_BAD_ACCESS (code=1, 
>> address=0xb010)
>>   frame #0: 0x22c2c68a libobjc.A.dylib`objc_retain + 10
>>   frame #1: 0x27a2a22a UIKit`-[UIView(Hierarchy) subviews] + 330
>>   frame #2: 0x27b3e1ea UIKit`discardEngineRecursive + 118
>>   frame #3: 0x27a2fd06 UIKit`-[UIView dealloc] + 630
>>   frame #4: 0x2336cd98 CoreFoundation`-[__NSDictionaryM dealloc] + 132
>>   frame #5: 0x22c2cf8a libobjc.A.dylib`objc_object::sidetable_release(bool) 
>> + 150
>>   frame #6: 0x22c2d3cc libobjc.A.dylib`(anonymous 
>> namespace)::AutoreleasePoolPage::pop(void*) + 388
>>   frame #7: 0x23363f30 CoreFoundation`_CFAutoreleasePoolPop + 16
>>   frame #8: 0x23415c56 CoreFoundation`__CFRunLoopRun + 1598
>>   frame #9: 0x233641c8 CoreFoundation`CFRunLoopRunSpecific + 516
>>   frame #10: 0x23363fbc CoreFoundation`CFRunLoopRunInMode + 108
>>   frame #11: 0x24980af8 GraphicsServices`GSEventRunModal + 160
>>   frame #12: 0x27a9c434 UIKit`UIApplicationMain + 144
>> * frame #13: 0x001b655e ProteinFold`main(argc=1, argv=0x0043bbc8) + 122 at 
>> main.m:14
>> 
>> If I remove the CALayer first before the 
>> -dismissViewControllerAnimated:completion:, it doesn't crash:
>> 
>>   [layer removeFromSuperlayer];
>> 
>> Why do I need to explicitly remove my added CALayer before dismissing the 
>> VC? Note: If I declare layer as weak, the crash does not occur, but neither 
>> does the layer display onscreen.
>> -Carl
>> 
>> 
>> ___
>> 
>> Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)
>> 
>> Please do not post admin requests or moderator comments to the list.
>> Contact the moderators at cocoa-dev-admins(at)lists.apple.com
>> 
>> Help/Unsubscribe/Update your Subscription:
>> https://lists.apple.com/mailman/options/cocoa-dev/cocoadev%40breaqz.com 
>> <https://lists.apple.com/mailman/options/cocoa-dev/cocoadev%40breaqz.com>
>> 
>> This email sent to cocoa...@breaqz.com <mailto:cocoa...@breaqz.com>
> 
> 
> ___
> 
> Cocoa-dev mailing list (Cocoa-dev@lists.apple.com 
> <mailto: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 
> <http://lists.apple.com/>
> 
> Help/Unsubscribe/Update your Subscription:
> https://lists.apple.com/mailman/options/cocoa-dev/david.duncan%40apple.com 
> <https://lists.apple.com/mailman/options/cocoa-dev/david.duncan%40apple.com>
> 
> This email sent to david.dun...@apple.com <mailto:david.dun...@apple.com>
--
David Duncan

___

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

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

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

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

Re: iOS 9: Adding CALayer to self.view.layer causes EXC_BAD_ACCESS

2016-12-06 Thread David Duncan

> On Dec 6, 2016, at 11:44 AM, Carl Hoefs <newsli...@autonomy.caltech.edu> 
> wrote:
> 
> I get the following crash in my iOS 9 app simply by adding a CALayer to the 
> current view controller's self.view.layer and then dismissing the current 
> view controller. Simplified code:
> 
>@property (strong,nonatomic) CALayer *layer;
>.  .  .
>_layer = [[CALayer alloc] init];
>[_layer setDelegate: self];
>[self.view.layer addSublayer:_layer];
> 
> Upon dismissing the VC:
> 
>[self dismissViewControllerAnimated:YES completion:nil];
> 
> The following exception occurs:
> 
> (lldb) bt
> * thread #1: tid = 0x121bd, 0x22c2c68a libobjc.A.dylib`objc_retain + 10, 
> queue = 'com.apple.main-thread', stop reason = EXC_BAD_ACCESS (code=1, 
> address=0xb010)
>frame #0: 0x22c2c68a libobjc.A.dylib`objc_retain + 10
>frame #1: 0x27a2a22a UIKit`-[UIView(Hierarchy) subviews] + 330
>frame #2: 0x27b3e1ea UIKit`discardEngineRecursive + 118
>frame #3: 0x27a2fd06 UIKit`-[UIView dealloc] + 630
>frame #4: 0x2336cd98 CoreFoundation`-[__NSDictionaryM dealloc] + 132
>frame #5: 0x22c2cf8a libobjc.A.dylib`objc_object::sidetable_release(bool) 
> + 150
>frame #6: 0x22c2d3cc libobjc.A.dylib`(anonymous 
> namespace)::AutoreleasePoolPage::pop(void*) + 388
>frame #7: 0x23363f30 CoreFoundation`_CFAutoreleasePoolPop + 16
>frame #8: 0x23415c56 CoreFoundation`__CFRunLoopRun + 1598
>frame #9: 0x233641c8 CoreFoundation`CFRunLoopRunSpecific + 516
>frame #10: 0x23363fbc CoreFoundation`CFRunLoopRunInMode + 108
>frame #11: 0x24980af8 GraphicsServices`GSEventRunModal + 160
>frame #12: 0x27a9c434 UIKit`UIApplicationMain + 144
>  * frame #13: 0x001b655e ProteinFold`main(argc=1, argv=0x0043bbc8) + 122 at 
> main.m:14

This is due to the confluence of a few UIKit implementation details. The bottom 
line is that UIKit is trying to iterate the subviews of your view controller’s 
view, encounters your layer, and tries to retain the layer’s delegate. Because 
the layer’s delegate is assign (not weak) and the view controller has already 
been deallocated, this explodes taking your app with it.

Your safest bets are to either clear the delegate of the layer at an 
appropriate time (possibly in your view controller’s dealloc is all that is 
necessary), or to use a UIView instead of a raw CALayer in this case. Removing 
the layer would also suffice, as that would prevent UIKit from seeing it at the 
time in question. Making the layer weak is probably causing your reference to 
deallocate before it can be added to the layer tree, which is why it doesn’t 
display in that case.

> 
> If I remove the CALayer first before the 
> -dismissViewControllerAnimated:completion:, it doesn't crash:
> 
>[layer removeFromSuperlayer];
> 
> Why do I need to explicitly remove my added CALayer before dismissing the VC? 
> Note: If I declare layer as weak, the crash does not occur, but neither does 
> the layer display onscreen.
> -Carl
> 
> 
> ___
> 
> Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)
> 
> Please do not post admin requests or moderator comments to the list.
> Contact the moderators at cocoa-dev-admins(at)lists.apple.com
> 
> Help/Unsubscribe/Update your Subscription:
> https://lists.apple.com/mailman/options/cocoa-dev/david.duncan%40apple.com
> 
> This email sent to david.dun...@apple.com

--
David Duncan


___

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

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

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

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

Re: How to detect rotation in progress in viewDidLayoutSubview

2016-11-30 Thread David Duncan
Create and use a subview. There is no significant cost to an additional 
content-less view.

--
David Duncan @ My iPhone

> On Nov 30, 2016, at 9:46 AM, Andreas Falkenhahn <andr...@falkenhahn.com> 
> wrote:
> 
>> On 29.11.2016 at 22:28 David Duncan wrote:
>> 
>> Correct, because the owning UIWindow owns the frame of the view
>> controller’s view, and may change it at any time.
>> The simplest way to fix your specific issue is to just set the
>> contentMode to AspectFit. This will automatically center and scale
>> the content for the current orientation to fit within the given bounds.
> 
> Hmm, I'm afraid that won't work because sometimes I also need the
> UIView to appear at a different fixed location that is not equal
> to the center, e.g. in the top-left or bottom-right corner of
> the UIWindow. Any other ideas?
> 
> -- 
> Best regards,
> Andreas Falkenhahnmailto:andr...@falkenhahn.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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

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

Re: How to detect rotation in progress in viewDidLayoutSubview

2016-11-29 Thread David Duncan

> On Nov 29, 2016, at 2:50 PM, Andreas Falkenhahn <andr...@falkenhahn.com> 
> wrote:
> 
> On 29.11.2016 at 17:35 David Duncan wrote:
> 
> 
>>> On Nov 29, 2016, at 11:30 AM, Andreas Falkenhahn <andr...@falkenhahn.com> 
>>> wrote:
> 
>>> On 28.11.2016 at 16:50 David Duncan wrote:
> 
>>>> I think you can do everything you need to do in layoutSubviews
>>>> (fundamentally it doesn’t matter if the device rotates or not, you
>>>> just want to keep the view centered in its superview).
> 
>>> Right, makes sense.
> 
>>>> In general you should do as much as possible in layoutSubviews type
>>>> methods. However sometimes you really do want to do something
>>>> temporary specifically due to a transition between sizes,
>>>> orientations, or size classes, and hence why we provide the
>>>> “willTransitionTo” methods. If it isn’t a temporary change, then you
>>>> don’t want the transition methods, as they are not always called at
>>>> points when layoutSubviews will be.
> 
>>> Ok, I've now ditched "willTransitionTo" completely and everything is
>>> done in my UIView's layoutSubviews method now. Seems to work fine.
> 
>>> Just one last thing: the documentation of layoutSubviews mentions
>>> that this method, as its name implies, is meant to make adjustments
>>> to subviews. But my UIView doesn't have any subviews at all. So
>>> currently I'm basically (ab?)using layoutSubviews to make adjustments
>>> to the UIView itself, not to its subviews, since there are none.
>>> Is that allowed?
> 
>> It is generally bad form to modify a view’s own geometry inside of
>> layoutSubviews (frame, bounds, center, transform, and a few related
>> layer properties), and more generally not outside of initialization
>> time. Also keep in mind that when I mentioned layoutSubviews above,
>> I also mean the UIViewController methods viewWillLayoutSubviews and
>> viewDidLayoutSubviews – and in that case the ‘self’ that you shouldn’t 
>> modify is self.view.
> 
>> That said, I imagined your view hierarchy was Window =>
>> ViewController.View => ContentView, at which point ViewController
>> modifying ContentView inside of viewWillLayoutSubviews (for example) is 
>> fully kosher.
> 
> It is actually just Window => ViewController.View. I really only have
> a single UIView initialized by my UIViewController in loadView() and
> that's it.
> 
> So it's forbidden to move this view in the UIViewController's 
> viewDidLayoutSubviews()
> because it is the root view and not a subview? But how should I do it then?

Correct, because the owning UIWindow owns the frame of the view controller’s 
view, and may change it at any time.

The simplest way to fix your specific issue is to just set the contentMode to 
AspectFit. This will automatically center and scale the content for the current 
orientation to fit within the given bounds.

> 
> -- 
> Best regards,
> Andreas Falkenhahnmailto:andr...@falkenhahn.com 
> <mailto:andr...@falkenhahn.com>
--
David Duncan

___

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

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

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

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

Re: How to detect rotation in progress in viewDidLayoutSubview

2016-11-29 Thread David Duncan

> On Nov 29, 2016, at 11:30 AM, Andreas Falkenhahn <andr...@falkenhahn.com> 
> wrote:
> 
> On 28.11.2016 at 16:50 David Duncan wrote:
> 
>> I think you can do everything you need to do in layoutSubviews
>> (fundamentally it doesn’t matter if the device rotates or not, you
>> just want to keep the view centered in its superview).
> 
> Right, makes sense.
> 
>> In general you should do as much as possible in layoutSubviews type
>> methods. However sometimes you really do want to do something
>> temporary specifically due to a transition between sizes,
>> orientations, or size classes, and hence why we provide the
>> “willTransitionTo” methods. If it isn’t a temporary change, then you
>> don’t want the transition methods, as they are not always called at
>> points when layoutSubviews will be.
> 
> Ok, I've now ditched "willTransitionTo" completely and everything is
> done in my UIView's layoutSubviews method now. Seems to work fine.
> 
> Just one last thing: the documentation of layoutSubviews mentions
> that this method, as its name implies, is meant to make adjustments
> to subviews. But my UIView doesn't have any subviews at all. So
> currently I'm basically (ab?)using layoutSubviews to make adjustments
> to the UIView itself, not to its subviews, since there are none.
> Is that allowed?

It is generally bad form to modify a view’s own geometry inside of 
layoutSubviews (frame, bounds, center, transform, and a few related layer 
properties), and more generally not outside of initialization time. Also keep 
in mind that when I mentioned layoutSubviews above, I also mean the 
UIViewController methods viewWillLayoutSubviews and viewDidLayoutSubviews – and 
in that case the ‘self’ that you shouldn’t modify is self.view.

That said, I imagined your view hierarchy was Window => ViewController.View => 
ContentView, at which point ViewController modifying ContentView inside of 
viewWillLayoutSubviews (for example) is fully kosher.

> 
> -- 
> Best regards,
> Andreas Falkenhahnmailto:andr...@falkenhahn.com
> 

--
David Duncan


___

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

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

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

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

Re: How to convert from decomposed to precomposed UTF-8 on iOS

2016-11-28 Thread David Duncan

> On Nov 28, 2016, at 10:36 AM, Andreas Falkenhahn <andr...@falkenhahn.com> 
> wrote:
> 
> (I'm sorry, but this mail isn't really about Cocoa but I've checked all
> the lists hosted on lists.apple.com and I haven't found a list which
> is suitable so I'll try here.)
> 
> I need to convert a char array that contains decomposed UTF-8 characters
> (as used by HFS) into a precomposed UTF-8 char array. How can I do that on
> iOS please?
> 
> On macOS I can simply use CreateTextEncoding(), TECCreateConverter(),
> and TECConvertText() but apparently these APIs aren't available on iOS.

NSString should have what you need – it has methods to obtain a corresponding 
NSString in forms C/D/KC/KD. Look for decomposed/precomposed properties.

> 
> Any ideas?
> 
> -- 
> Best regards,
> Andreas Falkenhahn  mailto:andr...@falkenhahn.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:
> https://lists.apple.com/mailman/options/cocoa-dev/david.duncan%40apple.com
> 
> This email sent to david.dun...@apple.com

--
David Duncan


___

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

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

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

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

Re: How to detect rotation in progress in viewDidLayoutSubview

2016-11-28 Thread David Duncan

> On Nov 27, 2016, at 7:25 AM, Andreas Falkenhahn <andr...@falkenhahn.com> 
> wrote:
> 
> On 27.11.2016 at 00:04 David Duncan wrote:
> 
>> What are you trying to accomplish?
> 
> I want to keep my UIView centered on the screen so I need to
> change its position when the device rotates. I'm currently
> moving the UIView to the new position using
> 
>[myView setFrame:...];
> 
> in viewDidLayoutSubviews(). 

I think you can do everything you need to do in layoutSubviews (fundamentally 
it doesn’t matter if the device rotates or not, you just want to keep the view 
centered in its superview).

> 
>> For most developers just looking at the aspect ratio in
>> viewDidLayoutSubviews is sufficient. 
> 
> Right, this would probably be a nicer way than using a flag.
> 
>> If you only want to do
>> something for rotating, doing it as an alongside animation in
>> viewWillTransitionToSize is usually what you want.
> 
> Do you mean that I should move the UIView in my "animateAlongsideTransition"
> block instead of viewDidLayoutSubviews()? This seems to work as
> well but I don't really know anything about those animation
> handlers so I felt more comfortable doing this in viewDidLayoutSubviews().

In general you should do as much as possible in layoutSubviews type methods. 
However sometimes you really do want to do something temporary specifically due 
to a transition between sizes, orientations, or size classes, and hence why we 
provide the “willTransitionTo” methods. If it isn’t a temporary change, then 
you don’t want the transition methods, as they are not always called at points 
when layoutSubviews will be.

> 
>> Also from your last thread, if you are trying to fix up a
>> transform, it may be easier to use contentMode instead of transform
>> for this case. AspectFit vs AspectFill will do the common letterbox
>> vs clip without you needing to do anything further.
> 
> Yes, I'm actually using contentMode now. If this is set to
> UIViewContentModeScaleToFill, I can just change the bounds
> of the UIView and I'll get GPU-accelerated scaling for free
> 
> -- 
> Best regards,
> Andreas Falkenhahnmailto:andr...@falkenhahn.com
> 

--
David Duncan


___

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

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

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

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

Re: How to detect rotation in progress in viewDidLayoutSubview

2016-11-26 Thread David Duncan
What are you trying to accomplish?

For most developers just looking at the aspect ratio in viewDidLayoutSubviews 
is sufficient. If you only want to do something for rotating, doing it as an 
alongside animation in viewWillTransitionToSize is usually what you want.

Also from your last thread, if you are trying to fix up a transform, it may be 
easier to use contentMode instead of transform for this case. AspectFit vs 
AspectFill will do the common letterbox vs clip without you needing to do 
anything further.

--
David Duncan @ My iPhone

> On Nov 26, 2016, at 3:40 PM, Andreas Falkenhahn <andr...@falkenhahn.com> 
> wrote:
> 
> When the user rotates the device, I need to reposition my view.
> I do this in viewDidLayoutSubview(). iOS then smoothly rotates
> the view to the new position.
> 
> However, in order to reposition my view in viewDidLayoutSubview()
> I need to know whether viewDidLayoutSubview() is called because
> the user has rotated the device or not.
> 
> Thus, I set a flag in viewWillTransitionToSize() that tells
> viewDidLayoutSubview() that a rotation is currently in progress.
> This flag is then reset in viewDidLayoutSubview() after it has
> repositioned the view. This works fine but still I feel somewhat
> uneasy about this because I'm not sure whether this is really the
> best way to do this. I'm also worried about potential unwanted
> side effects.
> 
> That's why I wanted to ask what is the recommended way to
> reposition my view when the user rotates the device?
> 
> I've already done a lot of research on this but I'm still not
> confident about this. Note that I'm not using Interface Builder
> or anything. My app just consists of a single UIView which is
> created manually. The UIView is custom-drawn by setting its
> CALayer to a CGImageRef.
> 
> -- 
> Best regards,
> Andreas Falkenhahn  mailto:andr...@falkenhahn.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:
> https://lists.apple.com/mailman/options/cocoa-dev/david.duncan%40apple.com
> 
> This email sent to david.dun...@apple.com

___

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

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

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

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

Re: Hardware-accelerated scaling on iOS without OpenGL

2016-11-25 Thread David Duncan
The transform is a reasonable way to go. You can also change the contentMode to 
get scaling for free. Fundamentally this all ends up as a texture draw on the 
GPU so how you get the geometry for the draw there is nearly irrelevant.

The major performance gain from OpenGL (or Metal) in this case is that you can 
avoid an additional buffer copy and composite on the way to the display in many 
circumstances. This may not be significant in your case however.

--
David Duncan @ My iPhone

> On Nov 25, 2016, at 11:38 AM, Andreas Falkenhahn <andr...@falkenhahn.com> 
> wrote:
> 
>> On 25.11.2016 at 16:29 David Duncan wrote:
>> 
>> The fastest method without OpenGL is to work with CGImage directly
>> and assign the image as the contents of a CALayer.
> 
>> This will engage CoreAnimation to use the hardware to scale the
>> image, but is still not quite as fast as OpenGL for the same task.
> 
>> Roughly you'll want to look at CGImageCreate and
>> CGDataProviderCreate (there are a number of variants of the latter).
> 
> Thanks, I've just tried this and the performance seems reasonably well.
> I don't know how fast direct OpenGL would be but it looks like the
> CALayer approach is already sufficiently fast enough.
> 
> But just to make sure I implemented this in the right way: Assigning the
> image as the contents of my view's CALayer means that I shouldn't draw
> in drawRect() at all but just do the following whenever I need to draw
> a new frame:
> 
>myImage = CGImageCreate(...);
>view.layer.contents = (id) myImage;
>CGImageRelease(myImage);
> 
> Is that right? I have to create a new CGImageRef for every frame I draw
> because CGImages are immutable objects, right? 
> 
> And to scale the whole shebang from 320x240 to full screen I just set
> 
>view.transform = CGAffineTransformScale(CGAffineTransformIdentity, scalex, 
> scaley);
> 
> Or is there a better way to force a view into full screen by scaling?
> 
> -- 
> Best regards,
> Andreas Falkenhahnmailto:andr...@falkenhahn.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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

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

Re: Hardware-accelerated scaling on iOS without OpenGL

2016-11-25 Thread David Duncan
The fastest method without OpenGL is to work with CGImage directly and assign 
the image as the contents of a CALayer.

This will engage CoreAnimation to use the hardware to scale the image, but is 
still not quite as fast as OpenGL for the same task.

Roughly you'll want to look at CGImageCreate and CGDataProviderCreate (there 
are a number of variants of the latter). Much sample code will try using 
CGBitmapContextCreateImage because it looks easier, but this will take a kernel 
hit for each frame and mark the memory copy-on-write which will cause you to 
take another hit when the memory gets written to. 

--
David Duncan @ My iPhone

> On Nov 25, 2016, at 10:22 AM, Andreas Falkenhahn <andr...@falkenhahn.com> 
> wrote:
> 
> I'm currently writing an iOS backend for a cross-platform program whose
> platform-independent engine writes all of its graphics into 32-bit pixel
> buffers, in RGBA order. The alpha byte isn't used. The graphics are always
> opaque so I don't need alpha blending.
> 
> What is the most efficient option to draw and scale these pixel buffers to
> my CGContextRef inside my drawRect method? The pixel buffers are usually
> only 320x240 pixels and need to be scaled to completely fill my view's
> dimensions, e.g. 1024x768 on non-Retina iPads and 2048x1536 on Retina iPads.
> This is a whole lot of work so it's best done using the GPU. But how can I
> force iOS to draw and scale using the GPU without using OpenGL?
> 
> I've tried using CGContextDrawImage() but this is really slow, probably 
> because
> everything is done using the CPU.
> 
> I've also had a look at the CIImage APIs because these are apparently GPU
> optimized but the problem is that CIImage objects are immutable so I'd have to
> constantly create new CIImage objects for each frame I need to draw which will
> probably kill the performance as well.
> 
> I could go with OpenGL of course but I'd like to get some feedback on whether
> there is an easier solution to get what I want here.
> 
> Thanks for any ideas!
> 
> -- 
> Best regards,
> Andreas Falkenhahn  mailto:andr...@falkenhahn.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:
> https://lists.apple.com/mailman/options/cocoa-dev/david.duncan%40apple.com
> 
> This email sent to david.dun...@apple.com

___

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

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

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

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

Re: CABasicAnimation in a view that's covered by another?

2016-11-22 Thread David Duncan

> On Nov 22, 2016, at 1:22 PM, Eric E. Dolecki <edole...@gmail.com> wrote:
> 
> If the panel is up covering the UIImageView and the cross-fade is called, and 
> I bring the panel back down, exposing the UIImageView, the cross-fade did not 
> take place, the image not updated. That's how I know.
> 
> If I time the crossfade on closing the panel... a 10th of a second after the 
> panel starts to move (thus exposing a tiny bit of the UIImageView before the 
> crossfade), it works. How strange is this?

Possible its a bug related to if the OS thinks that the image view needs to be 
drawn or not. If you give your panel alpha <1 does that resolve the issue as 
well? (If so, please file a bug).

> 
> On Tue, Nov 22, 2016 at 1:57 PM David Duncan <david.dun...@apple.com 
> <mailto:david.dun...@apple.com>> wrote:
> 
> > On Nov 22, 2016, at 7:26 AM, Eric E. Dolecki <edole...@gmail.com 
> > <mailto:edole...@gmail.com>> wrote:
> >
> > I have a cross-fading album art thing happening. When I can see the
> > imageview it works fine, if it's totally covered by another view (a panel I
> > slide up), it seems to not change. Is this a known thing? Doesn't seem
> > right - I am trying to track down other related things to see.
> 
> What do you mean by “seems to not change”? Can you see the view through the 
> panel you slide up? If not, how can you tell what is going on?
> 
> >
> >myfade = CABasicAnimation(keyPath: "contents")
> >myfade.duration = 0.4
> >myfade.fromValue = largeAlbumCover.image!.cgImage
> >myfade.toValue = artImage?.cgImage
> >myfade.delegate = self
> >largeAlbumCover.layer.add(myfade, forKey: "animateContents")
> >largeAlbumCover.image = artImage
> >
> > Thanks,
> > Eric
> > ___
> >
> > Cocoa-dev mailing list (Cocoa-dev@lists.apple.com 
> > <mailto: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 
> > <http://lists.apple.com/>
> >
> > Help/Unsubscribe/Update your Subscription:
> > https://lists.apple.com/mailman/options/cocoa-dev/david.duncan%40apple.com 
> > <https://lists.apple.com/mailman/options/cocoa-dev/david.duncan%40apple.com>
> >
> > This email sent to david.dun...@apple.com <mailto:david.dun...@apple.com>
> 
> --
> David Duncan
> 

--
David Duncan

___

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

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

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

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

Re: CABasicAnimation in a view that's covered by another?

2016-11-22 Thread David Duncan

> On Nov 22, 2016, at 7:26 AM, Eric E. Dolecki <edole...@gmail.com> wrote:
> 
> I have a cross-fading album art thing happening. When I can see the
> imageview it works fine, if it's totally covered by another view (a panel I
> slide up), it seems to not change. Is this a known thing? Doesn't seem
> right - I am trying to track down other related things to see.

What do you mean by “seems to not change”? Can you see the view through the 
panel you slide up? If not, how can you tell what is going on?

> 
>myfade = CABasicAnimation(keyPath: "contents")
>myfade.duration = 0.4
>myfade.fromValue = largeAlbumCover.image!.cgImage
>myfade.toValue = artImage?.cgImage
>myfade.delegate = self
>largeAlbumCover.layer.add(myfade, forKey: "animateContents")
>largeAlbumCover.image = artImage
> 
> Thanks,
> Eric
> ___
> 
> Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)
> 
> Please do not post admin requests or moderator comments to the list.
> Contact the moderators at cocoa-dev-admins(at)lists.apple.com
> 
> Help/Unsubscribe/Update your Subscription:
> https://lists.apple.com/mailman/options/cocoa-dev/david.duncan%40apple.com
> 
> This email sent to david.dun...@apple.com

--
David Duncan


___

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

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

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

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

Re: Implementing own text prediction on UITextField

2016-09-29 Thread David Duncan
There is not.

> On Sep 29, 2016, at 4:34 AM, Devarshi Kulshreshtha 
> <devarshi.bluec...@gmail.com> wrote:
> 
> Currently when we type on a text field it shows text prediction over
> keyboard on a bar, is there any way to populate the same with say a
> dictionary, or a plist, etc. Basically populating it using own data source
> rather than system data source.
> 
> Any ideas guys?
> 
> Thanks 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:
> https://lists.apple.com/mailman/options/cocoa-dev/david.duncan%40apple.com
> 
> This email sent to david.dun...@apple.com

--
David Duncan


___

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

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

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

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

Re: Maximum image size ?

2016-09-22 Thread David Duncan

> On Sep 22, 2016, at 6:14 AM, Gabriel Zachmann <z...@tu-clausthal.de> wrote:
> 
> 
> What is the maximum size of a bitmap image I can render using the Core 
> Graphics framework and CALayer ?

CoreGraphics is generally limited by main memory, and CALayer by GPU memory. 
CoreAnimation automatically tiles images that are larger than the GPU max image 
size.

However, you also generally don’t want to get anywhere near such limits, as 
performance tends to fall off a cliff before those points (due to many many 
implementation details and due to your own competition with the rest of the 
system).

If you know you will be dealing with very large images (a definition that 
varies from year to year mind you) you will probably want to deal with the 
largeness yourself, if only for initial loading performance reasons.

> 
> So far, I had assumed it is the maximum texture size the graphics card can 
> handle, so I determined the limits via
>   glGetIntegerv( GL_MAX_TEXTURE_SIZE, _ );
> 
> But apparently , the limits are much higher.
> 
> How can I determine the limit, so that my app can filter out images over the 
> limit, so that it does not crash in such cases?
> 
> I have checked the documentation, in particular 
> CGImageSourceCreateImageAtIndex() et al., to no avail.
> 
> 
> 
> 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:
> https://lists.apple.com/mailman/options/cocoa-dev/david.duncan%40apple.com
> 
> This email sent to david.dun...@apple.com

--
David Duncan


___

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

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

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

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

Re: CALayer kCAGravityResizeAspectFill and kCAGravityTop

2016-09-21 Thread David Duncan

> On Sep 21, 2016, at 11:44 AM, Torsten Curdt <tcu...@vafer.org> wrote:
> 
> There isn’t an option to fill width and align top. The more general 
> recommendation in this space however would be to use a UIImageView, which has 
> all the same options but participates in higher level layout (including the 
> content of autoResizingMasks, and also auto layout).
> 
> I am using the layer as a mask - so the UIImageView isn't really an option.

Its still an option, especially if you are otherwise using UIViews – 
UIView.maskView would do the trick.

> BUT I just found that adjusting the contentsRect to the right ratio does the 
> trick.

If you are going to do that, you might as well just calculate the aspect ratio 
as well.

Keep in mind that if the image you are using as a mask is not fully under your 
control, you will also have to adapt for the image orientation – if the image 
is not oriented up, then you need to rotate as well.

> 
> cheers,
> Torsten

--
David Duncan

___

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

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

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

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

Re: CALayer kCAGravityResizeAspectFill and kCAGravityTop

2016-09-21 Thread David Duncan

> On Sep 21, 2016, at 11:18 AM, Torsten Curdt <tcu...@vafer.org> wrote:
> 
> On iOS I want to fill a layer with an image.
> The width should be filled and the image should retain its aspect ratio.
> This
> 
>layer.contents = image.cgImage
>layer.contentsGravity = kCAGravityResizeAspectFill
> 
> almost does the right thing - but it positions the image at the centers.
> I would like to have it positioned at the top.

There isn’t an option to fill width and align top. The more general 
recommendation in this space however would be to use a UIImageView, which has 
all the same options but participates in higher level layout (including the 
content of autoResizingMasks, and also auto layout).

> 
> While looking at the docs for CALayer I found "autoresizingMask" but that
> seems to be macOS only.
> 
> Any pointers?
> 
> cheers,
> Torsten
> ___
> 
> Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)
> 
> Please do not post admin requests or moderator comments to the list.
> Contact the moderators at cocoa-dev-admins(at)lists.apple.com
> 
> Help/Unsubscribe/Update your Subscription:
> https://lists.apple.com/mailman/options/cocoa-dev/david.duncan%40apple.com
> 
> This email sent to david.dun...@apple.com

--
David Duncan


___

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

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

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

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

Re: Success with NSTableView weak delegates?

2016-09-20 Thread David Duncan

> On Sep 20, 2016, at 2:47 PM, Sean McBride <s...@rogue-research.com> wrote:
> 
> On Tue, 20 Sep 2016 14:26:27 -0700, David Duncan said:
> 
>>> On Sep 20, 2016, at 1:21 PM, Sean McBride <s...@rogue-research.com> wrote:
>>> 
>>> Hi all,
>>> 
>>> WWDC 2016 Session 203 "What's New in Cocoa" at around 43:37 in the
>> video, says that if you link against the 10.11 SDK that NSTableView's
>> delegate is weak.  So I went and wrapped my delegate nil-ing in:
>>> 
>>> #if MAC_OS_X_VERSION_MAX_ALLOWED < 101100
>>> [tableView setDelegate:nil];
>>> [tableView setDataSource:nil];
>>> #endif
>>> 
>>> yet (with NSZombie especially), I easily reproduce message-to-zombie
>> crashes with builds that are made against the Xcode 7.3.1 10.11 SDK.
>> 
>> On which OS version?
> 
> At runtime: 10.9.5, 10.10.5, and 10.11.6.
> 
>> The macro above only says “do this if I link against an SDK prior to
>> 10.11” – that doesn’t handle what happens at runtime when you are on
>> 10.10 or below. In particular, if you plan to deploy back to prior to
>> 10.11, then you would want to either do a runtime check, or for trivial
>> code like this always run the code until your MIN_ALLOWED (deployment
>> target) is >= 10.11.
> 
> Yes, I'm aware of these differences.  I'm also aware, as you surely are, that 
> sometimes behaviour depends (only) on what SDK you link against.

Sure, but that generally only applies to that OS or later, as we cannot 
generally change the behavior of older OSes (there are specific recent 
exceptions to that, but they are typically fairly low level and targeted). I 
don’t think the speaker here was trying to imply that this feature was 
available prior to 10.11.

> Besides, I both build and run on 10.11.6 and yet I see these 
> message-to-zombie crashes after removing the setDelegate:nil code.

Thats pretty much what I was trying to verify, and so this sounds like this is 
a bug somewhere. I would highly recommend filing it.
--
David Duncan

___

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

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

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

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

Re: Success with NSTableView weak delegates?

2016-09-20 Thread David Duncan

> On Sep 20, 2016, at 1:21 PM, Sean McBride <s...@rogue-research.com> wrote:
> 
> Hi all,
> 
> WWDC 2016 Session 203 "What's New in Cocoa" at around 43:37 in the video, 
> says that if you link against the 10.11 SDK that NSTableView's delegate is 
> weak.  So I went and wrapped my delegate nil-ing in:
> 
> #if MAC_OS_X_VERSION_MAX_ALLOWED < 101100
>   [tableView setDelegate:nil];
>   [tableView setDataSource:nil];
> #endif
> 
> yet (with NSZombie especially), I easily reproduce message-to-zombie crashes 
> with builds that are made against the Xcode 7.3.1 10.11 SDK.

On which OS version?

The macro above only says “do this if I link against an SDK prior to 10.11” – 
that doesn’t handle what happens at runtime when you are on 10.10 or below. In 
particular, if you plan to deploy back to prior to 10.11, then you would want 
to either do a runtime check, or for trivial code like this always run the code 
until your MIN_ALLOWED (deployment target) is >= 10.11.

> 
> Anyone have success with these supposedly weak tableview delegates?
> 
> Thanks,
> 
> -- 
> 
> Sean McBride, B. Eng s...@rogue-research.com
> Rogue Researchwww.rogue-research.com 
> Mac Software Developer  Montréal, Québec, Canada
> 
> 
> 
> ___
> 
> Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)
> 
> Please do not post admin requests or moderator comments to the list.
> Contact the moderators at cocoa-dev-admins(at)lists.apple.com
> 
> Help/Unsubscribe/Update your Subscription:
> https://lists.apple.com/mailman/options/cocoa-dev/david.duncan%40apple.com
> 
> This email sent to david.dun...@apple.com

--
David Duncan


___

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

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

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

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

Re: Unusual Conditional Formatting

2016-09-07 Thread David Duncan

> On Sep 6, 2016, at 3:10 PM, Frank D. Engel, Jr. <fde...@fjrhome.net> wrote:
> 
> I am trying to set up what is apparently a somewhat unusual behavior:
> 
> I have a formatter which I want to behave differently depending on an 
> attribute of the value coming in, and on a user preference that can be 
> toggled in the preference panel.
> 
> Basically, they are all floating-point values, but they could be coming from 
> several types of sources: for one type, I want it formatted one way (call it 
> type S), and for other types, I want the formatting to be one of two things 
> depending on the value of a checkbox in the preferences (type V or P).  The 
> value itself could be the same but should look different for the different 
> types.
> 
> I am hoping to do this in one formatter because these values are used in 
> multiple text boxes and table row cells all over my interface, formatters are 
> difficult or impossible to bind in XCode from what I can see, and different 
> rows in a table (for example) may have different types in the same column.
> 
> 
> Here is what I have so far: I used a category on NSNumber to add a 
> "valueType" attribute as described at 
> http://nshipster.com/associated-objects/.

Basically you are trying to add reference semantics (i.e. this the pointer 
identity of the number matters). This is probably going to end poorly for you 
to be quite honest.

Consider than on 64-bit platforms, NSNumbers are often represented as tagged 
pointers, so if you end up with a tagged pointer number that should have 2 
“identities”, then you will end up with an effectively random result.

You will probably have a better result if you provide your own class that has 
the value and the type.

> 
> The formatter checks this and the user preference when formatting an incoming 
> value.  It sets some instance variables on itself to remember what it last 
> saw so that it can correctly default its interpretation of an entered value 
> when trying to send it back.
> 
> In a cell-based table, it seems to be working perfectly, but in a view-based 
> table it is not.  In an NSTextField which is not in a table, it is not.
> 
> The binding for the values is indirect - to the effect of "myThing.value" - 
> and if I change "myThing" but the new thing has the same numeric value, the 
> formatter does not always seem to trigger to render the value in the correct 
> format - it holds that of the previous thing.  If I change the value from 
> another control, when the bindings update the field, the formatting is 
> suddenly corrected.
> 
> When the preference is changed, I'm using an observer within the class for 
> myThing to set value back to itself to try to trick the bindings to update to 
> the correct formatting - this is working in the cell-based table, but does 
> not seem to work in the standalone NSTextField (I haven't added that code to 
> the view-based table yet).
> 
> I'm seeing some other inconsistencies too that I am working through - is 
> there an easier way to do this, or does anyone have any idea how I can try to 
> diagnose what is causing the inconsistent behavior?
> 
> 
> 
> ___
> 
> Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)
> 
> Please do not post admin requests or moderator comments to the list.
> Contact the moderators at cocoa-dev-admins(at)lists.apple.com
> 
> Help/Unsubscribe/Update your Subscription:
> https://lists.apple.com/mailman/options/cocoa-dev/david.duncan%40apple.com
> 
> This email sent to david.dun...@apple.com

--
David Duncan


___

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

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

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

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

Re: Toolbar hiding on rotation?

2016-08-29 Thread David Duncan

> On Aug 29, 2016, at 9:57 AM, Alex Kac <a...@webis.net> wrote:
> 
> I have a UINavigationController and UIViewController root that I set the 
> toolbarItems on. I obviously also tell it not to hide the toolbar. Great! 
> Works perfectly. But when I rotate, the toolbar is hidden - even if I rotate 
> back to portrait. I've set all the "hides*" properties such as 
> hidesBarsWhenVerticallyCompact to false (they were already false - but I 
> tried anyway), and it still hides the toolbar. I’ve put breakpoints 
> everywhere including symbolic ones for the toolbar hidden properties/methods 
> in UIKit. Since we are using a navigationcontroller subclass, I even tried 
> overriding the toolbar methods so that they can't get set to true (hiding 
> that is) and it still hides the toolbar. 
> 
> In some ways, I'm okay with it hiding going in landscape, but I'm not OK with 
> it not coming back when you go to portrait. The view debugger also shows the 
> toolbar is completely gone. So something in UIKit is removing the toolbar 
> view and never bringing it back - nothing I do can bring it back. This is 
> obviously disconcerting. My next step will be to just creating my own toolbar 
> instead of using Apple’s navcontroller toolbar, but if I can get it to work, 
> that’s my preference.
> 
> Any ideas?

This sounds suspect, as this is not the default behavior at all – that is, you 
can create a brand new project and configure a navigation controller to show 
the toolbar and it won’t hide it on its own.

What methods are you using to hide/show the toolbar? What other overrides are 
on your subclass? Any other libraries you have in your project, or categories 
on UINavigationController?

--
David Duncan


___

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

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

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

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

Re: Core Graphics: Is it better to up-sample or down-sample images when drawing into a rect?

2016-08-24 Thread David Duncan

> On Aug 24, 2016, at 1:23 AM, Jeff Szuhay <j...@szuhay.org> wrote:
> 
> I’m using a bunch of layers to draw images to, compose them, and then draw 
> into a viewRect
> with 
> 
>   CGContextDrawLayerInRect( viewContext, viewRect, myLayer);
> 
> Of course, I’m trying to pick the most reasonable size for my layers. I 
> currently use 1024x1024
> but could easily make them 512x512 or 768x768.
> 
> So my question is, “Is is more efficient to draw the layer into a smaller 
> viewRect (down-sample) 
> or into a larger ViewRect (up-sample)?” 
> 
> Or does it even matter?

It depends on if quality or performance matters more.

Downsampling is generally more expensive because you have to deal with more 
data and so you become more easily bandwidth limited, but at the same time if 
you must resample an image, down sampling generally produces better quality. 
Upsampling is the opposite of all that.

So if performance matters more than quality, then you probably want to upsample.

> 
> I have an internal goal of using less than 1% of the CPU for my 1 second 
> image drawing so it is
> actually quite important for me to know.
> 
> TIA
> 
> Jeff Szuhay
> a.k.a tickt...@quartertil2.com <mailto:t...@quartertil2.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:
> https://lists.apple.com/mailman/options/cocoa-dev/david.duncan%40apple.com
> 
> This email sent to david.dun...@apple.com

--
David Duncan


___

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

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

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

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

Re: GetNumEventsInQueue() for Cocoa

2016-08-20 Thread David Duncan

> On Aug 20, 2016, at 10:30 AM, Andreas Falkenhahn <andr...@falkenhahn.com> 
> wrote:
> 
> Is there a Cocoa equivalent for the Carbon call
> GetNumEventsInQueue(GetMainEventQueue())?
> 
> I use this a lot to poll whether there are events in the queue. 

Why do you need to poll if there are events in the queue?

> I tried to use
> 
> [NSApp nextEventMatchingMask:NSAnyEventMask untilDate:nil 
> inMode:NSDefaultRunLoopMode dequeue:NO]
> 
> as a replacement but this is very, very slow in comparison to Carbon's
> GetNumEventsInQueue() API. I need something much faster. Any ideas?
> 
> -- 
> Best regards,
> Andreas Falkenhahn  mailto:andr...@falkenhahn.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:
> https://lists.apple.com/mailman/options/cocoa-dev/david.duncan%40apple.com
> 
> This email sent to david.dun...@apple.com

--
David Duncan


___

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

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

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

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

Re: Resend: array = [NSArray new] or array = [NSArray array]?

2016-08-19 Thread David Duncan
+new is alloc/init. +array is alloc/init/autorelease. Should be equivalent.

> On Aug 16, 2016, at 7:42 AM, Alex Zavatone <z...@mac.com> wrote:
> 
> I sent this out this morning but it got eaten, so this is a resend.  Sorry if 
> it gets to some of you twice.
> 
> 
> 
> Yes, I know about literals, but I have a different question here.
> 
> 
> Is this safe?
> 
> I have seen this in some code in our codebase:
> array = [NSArray new]; 
> 
> I'm familiar with using the public method from the NSArray header and what 
> the docs say to use:
> or array = [NSArray array];
> 
> Is there any risk to using [NSArray new] to init an array instead of [NSArray 
> array]??
> 
> I'm surprised to see this being used in our codebase and would like to make 
> sure we are not destroying the universe by using it.
> 
> Thank you in advance.
> - Alex Zavatone
> 
> 
> ___
> 
> Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)
> 
> Please do not post admin requests or moderator comments to the list.
> Contact the moderators at cocoa-dev-admins(at)lists.apple.com
> 
> Help/Unsubscribe/Update your Subscription:
> https://lists.apple.com/mailman/options/cocoa-dev/david.duncan%40apple.com
> 
> This email sent to david.dun...@apple.com

--
David Duncan


___

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

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

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

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

Re: Xcode 8 - XCODE_VERSION_MAJOR causes compilation issue

2016-08-11 Thread David Duncan

> On Aug 11, 2016, at 12:09 AM, Sasikumar JP <jps...@gmail.com> wrote:
> 
> Hi,
>   Xcode defines following build variables, we can not use them in Xcode 8
> as the values are invalid octal number.
> 
>   XCODE_VERSION_ACTUAL = 0800
>XCODE_VERSION_MAJOR = 0800
>XCODE_VERSION_MINOR = 0800

Sounds like you should write up a bug for this, but I’m not really aware of 
what the use case for comparing the Xcode version would be to be honest...

> 
> 
> I am working on iOS project, it should be compilable in both Xcode 7 and 
> Xcode 8.
> I am planning to add the conditional compilation like below
> 
> preprocessor macro:
> 
> XCODE_VERS=$(XCODE_VERSION_MAJOR)
> 
> 
> #if XCODE_VERS > 0700
> 
> @interface SampleTableCell : UITableViewCell
> 
> #else
> 
> @interface SampleTableCell : UITableViewCell
> 
> #endif
> 
> 
> But this code throws the compilation error (Invalid digit '8' in octal
> constant) in Xcode 8, since 0800 is not a valid octal value.
> 
> Is there any work around other than creating 2 different targets(separate
> target for Xcode 7 and Xcode 8)

You don’t want the Xcode version here, you want the iOS SDK version, which in 
this case is represented by the conditional "__IPHONE_OS_VERSION_MAX_ALLOWED >= 
__IPHONE_10_0” (MAX_ALLOWED corresponds to the SDK version you link against, in 
this case the iOS 10.0 SDK).

But in the long run building with Xcode 8 (and the iOS 10.0 or later SDK) will 
be a given, so I suspect that most solve this problem by branching for that SDK 
and all the updates that come with it rather than maintaining conditionals like 
this in their code.
--
David Duncan


___

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

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

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

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

Re: Objective-C basics - (Why NSNumber conforms to NSCopying protocol)

2016-08-11 Thread David Duncan

> On Aug 10, 2016, at 11:32 PM, Sasikumar JP <jps...@gmail.com> wrote:
> 
> Hi,
> 
>   This may be very basic question. I am curious to know the details.
> 
> what was the reason NSNumber conforms to NSCopying protocol.
> 
> NSNumber is immutable class, Making a copy of NSNumber object returns the
> same reference.
> 
> Is there any case where NSNumber returns the new object? if not, then what
> is the purpose of conformance to NSCopying protocol.


There is nothing stopping a developer from subclassing NSNumber, and if that 
developer decided to create MyMutableNumber that otherwise conformed to the 
NSNumber interface, the developer would need to implement -copyWithZone: to do 
the right thing. If NSNumber doesn’t implement NSCopying, then the subclasser 
can’t hope to get the correct behavior in this case.
--
David Duncan


___

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

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

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

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

Re: OK - I must be missing something simple here.

2016-06-28 Thread David Duncan

> On Jun 22, 2016, at 1:36 PM, Alex Zavatone <z...@mac.com> wrote:
> 
> 
> On Jun 22, 2016, at 1:59 PM, David Duncan wrote:
> 
>> 
>>> On Jun 22, 2016, at 11:54 AM, Alex Zavatone <z...@mac.com> wrote:
>>> 
>>> 
>>> On Jun 22, 2016, at 10:51 AM, Alastair Houghton wrote:
>>> 
>>>> On 22 Jun 2016, at 16:38, Alex Zavatone <z...@mac.com> wrote:
>>>>>> 
>>>>>> Is the thing that you’re missing that IBOutlets are nothing special; 
>>>>>> they’re just a property (the syntax “IBOutlet” is there just to tell 
>>>>>> Xcode which things to show in the GUI editor).  So you can set the 
>>>>>> property, just the same as you would any other property, from code.  
>>>>>> Does that help?
>>>>> 
>>>>> I remember reading the docs that IBAction and IBOutlet are mainly 
>>>>> conventions for the viewer.
>>>>> 
>>>>> What I am saying is that I DO set the property to be the instance of the 
>>>>> button.
>>>>> 
>>>>> And nothing happens.  By that, there is no visual change to the screen.
>>>> 
>>>> You *are* updating the items property on the UIToolbar, right?  Rather 
>>>> than just altering some random IBOutlet and expecting it to magically 
>>>> update the toolbar somehow?
>>> 
>>> Alastair, you're getting confused.  
>>> 
>>> Why would there be a UIToolbar?  This is just a plain old a UIButton.  
>> 
>> You started by mentioning that these buttons were being displayed as custom 
>> views on a UIBarButtonItem, hence the question.
> 
> I'm sorry, David, I thought that I said that they worked under that condition.
> 
> What is failing is when I have a UIButton instance (that I know is good, 
> because i use that UIButton's instance to create the UIBarButtonItem, but I 
> keep the UIButton instance around) and I have an IBOutlet to a UIButton on a 
> storyboard scene's viewController.  
> 
> This IBOutlet to a UIButton class on the viewController has a 24 x 24 pixel 
> dimensions in the viewController in the scene, if it matters.
> 
> If I try to set the IBOutlet to one of the UIButton instance, nothing shows 
> up.

Right. This is what I mentioned before – you are literally just setting a 
property. The old button would still be sitting there in the view hierarchy, 
just now you no longer have an explicit reference to it. You would need to 
insert the new button and remove the old one (as well as adapt any code that 
might be directly referencing the button that was in the view hierarchy).

IBOutlet is just  a way to connect to instances created on the storyboard by 
Interface Builder.

> 
> If I set the nav bar's right item to the UIBarButtonItem instance, that 
> displays fine.
> 
> If I have an IBOutlet that is a UIImageView and I set the image property of 
> the UImageView to a UIImage instance, that also instantly displays fine.
> 
> 
> The only reason I know that the button should display something is because 
> that's what I use to initialize the UIBarButtonItem.
> 
> 
> 
> Basically, I have a signal strength meter and I'm just interested in swapping 
> out the graphics on the fly as the signal value gets updated.
> 
> When there is a nav bar on the screen, this graphic needs to be in a 
> UIBarButtonItem and the nav bar handles all the placement of where it should 
> go.
> 
> But in screens where I have no nav bar, or if the signal strength is to be 
> monitored by screens outside of the framework that this is all in, I needed 
> to place the element differently.  I tried to use the UIButton instances (not 
> UIBarButtonItem) but the contents simply don't display and had to resort to 
> UIImages.
> 
> Thanks and sorry for the confusion.
> 
> 
>> Outlets aren’t magic here – all IBOutlet does is allow you to connect things 
>> in a storyboard. If you want to change the value of a property or instance 
>> variable backed by an IBOutlet you are free to do so – but you also need to 
>> implement all of the other things that might mean.
>> 
>> That would mean for example that you need to insert the new view and remove 
>> the old view from its superview, or reset the custom view on a 
>> UIBarButtonItem, or reparent a view controller, or any other thing that 
>> might be relevant in the context.
>> --
>> David Duncan

--
David Duncan

___

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

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

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

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

Re: OK - I must be missing something simple here.

2016-06-22 Thread David Duncan

> On Jun 22, 2016, at 11:54 AM, Alex Zavatone <z...@mac.com> wrote:
> 
> 
> On Jun 22, 2016, at 10:51 AM, Alastair Houghton wrote:
> 
>> On 22 Jun 2016, at 16:38, Alex Zavatone <z...@mac.com> wrote:
>>>> 
>>>> Is the thing that you’re missing that IBOutlets are nothing special; 
>>>> they’re just a property (the syntax “IBOutlet” is there just to tell Xcode 
>>>> which things to show in the GUI editor).  So you can set the property, 
>>>> just the same as you would any other property, from code.  Does that help?
>>> 
>>> I remember reading the docs that IBAction and IBOutlet are mainly 
>>> conventions for the viewer.
>>> 
>>> What I am saying is that I DO set the property to be the instance of the 
>>> button.
>>> 
>>> And nothing happens.  By that, there is no visual change to the screen.
>> 
>> You *are* updating the items property on the UIToolbar, right?  Rather than 
>> just altering some random IBOutlet and expecting it to magically update the 
>> toolbar somehow?
> 
> Alastair, you're getting confused.  
> 
> Why would there be a UIToolbar?  This is just a plain old a UIButton.  

You started by mentioning that these buttons were being displayed as custom 
views on a UIBarButtonItem, hence the question.

Outlets aren’t magic here – all IBOutlet does is allow you to connect things in 
a storyboard. If you want to change the value of a property or instance 
variable backed by an IBOutlet you are free to do so – but you also need to 
implement all of the other things that might mean.

That would mean for example that you need to insert the new view and remove the 
old view from its superview, or reset the custom view on a UIBarButtonItem, or 
reparent a view controller, or any other thing that might be relevant in the 
context.
--
David Duncan


___

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

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

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

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

Re: edgesForExtendedLayout outside of loadView/viewDidLoad

2016-06-17 Thread David Duncan
You are probably still 1 (or more) views off. 

The parent view controller needs to do layout to adjust to your changes, and 
there is no guarantee that self.view.superview is the view that needs layout to 
do it. You probably want self.parentViewController.view for that.

It likely works if you call it twice because of implementation details of 
layout.  

--
David Duncan @ My iPhone

> On Jun 17, 2016, at 2:27 AM, Torsten Curdt <tcu...@vafer.org> wrote:
> 
> This is odd. This seems to eventually work
> 
>  self.edgesForExtendedLayout = UIRectEdge.None
>  self.view.superview?.setNeedsUpdateConstraints()
>  self.view.superview?.updateConstraintsIfNeeded()
> 
> but only after the 2nd call.
> 
> So as a work around I am calling it like this:
> 
>  self.edgesForExtendedLayout = UIRectEdge.None
>  self.view.superview?.setNeedsUpdateConstraints()
>  self.view.superview?.updateConstraintsIfNeeded()
>  self.view.superview?.setNeedsUpdateConstraints()
>  self.view.superview?.updateConstraintsIfNeeded()
> 
> I am OK for now (given it's just for testing) but I would love to
> understand the "why".
> cheers,
> Torsten
> ___
> 
> Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)
> 
> Please do not post admin requests or moderator comments to the list.
> Contact the moderators at cocoa-dev-admins(at)lists.apple.com
> 
> Help/Unsubscribe/Update your Subscription:
> https://lists.apple.com/mailman/options/cocoa-dev/david.duncan%40apple.com
> 
> This email sent to david.dun...@apple.com

___

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

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

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

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

Re: UINavigationController back gesture animation

2016-06-15 Thread David Duncan
Most pushes end up deferred (they don’t happen until the run loop turns) so the 
transition coordinator would not have been created yet.

Try using the UINavigationController delegate methods, 
-navigationController:willShow/didShowViewController:animated:, instead.

> On Jun 15, 2016, at 7:57 AM, Torsten Curdt <tcu...@vafer.org> wrote:
> 
> Since I am getting nowhere with this I thought maybe at least I could know
> when the animation finishes.
> So I was trying it like this:
> 
> extension UINavigationController {
>func pushViewController(viewController: UIViewController, animated:
> Bool, completion: (Void -> Void)) {
>pushViewController(viewController, animated: animated)
> 
>if let coordinator = transitionCoordinator() where animated {
>coordinator.animateAlongsideTransition(nil) { _ in
>completion()
>}
>} else {
>completion()
>}
>}
> }
> 
> ...but the coordinator is just nil.
> 
> Any thoughts?
> ___
> 
> Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)
> 
> Please do not post admin requests or moderator comments to the list.
> Contact the moderators at cocoa-dev-admins(at)lists.apple.com
> 
> Help/Unsubscribe/Update your Subscription:
> https://lists.apple.com/mailman/options/cocoa-dev/david.duncan%40apple.com
> 
> This email sent to david.dun...@apple.com

--
David Duncan


___

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

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

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

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

Re: What type category should I use for my model in Swift?

2016-06-02 Thread David Duncan

> On Jun 2, 2016, at 8:55 AM, Daryle Walker <dary...@mac.com> wrote:
> 
> [Warning: rambling]
> 
> In Objective-C, you pretty much have to use a class for you model (in your 
> MVC Cocoa app). But in Swift, you have the option to use a struct/enum or a 
> non-NSObject class too.
> 
> My model in mind is dumb data, so a struct seems appropriate.  But your 
> various Cocoa subclass would need to reference the model, and using a struct 
> means it’s by value instead of reference, so coordinating changes would get 
> harder.
> 
> I’m guessing that I could use something like view-models, and only those VMs 
> access the model, and always through referencing the containing object (like 
> a NSDocument subclass).  But a reference type, even a non-NSObject one, still 
> seems easier.  And I may want to use KVO or Core Data, which require NSObject 
> subclasses.


In practical terms, a model typically both has value and reference types. If 
you take a game example, the data that describes the capabilities of a unit is 
value data, but the unit itself has identity and is thus a reference type. Also 
“Dumb” vs “Smart” data doesn’t really translate well to value vs reference – 
you can have “smart” structs and “dumb” classes (a Box class is a typical 
example of a “dumb" class – its entire purpose is to grant identity to a value 
type) – its really a matter of if you need identity or not.

I would highly recommend you experiment and do what feels for your case.
--
David Duncan


___

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

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

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

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

Re: Popover arrow point never properly aligned

2016-06-01 Thread David Duncan
Can you post a (cropped) screenshot?

> On Jun 1, 2016, at 1:39 PM, Rick Mann <rm...@latencyzero.com> wrote:
> 
> According to the docs, specifying barButtonItem is sufficient:
> 
> "Assign a value to this property to anchor the popover to the specified bar 
> button item. When presented, the popover’s arrow points to the specified 
> item. Alternatively, you may specify the anchor location for the popover 
> using the sourceView and sourceRect properties."
> 
> It's actually not straightforward to get the rect of a UIBarButtonItem (I 
> don't know why they didn't make that a UIView). So AFAICT, iOS is incorrectly 
> computing the source rect.
> 
>> On Jun 1, 2016, at 04:14 , Logan Cautrell <logancautr...@ftml.net> wrote:
>> 
>> I would check the sourceRect property on UIPopoverPresentationController.
>> 
>> If you want precise control over the positioning, then you may need a custom 
>> view in a UIBarButton. You can calculate the position and update the 
>> sourceRect accordingly.
>>  -logan
>> 
>> 
>>> On May 26, 2016, at 7:08 PM, Rick Mann <rm...@latencyzero.com> wrote:
>>> 
>>> I'm presenting a popover from a UINavigationBar UIBarButtonItem. The point 
>>> of origin of the popover never seems to come out of the center of the 
>>> UIBarButtonItem. The code I'm using is:
>>> 
>>> @IBAction
>>> func
>>> shareModel(inSender: AnyObject)
>>> {
>>>  if let model = self.model
>>>  {
>>>  let source = ModelShareActivitySource(model)
>>>  let avc = UIActivityViewController(activityItems: [source], 
>>> applicationActivities: nil)
>>>  avc.popoverPresentationController?.barButtonItem = self.shareButton
>>>  presentViewController(avc, animated: true, completion: nil)
>>>  }
>>> }
>>> @IBOutlet weak var shareButton: UIBarButtonItem!
>>> 
>>> Is anyone else seeing this?
>>> 
>>> -- 
>>> Rick Mann
>>> rm...@latencyzero.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:
>>> https://lists.apple.com/mailman/options/cocoa-dev/logancautrell%40ftml.net
>>> 
>>> This email sent to logancautr...@ftml.net
>> 
> 
> 
> -- 
> Rick Mann
> rm...@latencyzero.com <mailto:rm...@latencyzero.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:
> https://lists.apple.com/mailman/options/cocoa-dev/david.duncan%40apple.com
> 
> This email sent to david.dun...@apple.com

--
David Duncan

___

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

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

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

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

Re: Programmatically pinch a UIView

2016-05-11 Thread David Duncan
> On May 11, 2016, at 1:32 PM, Carl Hoefs <newsli...@autonomy.caltech.edu> 
> wrote:
> 
> In iOS 9.3, I have a UIView that displays a graph, and the view is pinchable. 
> That works fine but I want to programmatically pinch the UIView so the 
> default display initially shows the graph a bit smaller. How can I do this? 
> Alternately, I've tried setting self.view.contentScaleFactor but this 
> property seems to have no effect.


contentScaleFactor determines the pixel : point relationship when using 
-drawRect: on a view. You want to set the transform for something like this 
(note that this will affect the view’s frame as well).
--
David Duncan


___

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

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

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

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

Re: Is a portrait-only launch image possible?

2016-03-14 Thread David Duncan
It is, but similarly we now prefer you use a launch storyboard – so it can look 
just like your welcome screen (at least to the point that you can describe that 
in Interface Builder). This should have been created with your project.

> On Mar 14, 2016, at 4:38 AM, Charles Jenkins <cejw...@gmail.com> wrote:
> 
> Thank you, David. Is it possible then to have two launch images and the 
> system will select the correct one based on orientation? If not, I’ll have to 
> give up on my idea of a smooth transition, because my launch image won’t be 
> able to look anything like the welcome screen that follows.
> 
> -- 
> 
> Charles
> 
> On March 14, 2016 at 01:40:09, David Duncan (david.dun...@apple.com 
> <mailto:david.dun...@apple.com>) wrote:
> 
>> 
>> > On Mar 13, 2016, at 12:32 PM, Charles Jenkins <cejw...@gmail.com> wrote: 
>> >  
>> > I’m developing my first iOS app. On the General tab of my app’s build 
>> > settings, I have checked only Portrait as the supported orientation. When 
>> > testing on an iPad today, I noticed that if I start the app with the iPad 
>> > held in landscape mode, the launch image appears in landscape and of 
>> > course looks terrible because parts of it are cut off. 
>> >  
>> > The next screen that appears is my welcome/splash screen, which is very 
>> > similar to the launch image; I meant for the transition from launch image 
>> > to welcome screen to be subtle. But the welcome screen appears in portrait 
>> > mode as it should, so the transition is jarring. 
>> >  
>> > It is not possible to have a Portrait-only launch image? If so, where else 
>> > do I need to look for settings controlling the orientation of the launch 
>> > image? 
>> 
>> Modern iPad apps (which support multitasking) do not support control of 
>> interface orientation – your application will have to support all 
>> orientations. You can opt out of this by setting an Info.plist setting that 
>> states that your application must always be presented fullscreen (I don’t 
>> recall the property off hand, but it shouldn’t be too hard to find it if you 
>> really need it) but the recommendation would be to instead support all 
>> orientations so that your application will participate in multitasking. 
>> 
>> -- 
>> David Duncan

--
David Duncan

___

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

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

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

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

Re: Is a portrait-only launch image possible?

2016-03-13 Thread David Duncan

> On Mar 13, 2016, at 12:32 PM, Charles Jenkins <cejw...@gmail.com> wrote:
> 
> I’m developing my first iOS app. On the General tab of my app’s build 
> settings, I have checked only Portrait as the supported orientation. When 
> testing on an iPad today, I noticed that if I start the app with the iPad 
> held in landscape mode, the launch image appears in landscape and of course 
> looks terrible because parts of it are cut off.
> 
> The next screen that appears is my welcome/splash screen, which is very 
> similar to the launch image; I meant for the transition from launch image to 
> welcome screen to be subtle. But the welcome screen appears in portrait mode 
> as it should, so the transition is jarring.
> 
> It is not possible to have a Portrait-only launch image? If so, where else do 
> I need to look for settings controlling the orientation of the launch image?

Modern iPad apps (which support multitasking) do not support control of 
interface orientation – your application will have to support all orientations. 
You can opt out of this by setting an Info.plist setting that states that your 
application must always be presented fullscreen (I don’t recall the property 
off hand, but it shouldn’t be too hard to find it if you really need it) but 
the recommendation would be to instead support all orientations so that your 
application will participate in multitasking.

--
David Duncan


___

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

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

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

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

Re: UI to allow user to scale and crop image within a circle

2016-02-24 Thread David Duncan

> On Feb 24, 2016, at 3:47 PM, Quincey Morris 
> <quinceymor...@rivergatesoftware.com> wrote:
> 
> On Feb 24, 2016, at 13:44 , Graham Cox <graham@bigpond.com 
> <mailto:graham@bigpond.com>> wrote:
>> 
>> However, if you use a clipping path, you can just create this on the fly as 
>> part of -drawRect: and so it’ll always be correct
> 
> I don’t recall Charles’s drawing code exactly, but I think this is just part 
> of the solution. It’ll always be correct for the part of the view being 
> drawn, but there’s no guarantee that the whole view will be redrawn if the 
> relationship between the bounds origin and the circle changes. I think 
> Charles still needs something to force redrawing of the whole view when the 
> view geometry changes.

By default -setNeedsDisplay will dirty the entire view for redraw. 
-setNeedsDisplayInRect: can be used for partial updates, but typically you will 
call that directly. If you always draw inside of the whole bounds of the view 
however, you are generally insulated from origin changes (as either 
setNeedsDisplay method should do the right thing in these circumstances).

> 
> Of course, if the view geometry never changes, or the relationship of the 
> circle to the bounds origin never changes, then I think the forced redrawing 
> isn’t necessary.
> 

--
David Duncan

___

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

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

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

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

Re: UI to allow user to scale and crop image within a circle

2016-02-24 Thread David Duncan

> On Feb 24, 2016, at 1:44 PM, Graham Cox <graham@bigpond.com> wrote:
> 
> 
>> On 24 Feb 2016, at 11:08 PM, Charles Jenkins <cejw...@gmail.com> wrote:
>> 
>> My guess is, you do this by adding a mask layer; but you probably don’t 
>> redraw the mask in drawRect(), hm? It should never need to be refreshed 
>> unless the bounds change.
> 
> 
> Can you not just use a clipping path? They’re usually much easier to set up 
> especially for simple cases like this than a mask layer.
> 
> e.g. the simplest way I can think of drawing this is a) draw your image at 
> the correct size and position, b) form a clipping path from the bounds rect 
> plus the desired circle, setting the winding rule if necessary so that the 
> path includes all of the area of your view EXCEPT the circle. c) paint over 
> the entire view in a solid colour (black I think you said). The clipping path 
> ensures that you won’t paint over the circular aperture that shows the image.
> 
>> Assuming I can figure out how to make a mask layer, what is the correct way 
>> to monitor for a bounds change in order to recreate the mask?
> 
> 
> Override -setFrame:, call super then do what you need to do.

-layoutSubviews would be better, as in general if you need to override 
-setFrame: for something, you also need to override -setCenter: and 
-setBounds:. If you need to ensure animation works, you can call 
-layoutIfNeeded inside of your animation block.

But since your drawing something, a clipping view isn’t necessary – you can 
just clip your drawing.

> 
> However, if you use a clipping path, you can just create this on the fly as 
> part of -drawRect: and so it’ll always be correct, and you won’t need to do 
> this. There’s no reason to cache this path unless it’s really complex and 
> expensive. Hint: it’s not, it’s a circle.
> 
> —Graham
> 
> 

--
David Duncan


___

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

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

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

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

Re: UI to allow user to scale and crop image within a circle

2016-02-24 Thread David Duncan

> On Feb 24, 2016, at 4:08 AM, Charles Jenkins <cejw...@gmail.com> wrote:
> 
> Good tip! Thanks, Dave and Quincey. I was pretty sure the problem was 
> something embarrassingly basic.
> 
> The next step is to redesign the CircleOverlayView to fill its view with 
> black except for the center of the circle. I already learned that filling the 
> view with black and then filling the circle with clearColor() doesn’t work! 
> My guess is, you do this by adding a mask layer; but you probably don’t 
> redraw the mask in drawRect(), hm? It should never need to be refreshed 
> unless the bounds change.
> 
> Assuming I can figure out how to make a mask layer, what is the correct way 
> to monitor for a bounds change in order to recreate the mask?

You can’t fill with clear color with normal blending because clear color has 0 
alpha. You can however fill it with the copy blend mode.

> 
> -- 
> 
> Charles
> 
> On February 24, 2016 at 03:16:00, David Duncan (david.dun...@apple.com 
> <mailto:david.dun...@apple.com>) wrote:
> 
>> 
>> > On Feb 23, 2016, at 7:17 PM, Quincey Morris 
>> > <quinceymor...@rivergatesoftware.com> wrote: 
>> >  
>> > On Feb 23, 2016, at 18:50 , Charles Jenkins <cejw...@gmail.com> wrote: 
>> >>  
>> >> I draw based on the overlay view’s frame, NOT based on the rect that gets 
>> >> passed in to drawRect(). I must not understand what that parameter is 
>> >> for. 
>> >  
>> > From the UIView documentation for ‘drawRect’: 
>> >  
>> >> The portion of the view’s bounds that needs to be updated. The first time 
>> >> your view is drawn, this rectangle is typically the entire visible bounds 
>> >> of your view. However, during subsequent drawing operations, the 
>> >> rectangle may specify only part of your view. 
>> >  
>> >  
>> > So, yes, your code is right now. :) 
>> >  
>> 
>> Its almost right – drawing should be done based on the bounds not the frame 
>> (this will be an issue if you either use the frame.origin or if you 
>> transform the view). 
>> 
>> > ___ 
>> >  
>> > Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) 
>> >  
>> > Please do not post admin requests or moderator comments to the list. 
>> > Contact the moderators at cocoa-dev-admins(at)lists.apple.com 
>> >  
>> > Help/Unsubscribe/Update your Subscription: 
>> > https://lists.apple.com/mailman/options/cocoa-dev/david.duncan%40apple.com 
>> >  
>> > This email sent to david.dun...@apple.com 
>> 
>> -- 
>> David Duncan

--
David Duncan

___

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

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

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

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

Re: UI to allow user to scale and crop image within a circle

2016-02-24 Thread David Duncan

> On Feb 23, 2016, at 7:17 PM, Quincey Morris 
> <quinceymor...@rivergatesoftware.com> wrote:
> 
> On Feb 23, 2016, at 18:50 , Charles Jenkins <cejw...@gmail.com> wrote:
>> 
>> I draw based on the overlay view’s frame, NOT based on the rect that gets 
>> passed in to drawRect(). I must not understand what that parameter is for.
> 
> From the UIView documentation for ‘drawRect’:
> 
>> The portion of the view’s bounds that needs to be updated. The first time 
>> your view is drawn, this rectangle is typically the entire visible bounds of 
>> your view. However, during subsequent drawing operations, the rectangle may 
>> specify only part of your view.
> 
> 
> So, yes, your code is right now. :)
> 

Its almost right – drawing should be done based on the bounds not the frame 
(this will be an issue if you either use the frame.origin or if you transform 
the view).

> ___
> 
> Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)
> 
> Please do not post admin requests or moderator comments to the list.
> Contact the moderators at cocoa-dev-admins(at)lists.apple.com
> 
> Help/Unsubscribe/Update your Subscription:
> https://lists.apple.com/mailman/options/cocoa-dev/david.duncan%40apple.com
> 
> This email sent to david.dun...@apple.com

--
David Duncan


___

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

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

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

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

Re: Confusion around tint color and UIImage rendering mode

2016-01-11 Thread David Duncan

> On Jan 11, 2016, at 3:53 PM, Rick Mann <rm...@latencyzero.com> wrote:
> 
> I have a UIButton subclass that does a lot of complex state changing, either 
> replacing its image or drawing progress into itself. The images look like 
> typical iOS 7+ icons, little blue outlines of things.
> 
> This worked well in the regular view hierarchy, but now I need to add one to 
> at UINavigationBar. I dropped it in and it made a UIBarButtonItem to contain 
> it. Everything seems to work, but it draws blue. I realized this was because 
> the image was blue.
> 
> But as I investigated, it seemed that the actual drawn color depends on the 
> UIImage's rendering mode, which was Default. I would've expected it to draw 
> it as a template while applying the tint color when the view appeared in a 
> nav bar, but it was blue. I tried changing the tint color of both the 
> UIBarButtonItem and the UIButton in IB to white, but it still came out blue.
> 
> So I changed the rendering mode in the Asset catalog for the image to 
> Template. Now it draws correctly in the nav bar, but ALSO in the regular view 
> hierarchy. That is, it's white in the nav bar (regardless of UIBarButtonItem 
> or UIButton tint color), and blue in the regular view hierarchy.
> 
> So, I'm a little confused. Any ideas what's going on?

UIBarButtonItem does not explicitly convert the image to a template for 
rendering. You can do so by calling -imageWithRenderingMoe: on your source 
image.

> 
> Thanks,
> 
> -- 
> Rick Mann
> rm...@latencyzero.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:
> https://lists.apple.com/mailman/options/cocoa-dev/david.duncan%40apple.com
> 
> This email sent to david.dun...@apple.com

--
David Duncan


___

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

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

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

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

Re: Custom font for UIAlertAction

2015-12-15 Thread David Duncan

> On Dec 15, 2015, at 8:53 AM, Wojciech Czekalski <wczekal...@me.com> wrote:
> 
> Yes, you can recursively iterate through the alert view's subviews and check 
> for a UILabel and set the font on it. It's hacky but I don't think there's 
> another way

Do NOT do things like this. The view hierarchy is considered private and the 
results of any changes you make are not guaranteed to continue working into the 
future.

> 
> Wysłane z iPhone'a
> 
> Dnia 15.12.2015 o godz. 15:44 Eric E. Dolecki <edole...@gmail.com> napisał(a):
> 
>> I am hoping to change the font for the buttons in a UIAlertController (not
>> the color, just the face as the styles give me what I want). It doesn’t
>> appear I can use an attributedString (takes String) - is there any action I
>> can take to achieve this besides subclassing?
>> 
>> Eric
>> ___
>> 
>> Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)
>> 
>> Please do not post admin requests or moderator comments to the list.
>> Contact the moderators at cocoa-dev-admins(at)lists.apple.com
>> 
>> Help/Unsubscribe/Update your Subscription:
>> https://lists.apple.com/mailman/options/cocoa-dev/wczekalski%40me.com
>> 
>> This email sent to wczekal...@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:
> https://lists.apple.com/mailman/options/cocoa-dev/david.duncan%40apple.com
> 
> This email sent to david.dun...@apple.com

--
David Duncan


___

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

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

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

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

Re: Custom font for UIAlertAction

2015-12-15 Thread David Duncan

> On Dec 15, 2015, at 10:23 AM, Wojciech Czekalski <wczekal...@me.com> wrote:
> 
> I dont recommend it either but it is possible to do it this way. It requires 
> extensive testing etc. If done properly however won't crash your app if 
> anything but will silently fail. 

What I’m saying is that UIKit won’t guarantee that this won’t someday crash 
your application. Doing things like this is wholly undefined, do not do them.

> 
> Wysłane z iPhone'a
> 
> Dnia 15.12.2015 o godz. 18:04 David Duncan <david.dun...@apple.com> 
> napisał(a):
> 
>> 
>>> On Dec 15, 2015, at 8:53 AM, Wojciech Czekalski <wczekal...@me.com> wrote:
>>> 
>>> Yes, you can recursively iterate through the alert view's subviews and 
>>> check for a UILabel and set the font on it. It's hacky but I don't think 
>>> there's another way
>> 
>> Do NOT do things like this. The view hierarchy is considered private and the 
>> results of any changes you make are not guaranteed to continue working into 
>> the future.
>> 
>>> 
>>> Wysłane z iPhone'a
>>> 
>>> Dnia 15.12.2015 o godz. 15:44 Eric E. Dolecki <edole...@gmail.com> 
>>> napisał(a):
>>> 
>>>> I am hoping to change the font for the buttons in a UIAlertController (not
>>>> the color, just the face as the styles give me what I want). It doesn’t
>>>> appear I can use an attributedString (takes String) - is there any action I
>>>> can take to achieve this besides subclassing?
>>>> 
>>>> Eric
>>>> ___
>>>> 
>>>> Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)
>>>> 
>>>> Please do not post admin requests or moderator comments to the list.
>>>> Contact the moderators at cocoa-dev-admins(at)lists.apple.com
>>>> 
>>>> Help/Unsubscribe/Update your Subscription:
>>>> https://lists.apple.com/mailman/options/cocoa-dev/wczekalski%40me.com
>>>> 
>>>> This email sent to wczekal...@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:
>>> https://lists.apple.com/mailman/options/cocoa-dev/david.duncan%40apple.com
>>> 
>>> This email sent to david.dun...@apple.com
>> 
>> --
>> David Duncan
>> 

--
David Duncan

___

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

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

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

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

Re: iPad Pro apps given more memory?

2015-12-09 Thread David Duncan

> On Dec 9, 2015, at 3:36 PM, Rick Mann <rm...@latencyzero.com> wrote:
> 
> 
>> On Dec 9, 2015, at 15:19 , Jens Alfke <j...@mooseyard.com> wrote:
>> 
>> 
>>> On Dec 9, 2015, at 2:56 PM, Rick Mann <rm...@latencyzero.com> wrote:
>>> 
>>> One of the WWDC videos stressed that iOS apps are given no more than 600 MB 
>>> of RAM. Our app is VERY RAM-intensive. 
>> 
>> Slightly off-topic, but I wonder if you could use mmap to give your app more 
>> address space? Create a big empty file, mmap it as writeable, then use a 
>> custom allocator to manage memory in the mapped space.
>> 
>> (This doesn’t actually give you more RAM; the mapped address space will tend 
>> to get paged out to storage so it’ll definitely be slower than real RAM, but 
>> it’s better than crashing!)
> 
> That's an interesting thought. We're also very compute intensive, so the 
> speed hit might obviate the advantages. Worth considering, though.

The virtual limit is 2GB on most devices right now, so you can use mmap() to go 
beyond the dirty limit.

> 
> 
> -- 
> Rick Mann
> rm...@latencyzero.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:
> https://lists.apple.com/mailman/options/cocoa-dev/david.duncan%40apple.com
> 
> This email sent to david.dun...@apple.com

--
David Duncan


___

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

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

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

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

Re: iPad Pro apps given more memory?

2015-12-09 Thread David Duncan

> On Dec 9, 2015, at 5:17 PM, Rick Mann <rm...@latencyzero.com> wrote:
> 
>> 
>> On Dec 9, 2015, at 16:42 , David Duncan <david.dun...@apple.com> wrote:
>> 
>> 
>>> On Dec 9, 2015, at 4:35 PM, Rick Mann <rm...@latencyzero.com> wrote:
>>> 
>>>> 
>>>> On Dec 9, 2015, at 16:24 , David Duncan <david.dun...@apple.com> wrote:
>>>> 
>>>> 
>>>>> On Dec 9, 2015, at 3:36 PM, Rick Mann <rm...@latencyzero.com> wrote:
>>>>> 
>>>>> 
>>>>>> On Dec 9, 2015, at 15:19 , Jens Alfke <j...@mooseyard.com> wrote:
>>>>>> 
>>>>>> 
>>>>>>> On Dec 9, 2015, at 2:56 PM, Rick Mann <rm...@latencyzero.com> wrote:
>>>>>>> 
>>>>>>> One of the WWDC videos stressed that iOS apps are given no more than 
>>>>>>> 600 MB of RAM. Our app is VERY RAM-intensive. 
>>>>>> 
>>>>>> Slightly off-topic, but I wonder if you could use mmap to give your app 
>>>>>> more address space? Create a big empty file, mmap it as writeable, then 
>>>>>> use a custom allocator to manage memory in the mapped space.
>>>>>> 
>>>>>> (This doesn’t actually give you more RAM; the mapped address space will 
>>>>>> tend to get paged out to storage so it’ll definitely be slower than real 
>>>>>> RAM, but it’s better than crashing!)
>>>>> 
>>>>> That's an interesting thought. We're also very compute intensive, so the 
>>>>> speed hit might obviate the advantages. Worth considering, though.
>>>> 
>>>> The virtual limit is 2GB on most devices right now, so you can use mmap() 
>>>> to go beyond the dirty limit.
>>> 
>>> Hi. Sorry, can you elaborate on that? Is the "virtual limit" the thing that 
>>> used to be 600 MB? What's the dirty limit, and how does it compare with the 
>>> virtual limit?
>> 
>> The virtual limit is how much virtual memory you can use. The dirty limit is 
>> how much dirty memory you can use. The dirty limit is the limit you had 
>> heard previously, I think 650MB on most devices.
> 
> Sorry, more questions, to be sure that I'm clear. If there's a discussion 
> somewhere of this already, feel free to point me to that.
> 
> - Is there still a 650 MB dirty limit, even on iPad Pro (which has 4GB, more 
> RAM than any previous device), or has that increased as well?

I think it has, but I don’t know what the size it has increased to is.

> - By "virtual memory," I'm sure you don't mean it's swapping to disk (flash). 
> Or do you? If not, how is it virtual?
> - Is there any way to programmatically determine what these limits are, for 
> diagnostic, debug, and development purposes? It would even be helpful to know 
> that we're approaching a limit, it might allow us to do something in the 
> moment to prevent being killed by iOS, even if it's at the expense of 
> execution time (something we don't want to do on a normal basis).

You can determine the virtual limit by trying to allocate memory. As long as 
you don’t write to the memory, its a virtual allocation. Once you start writing 
to it, the written to memory becomes dirty, and falls under your dirty memory 
limit. You can also use Instruments to monitor memory usage and watch when you 
hit jetsam limits (and inspect the resulting reports).

> 
> We basically work with the point clouds and images generated by our 3D 
> camera. Aligning point clouds gets more and more challenging when users have 
> more and more individual scans, as we try each new scan against all the 
> previous scans (there are some low-memory-requirement reject criteria we use, 
> but it's impossible to ignore them all). We also have another data structure 
> that grows with the number of scans conducted. During alignment, we do have 
> these peaks of memory usage that we've worked hard to reduce, but it's 
> getting more and more difficult to do so.
> 
> We'd like to be able to suggest to certain customers that an iPad Pro will be 
> able to manage larger models.
> 
> Thanks,
> 
> -- 
> Rick Mann
> rm...@latencyzero.com <mailto:rm...@latencyzero.com>
--
David Duncan

___

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

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

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

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

Re: Supporting iPad Pro keyboard in iOS apps?

2015-12-09 Thread David Duncan

> On Dec 9, 2015, at 3:55 PM, Rick Mann <rm...@latencyzero.com> wrote:
> 
>> 
>> On Dec 9, 2015, at 15:50 , SevenBits <sevenbitst...@gmail.com 
>> <mailto:sevenbitst...@gmail.com>> wrote:
>> 
>> Is it a matter of building with an newer SDK?
> 
> I don't think so; we're building with the latest.

You are probably running scaled up. If you add a default nib or storyboard you 
should run at the native device size.

> 
>> 
>> On Wednesday, December 9, 2015, Rick Mann <rm...@latencyzero.com> wrote:
>> Our app, which seems to run just fine on iPad Pro, nevertheless presents an 
>> old-style keyboard when editing fields. The iPad Pro has a (graphical) 
>> keyboard with more keys than previous devices. But ours shows a blown-up 
>> version of the older keyboard.
>> 
>> No matter what search term I use, I can't find anything about this from a 
>> developer's perspective, just discussions about iPad Pro features.
>> 
>> I'm hoping it's something trivial we need to adjust in our app.
>> 
>> Thoughts? Thanks!
>> 
>> --
>> Rick Mann
>> rm...@latencyzero.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:
>> https://lists.apple.com/mailman/options/cocoa-dev/sevenbitstech%40gmail.com
>> 
>> This email sent to sevenbitst...@gmail.com
> 
> 
> -- 
> Rick Mann
> rm...@latencyzero.com <mailto:rm...@latencyzero.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:
> https://lists.apple.com/mailman/options/cocoa-dev/david.duncan%40apple.com
> 
> This email sent to david.dun...@apple.com

--
David Duncan

___

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

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

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

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

Re: iPad Pro apps given more memory?

2015-12-09 Thread David Duncan

> On Dec 9, 2015, at 4:35 PM, Rick Mann <rm...@latencyzero.com> wrote:
> 
>> 
>> On Dec 9, 2015, at 16:24 , David Duncan <david.dun...@apple.com> wrote:
>> 
>> 
>>> On Dec 9, 2015, at 3:36 PM, Rick Mann <rm...@latencyzero.com> wrote:
>>> 
>>> 
>>>> On Dec 9, 2015, at 15:19 , Jens Alfke <j...@mooseyard.com> wrote:
>>>> 
>>>> 
>>>>> On Dec 9, 2015, at 2:56 PM, Rick Mann <rm...@latencyzero.com> wrote:
>>>>> 
>>>>> One of the WWDC videos stressed that iOS apps are given no more than 600 
>>>>> MB of RAM. Our app is VERY RAM-intensive. 
>>>> 
>>>> Slightly off-topic, but I wonder if you could use mmap to give your app 
>>>> more address space? Create a big empty file, mmap it as writeable, then 
>>>> use a custom allocator to manage memory in the mapped space.
>>>> 
>>>> (This doesn’t actually give you more RAM; the mapped address space will 
>>>> tend to get paged out to storage so it’ll definitely be slower than real 
>>>> RAM, but it’s better than crashing!)
>>> 
>>> That's an interesting thought. We're also very compute intensive, so the 
>>> speed hit might obviate the advantages. Worth considering, though.
>> 
>> The virtual limit is 2GB on most devices right now, so you can use mmap() to 
>> go beyond the dirty limit.
> 
> Hi. Sorry, can you elaborate on that? Is the "virtual limit" the thing that 
> used to be 600 MB? What's the dirty limit, and how does it compare with the 
> virtual limit?

The virtual limit is how much virtual memory you can use. The dirty limit is 
how much dirty memory you can use. The dirty limit is the limit you had heard 
previously, I think 650MB on most devices.

> 
> Thanks,
> 
> 
> -- 
> Rick Mann
> rm...@latencyzero.com <mailto:rm...@latencyzero.com>
--
David Duncan

___

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

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

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

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

Re: Adding minutes to display time

2015-12-08 Thread David Duncan

> On Dec 8, 2015, at 12:14 PM, Eric E. Dolecki <edole...@gmail.com> wrote:
> 
> Hey all,
> 
> I am being supplied a time (not day specific). Say "7:30 AM" - as a string.
> Could be PM.
> 
> I need to make a slider with a range of 1 minute to 120 mins. Moving the
> slider adjusts the 7:30 AM display. So I am adding minutes to the display
> time. What's the best way to do this? I am using Swift.

NSCalendar and NSDateComponents are still the best way to do these types of 
time modifications (with NSDateFormatter for display).

> 
> I'll be googling too.
> 
> Thanks,
> Eric
> ___
> 
> Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)
> 
> Please do not post admin requests or moderator comments to the list.
> Contact the moderators at cocoa-dev-admins(at)lists.apple.com
> 
> Help/Unsubscribe/Update your Subscription:
> https://lists.apple.com/mailman/options/cocoa-dev/david.duncan%40apple.com
> 
> This email sent to david.dun...@apple.com

--
David Duncan


___

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

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

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

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

Re: Adding minutes to display time

2015-12-08 Thread David Duncan

> On Dec 8, 2015, at 2:04 PM, Eric E. Dolecki <edole...@gmail.com> wrote:
> 
> I tried an extension I found. It's off by 5 hours...
> 
> extension NSDate
> {
> convenience
> init(dateString:String) {
> let dateStringFormatter = NSDateFormatter()
> dateStringFormatter.calendar = NSCalendar(calendarIdentifier: 
> NSCalendarIdentifierGregorian)
> dateStringFormatter.dateFormat = "-MM-dd HH:mm"
> dateStringFormatter.locale = NSLocale(localeIdentifier: "en_US_POSIX")
> dateStringFormatter.timeZone = NSTimeZone.localTimeZone()
> let d = dateStringFormatter.dateFromString(dateString)!
> self.init(timeInterval:0, sinceDate:d)
> }
> }
> 
> ...
> 
> let calendar = NSCalendar.currentCalendar()
> calendar.timeZone = NSTimeZone.localTimeZone()
> calendar.locale = NSLocale(localeIdentifier: "en_US_POSIX")
> let startDate = NSDate(dateString:"2015-12-08 7:30")
> let date = calendar.dateByAddingUnit(.Minute, value: 5, toDate: 
> startDate, options: [])
> print (date!) //This is way off. How to fix this?

A NSDate’s description aways prints its time in UTC, not the local time zone. 
If you print the result of a properly constructed NSDateFormatter you should 
see the correct results.

> 
> 
> 
> On Tue, Dec 8, 2015 at 3:54 PM David Duncan <david.dun...@apple.com 
> <mailto:david.dun...@apple.com>> wrote:
> 
> > On Dec 8, 2015, at 12:14 PM, Eric E. Dolecki <edole...@gmail.com 
> > <mailto:edole...@gmail.com>> wrote:
> >
> > Hey all,
> >
> > I am being supplied a time (not day specific). Say "7:30 AM" - as a string.
> > Could be PM.
> >
> > I need to make a slider with a range of 1 minute to 120 mins. Moving the
> > slider adjusts the 7:30 AM display. So I am adding minutes to the display
> > time. What's the best way to do this? I am using Swift.
> 
> NSCalendar and NSDateComponents are still the best way to do these types of 
> time modifications (with NSDateFormatter for display).
> 
> >
> > I'll be googling too.
> >
> > Thanks,
> > Eric
> > ___
> >
> > Cocoa-dev mailing list (Cocoa-dev@lists.apple.com 
> > <mailto: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 
> > <http://lists.apple.com/>
> >
> > Help/Unsubscribe/Update your Subscription:
> > https://lists.apple.com/mailman/options/cocoa-dev/david.duncan%40apple.com 
> > <https://lists.apple.com/mailman/options/cocoa-dev/david.duncan%40apple.com>
> >
> > This email sent to david.dun...@apple.com <mailto:david.dun...@apple.com>
> 
> --
> David Duncan
> 

--
David Duncan

___

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

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

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

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

Re: UIView underlying rects for drawRect

2015-12-07 Thread David Duncan

> On Dec 6, 2015, at 4:51 AM, Roland King <r...@rols.org> wrote:
> 
>> 
>> On 6 Dec 2015, at 20:18, Roland King <r...@rols.org> wrote:
>> 
>> 
>>> 
>>> CALayer has a mechanism built in for the sort of thing you want to do. Read 
>>> up on -[CALayer display]. You should be able to override that, or implement 
>>> the corresponding delegate method in your UIView and perform management of 
>>> your custom bitmap there. I myself do this in one app to share one bitmap 
>>> between multiple layers for example.
>>> 
>>> The other thing worth investigating perhaps is whether CATiledLayer would 
>>> better suit your drawing needs, or if you could split your custom view up 
>>> into a series of sub-views, so you only need invalidate slices of one or 
>>> two of them.
>>> 
>>> Mike.
>> 
>> That’s what I was just trying. I made a subclass of CALayer() and overrode 
>> just display() to do absolutely nothing at all, except print ‘display()’. I 
>> then made a UIView subclass which overrides layerClass() to return the type 
>> and stuck one such view randomly in my NIB. The view is made, the layer is 
>> created .. and absolutely nothing else happens. I expected to get at least 
>> ONE call to display() as the view/layer starts dirty, but I don’t get even 
>> that. I even hooked up a button to call setNeedsDisplay on the view but that 
>> didn’t prompt it either. I overrode a bunch of other methods too to print 
>> but the only one which currently gets called is init(). 
>> 
>> I expected the UIView would drive at least an initial setNeedsDisplay on the 
>> layer, and a setNeedsDisplay on the view would end up being passed-through, 
>> but it doesn’t. Calling setNeedsDisplay on the actual layer object itself 
>> seems to work, but I did sort of expect the UIView to do some things with 
>> the layer automatically. Guess I was wrong and I will need to hook all those 
>> bits up for myself. 
> 
> ok I begin to see how it all works now. So if the layer is the view’s layer, 
> instead of a separate totally custom layer you add to the layer, then the 
> view sets some things on it but not everything. It turns off 
> needsDisplayOnBoundsChange (which I had set on init in the layer) unless the 
> view’s contentMode is redraw, which somewhat confused me. That causes the 
> layer to call display() on itself on bounds change. However it doesn’t pass 
> setNeedsDisplay() and setNeedsDisplayInRect() through to the underlying layer 
> which I’d have expected. I assume it only calls those that if the layer is a 
> normal UIView layer and not a custom one. 

UIView will not dirty its layer if your subclass does not implement -drawRect:.

> 
> I think as long as that’s the extent of its meddling with ‘its layer’, just 
> setting a few properties when it starts up and adjusting the bounds for me, I 
> can live with it. I’ll try out a few more things on the view to see if there 
> are other things I need to be prepared to deal with, just having it manage 
> the layer bounds automatically is helpful if that’s about all it does. 
> 
> 
> ___
> 
> Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)
> 
> Please do not post admin requests or moderator comments to the list.
> Contact the moderators at cocoa-dev-admins(at)lists.apple.com
> 
> Help/Unsubscribe/Update your Subscription:
> https://lists.apple.com/mailman/options/cocoa-dev/david.duncan%40apple.com
> 
> This email sent to david.dun...@apple.com

--
David Duncan

___

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

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

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

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

Re: The joys of people using valueForKey to get objects out of a dictionary.

2015-11-10 Thread David Duncan

> On Nov 10, 2015, at 8:32 AM, Alex Zavatone <z...@mac.com> wrote:
> 
> It's been about 4 or 5 years since I made this mistake but I've just seen a 
> massive swath of code where every access of a dictionary object is using 
> valueForKey instead of objectForKey.
> 
> I've got a few examples of why this is a "really bad idea"™, and certainly 
> might explain why lots of that code is wrapped in try/catch blocks.
> 
> Am I correct that using valueForKey will raise an exception if the key is 
> missing?
> 
> Looking for reasons why I can explain "yeah, I know it works, but here's why 
> it's a terrible idea to use to access a dictionary's objects".
> 
> Thanks in advance.


I will note that the exception throwing behavior is implementation dependent - 
NSDictionary may not throw but I’ve had experience with other objects that do, 
and this may be the generic behavior on NSObject (I haven’t checked).
--
David Duncan


___

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

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

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

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

Re: Fade when changing window's rootViewController possible?

2015-11-09 Thread David Duncan

> On Nov 7, 2015, at 11:31 PM, Diederik Meijer <diede...@tenhorses.com> wrote:
> 
> Thank you David,
> 
> I forgot to mention that one of them is a UISplitViewController and - unless 
> this has changed - that one can not be presented modally.

I’m not aware of any particular reason why a split view controller could not be 
presented modally. Alternatively you could present the other view controller 
with no animation and then dismiss it when you want to reveal the split view 
controller.

> It is for this reason that I want to switch the window’s rootViewController. 
> Otherwise, a plain presentViewController would definitely make a lot more 
> sense :-)
> 
> This is what I actually found briefly after sending the question (method 
> edited for my app’s specifics and original code found not in a separate 
> method).
> 
> Method added to appDelegate:
> 
> -(void)switchWindowRootVCTo:(NSString *)newVCString {
> id newVC = nil;
> if ([newVCString isEqual:@"UISplitViewController"]) newVC = self.svc;
> else if ([newVCString isEqual:@"THWelcomeVC"]) newVC = self.wvc;
> self.window.rootViewController = newVC;
> [UIView transitionWithView:self.window 
>   duration:0.50
>   options:UIViewAnimationOptionTransitionCrossDissolve 
> animations:^{ 
>   self.window.rootViewController = newVC; 
>   }
>   completion:nil];
> }
> 
> So both the old and the new root VC are properties of the appDelegate 
> (self.svc and self.wvc respectively) and they are both initialized in 
> applicationDidiFinishLaunching.
> 
> Each of them can call the above method of the app delegate and trigger the 
> switch.
> 
> 
> Best regards,
> 
> 
> 
> Diederik
> 
> 
> 
>> Op 8 nov. 2015, om 04:36 heeft David Duncan <david.dun...@apple.com 
>> <mailto:david.dun...@apple.com>> het volgende geschreven:
>> 
>>> 
>>> On Nov 7, 2015, at 1:30 PM, Diederik Meijer <diede...@tenhorses.com 
>>> <mailto:diede...@tenhorses.com>> wrote:
>>> 
>>> Dear list,
>>> 
>>> Is it possible to change an iOS app window’s rootViewController at runtime 
>>> and have a fade animation between the two states happen?
>> 
>> Not trivially, but you can do this trivially by presenting your 
>> “replacement” view controller modally, which is also the more supported path 
>> (by far).
>> 
>>> 
>>> Obviously there is no modal or push presentation, the view is just replaced 
>>> by a new one. For this reason a fade between the two would be nice.
>>> 
>>> This is for iOS 8 and up, coding in Objective-C.
>>> 
>>> 
>>> Many thanks,
>>> 
>>> 
>>> 
>>> Diederik
>>> 
>>> 
>>> 
>>> ___
>>> 
>>> Cocoa-dev mailing list (Cocoa-dev@lists.apple.com 
>>> <mailto: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 
>>> <http://lists.apple.com/>
>>> 
>>> Help/Unsubscribe/Update your Subscription:
>>> https://lists.apple.com/mailman/options/cocoa-dev/david.duncan%40apple.com 
>>> <https://lists.apple.com/mailman/options/cocoa-dev/david.duncan%40apple.com>
>>> 
>>> This email sent to david.dun...@apple.com <mailto:david.dun...@apple.com>
>> 
>> --
>> David Duncan
> 

--
David Duncan

___

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

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

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

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

Re: Fade when changing window's rootViewController possible?

2015-11-07 Thread David Duncan

> On Nov 7, 2015, at 1:30 PM, Diederik Meijer <diede...@tenhorses.com> wrote:
> 
> Dear list,
> 
> Is it possible to change an iOS app window’s rootViewController at runtime 
> and have a fade animation between the two states happen?

Not trivially, but you can do this trivially by presenting your “replacement” 
view controller modally, which is also the more supported path (by far).

> 
> Obviously there is no modal or push presentation, the view is just replaced 
> by a new one. For this reason a fade between the two would be nice.
> 
> This is for iOS 8 and up, coding in Objective-C.
> 
> 
> Many thanks,
> 
> 
> 
> Diederik
> 
> 
> 
> ___
> 
> Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)
> 
> Please do not post admin requests or moderator comments to the list.
> Contact the moderators at cocoa-dev-admins(at)lists.apple.com
> 
> Help/Unsubscribe/Update your Subscription:
> https://lists.apple.com/mailman/options/cocoa-dev/david.duncan%40apple.com
> 
> This email sent to david.dun...@apple.com

--
David Duncan


___

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

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

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

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

Re: 'barHideOnSwipeGestureRecognizer' works with two UIScrollViews but not with two others

2015-11-06 Thread David Duncan

> On Nov 6, 2015, at 8:04 AM, David Hoerl <dho...@mac.com> wrote:
> 
> I know this is an esoteric question.
> 
> I enabled 'hidesBarsOnSwipe' in my MMSpreadSheet view controller. This UIView 
> subclass has 4 UICollectionViews in it - two up top and two below.
> 
> The top left 'corner' controller does not scroll, and the top right does not 
> scroll vertically. Out of the box up/down swipes work perfectly with the 
> barHideOnSwipeGestureRecognizer to get the Navigation Bar to hide/show.
> 
> But try as I might, I cannot get the bottom two views to provide the same 
> functionality, both of which scroll vertically. I tried adding a new 
> UIPanGestureRecognizer to the collectionView that returns 'true' when sent 
> the delegate message 'shouldRecognizeSimultaneouslyWithGestureRecognizer'. 
> Interesting that I actually get asked if this new recognizer should work with 
> both the 'barHideOnSwipeGestureRecognizer' and the CollectionView's 
> panGestureRecognizer (I return 'true' for both).
> 
> I also configured this new recognizer to exactly match the configuration of 
> the UICollectionViews panGestureRecognizer.
> 
> Just odd that the barHideOnSwipeGestureRecognizer has added itself to the 
> collection view, but refuses to handle the swipe.

The scroll (collection) view needs to abut or underlap the navigation bar for 
the gesture to recognize, which is why your bottom collection views don’t work. 
There isn’t a way to override this behavior, so I don’t really have any good 
answers for how you might obtain it.

> 
> Any suggestions?
> 
> - David
> ___
> 
> Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)
> 
> Please do not post admin requests or moderator comments to the list.
> Contact the moderators at cocoa-dev-admins(at)lists.apple.com
> 
> Help/Unsubscribe/Update your Subscription:
> https://lists.apple.com/mailman/options/cocoa-dev/david.duncan%40apple.com
> 
> This email sent to david.dun...@apple.com

--
David Duncan


___

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

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

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

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

Re: runOnMainQueueWithoutDeadlocking and all its evils.

2015-11-06 Thread David Duncan

> On Nov 6, 2015, at 8:36 AM, Alex Zavatone <z...@mac.com> wrote:
> 
> Bearing in mind my experience dealing with code in the past that was chock 
> full of runOnMainQueueWithoutDeadlocking calls, I can not fathom why someone 
> who was not updating the UI would need to use this type of approach… 
> everywhere.
> 
> Besides complete ineptitude, is there a rational reason that any one of you 
> can think of why someone would be using this for GCD dispatches instead of 
> just making and using their own GCD dispatch queue?
> 
> Before I start destroying the universe and changing this (in a fork), I'd 
> like to hear the words of those much smarter than I on this subject.
> 
> 
> But seriously, WHY?

Roughly this approach reads like a lock that uses the main queue as its locking 
point. Without understanding what is being protected, it is hard to tell why 
this is being done.

The usage of dispatch_sync() says that whomever wrote this expected to have the 
results available immediately. If not, then simply switching to 
dispatch_async() may be sufficient in many cases. Beyond that you will probably 
need to evaluate what work is being done in these cases.

> 
> Thank you.
> 
> - Alex Zavatone
> 
> 
> 
> 
> 
> ___
> 
> Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)
> 
> Please do not post admin requests or moderator comments to the list.
> Contact the moderators at cocoa-dev-admins(at)lists.apple.com
> 
> Help/Unsubscribe/Update your Subscription:
> https://lists.apple.com/mailman/options/cocoa-dev/david.duncan%40apple.com
> 
> This email sent to david.dun...@apple.com

--
David Duncan


___

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

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

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

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

  1   2   3   4   5   6   7   8   9   10   >