[ANN] Open source Cocoa Google Reader class

2011-05-26 Thread Daniel Isenhower
Just thought I would throw this out there in case it's of help to anyone.

https://github.com/perspecdev/PSGoogleReader
___

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

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

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

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


Duplicate records adding to an NSTableView + NSArrayController

2011-05-26 Thread Darren Wheatley
Hi,

I have an NSTableView bound to an NSArrayController, itself bound to a Core 
Data store.

The app is working as expected, with two exceptions:

1. Duplicate records:

I have an "add" button bound to arraycontroller.insert

I have created a newObject method to allow me to define default values, which 
works fine. When I click add a new record gets inserted, but it appears twice 
in the NSTableView. However, if I save the moc, close and reopen the 
application only one record is present.

So although it looks like two duplicate records are added, only one is actually 
present.

Can anyone tell me why two records are visible when I add a new record, but not 
on subsequent runs of the application?


2. Calculating max records

Within my "newObject" method I perform a fetch on the moc to determine the MAX 
value for the "ID" field.

This works fine, but the @max.id value is not updated unless I save the MOC 
after adding each new record. If I don't save the moc the max: function returns 
the same value as for the previous run.

Unless I am missing something obvious all of my objects use the same moc 
(defined centrally, and then passed around).

Can anyone suggest why the max: function is only working properly after a moc 
save?


Thanks in advance

Darren.




___

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

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

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

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


How to implement "while there are objects in the array - run runloop" idea?

2011-05-26 Thread Nick
Hello
Could you please give me an idea how to implement this task?

I have a custom (not main) thread, that adds objects to an NSArray at random
times.
I have an another thread (main thread) that has to retrieve these objects
and do something with them (extract some properties from the retrieved
object and make an NSURLConnection's asynchronous connection).

Is there any way to make the RunLoop (after it has processed all
NSUrlConnection's asynchronous things)  check, if there are some objects in
my NSArray queue, and if there are - to initiate new NSURLConnections, if
there are not, and if there are no other events pending, just 'block', as
the runloop always does?

Or, if there is no way to do this using the runloop itself, what would be
the most natural way to solve such a task? I am stuck at this.
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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

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


Drawing an arc fill inside an image

2011-05-26 Thread Alex Kac
I'm not sure what the best way to tackle this is... so I thought I'd ask here. 
I have an image with a circular button inside of it. I'd like to dynamically 
fill this button in an arc to show "progress" much like how when you are on 
iTunes Store on an iOS and its playing the preview its animating filling the 
circle in a sweep of an arc. Mine doesn't need to animate however.

So I have the image, and I suppose I can draw that image to a context and then 
draw an arc on that image, and then make another image out of it. That seems 
like it would get slow if I needed to do that a lot. Any suggestions? I also 
wouldn't mind any links that might show similar code. This is for iOS. I tried 
searching Google, but my GoogleFu is not showing anything, probably due to me 
not using the right terms.

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

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


Best way to handle iOS device rotation

2011-05-26 Thread koko
Should I make two views Portrait and Landscape to handle iOS device rotation or 
should struts and springs take care of that for me?

koko

"Don't fight the framework."
--Kyle Sluder

___

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

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

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

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


Re: Best way to handle iOS device rotation

2011-05-26 Thread David Duncan
On May 26, 2011, at 11:24 AM, koko wrote:

> Should I make two views Portrait and Landscape to handle iOS device rotation 
> or should struts and springs take care of that for me?


Springs & Struts can do a lot, but if you need some custom layout you can do it 
during the UIViewController orientation callbacks (see the documentation for 
details) or by implementing -layoutSubviews on relevant views in your view 
hierarchy.
--
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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

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


Re: Best way to handle iOS device rotation

2011-05-26 Thread Fritz Anderson
On 26 May 2011, at 1:24 PM, koko wrote:

> Should I make two views Portrait and Landscape to handle iOS device rotation 
> or should struts and springs take care of that for me?

Don't make two views. Start with auto-resizing (struts and springs). That 
should be enough in 95% of cases. If you have something very fancy to do, look 
at implementing one or two of the willAnimate... methods in UIViewController.

— F

___

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

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

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

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


Re: How to implement "while there are objects in the array - run runloop" idea?

2011-05-26 Thread Stephen J. Butler
On Thu, May 26, 2011 at 12:56 PM, Nick  wrote:
> I have a custom (not main) thread, that adds objects to an NSArray at random
> times.
> I have an another thread (main thread) that has to retrieve these objects
> and do something with them (extract some properties from the retrieved
> object and make an NSURLConnection's asynchronous connection).

How are you synchronizing access to the shared array? Lock objects?

You might want to abandon that approach and not add objects from the
background thread directly to the shared array. Instead, you could
"signal" the main thread that a new object is ready to be processed.
Some common methods:

- Distributed Objects/NSConnection. The main thread would be your
server and your background thread the client. The client would call
something like [proxy processObject:blah] and the main thread would
perform the action.

- Use mach pipes to pass objects to the main thread. mach pipes can be
added as a source to the runloop. Either serialize and pass the object
over the pipe itself, or (since you are in the same address space)
just pass a token single byte message over the pipe to notify the main
thread that a new object has been added to the array to be processed.

- Use NSObject's performSelectorOnMainThread:withObject:waitUntilDone
to message the main thread directly from the background thread and
hand off the new object to be processed. Or you could still add the
object to the shared array and use
performSelectorOnMainThread:withObject:waitUntilDone to notify the
main thread.

- Use NSNotifications to notify that a new object is waiting to be
processed. If you go this route, you could actually have multiple
processing threads all listening for the notification.
___

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

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

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

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


Re: How to implement "while there are objects in the array - run runloop" idea?

2011-05-26 Thread Jens Alfke

On May 26, 2011, at 10:56 AM, Nick wrote:

> I have a custom (not main) thread, that adds objects to an NSArray at random 
> times.
> ...
> Is there any way to make the RunLoop (after it has processed all
> NSUrlConnection's asynchronous things)  check, if there are some objects in
> my NSArray queue, and if there are - to initiate new NSURLConnections, if
> there are not, and if there are no other events pending, just 'block', as
> the runloop always does?

The background thread needs to do something to wake up the main runloop after 
it adds an object to the array. Calling -performSelectorOnMainThread: would be 
an ideal way to do this. If you do that, you may not even need to use an array 
to queue the objects; instead just pass each object to the main thread as the 
parameter to that perform.

—Jens

smime.p7s
Description: S/MIME cryptographic signature
___

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

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

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

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


Re: How to implement "while there are objects in the array - run runloop" idea?

2011-05-26 Thread Ken Thomases
On May 26, 2011, at 1:35 PM, Stephen J. Butler wrote:

> - Use NSNotifications to notify that a new object is waiting to be
> processed. If you go this route, you could actually have multiple
> processing threads all listening for the notification.

Notifications are delivered on the same thread as they are posted.  So, this 
doesn't help get work from one thread to another (or several others).  You can, 
upon receiving a notification, initiate some work on another thread, but that 
gets you back to square one as far as this discussion is concerned.

Regards,
Ken

___

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

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

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

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


Re: Drawing an arc fill inside an image

2011-05-26 Thread Jens Alfke

On May 26, 2011, at 11:21 AM, Alex Kac wrote:

> So I have the image, and I suppose I can draw that image to a context and 
> then draw an arc on that image, and then make another image out of it. That 
> seems like it would get slow if I needed to do that a lot.


No need to make a new image. Just draw directly into the original one:

[image lockFocus];
…draw stuff…
[image unlockFocus];

—Jens

smime.p7s
Description: S/MIME cryptographic signature
___

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

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

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

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


Why do things wind up under the nav bar after rotation?

2011-05-26 Thread G S
Hi all.  I'm having a layout problem on all my screens after they're
rotated.  It seems as though the view loses all knowledge of the
navigation bar at the top after a rotation, so subviews are shoved up
under it.  Check it out:

http://i.stack.imgur.com/mFALa.png

It's not just this view.  It also occurs on a view that contains a
UITableView, which is loaded from a XIB (unlike the one above).  I
have autoresizing set in all directions.  The problem corrects itself
on the screen depicted above if I push another view onto the
navigation stack and then pop it, but I don't know what's being called
to bring about the correction.  On the tableview screen, the view
corrects itself when the tableview is tapped.

I've tried calling setNeedsLayout after the rotation finishes, but
that had no effect.  I also tried calling viewWillAppear (thinking
that might have triggered the correction), but that didn't do it
either.

Any ideas?  Thanks!

Gavin
___

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

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

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

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


Re: How to implement "while there are objects in the array - run runloop" idea?

2011-05-26 Thread Stephen J. Butler
On Thu, May 26, 2011 at 1:39 PM, Ken Thomases  wrote:
> On May 26, 2011, at 1:35 PM, Stephen J. Butler wrote:
>> - Use NSNotifications to notify that a new object is waiting to be
>> processed. If you go this route, you could actually have multiple
>> processing threads all listening for the notification.
>
> Notifications are delivered on the same thread as they are posted.  So, this 
> doesn't help get work from one thread to another (or several others).  You 
> can, upon receiving a notification, initiate some work on another thread, but 
> that gets you back to square one as far as this discussion is concerned.

Huh... I don't know why I thought notifications were process wide. Too
little caffeine today.
___

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

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

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

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


Re: Drawing an arc fill inside an image

2011-05-26 Thread Steve Christensen
Custom view that sits on top of a UIImageView? Implement -drawRect: and a 
progress property and you're done.


On May 26, 2011, at 11:21 AM, Alex Kac wrote:

> I'm not sure what the best way to tackle this is... so I thought I'd ask 
> here. I have an image with a circular button inside of it. I'd like to 
> dynamically fill this button in an arc to show "progress" much like how when 
> you are on iTunes Store on an iOS and its playing the preview its animating 
> filling the circle in a sweep of an arc. Mine doesn't need to animate however.
> 
> So I have the image, and I suppose I can draw that image to a context and 
> then draw an arc on that image, and then make another image out of it. That 
> seems like it would get slow if I needed to do that a lot. Any suggestions? I 
> also wouldn't mind any links that might show similar code. This is for iOS. I 
> tried searching Google, but my GoogleFu is not showing anything, probably due 
> to me not using the right terms.

___

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

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

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

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


Re: Best way to handle iOS device rotation

2011-05-26 Thread koko
Thanks David and Fritz ... always best to check the path !

koko

"Don't fight the framework."
--Kyle Sluder

On May 26, 2011, at 12:32 PM, David Duncan wrote:

> On May 26, 2011, at 11:24 AM, koko wrote:
> 
>> Should I make two views Portrait and Landscape to handle iOS device rotation 
>> or should struts and springs take care of that for me?
> 
> 
> Springs & Struts can do a lot, but if you need some custom layout you can do 
> it during the UIViewController orientation callbacks (see the documentation 
> for details) or by implementing -layoutSubviews on relevant views in your 
> view hierarchy.
> --
> 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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

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


Re: Why do things wind up under the nav bar after rotation?

2011-05-26 Thread G S
Resolved. Turns out that doing this after rotation will re-align everything:

[self.navigationController.view layoutSubviews];

Kinda seems like the framework would call that, but I guess not.
___

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

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

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

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


Re: Why do things wind up under the nav bar after rotation?

2011-05-26 Thread David Duncan
On May 26, 2011, at 12:00 PM, G S wrote:

> Resolved. Turns out that doing this after rotation will re-align everything:
> 
>   [self.navigationController.view layoutSubviews];
> 
> Kinda seems like the framework would call that, but I guess not.

It should and this shouldn't be necessary. A bug report would be good here.
--
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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

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


Re: How to implement "while there are objects in the array - run runloop" idea?

2011-05-26 Thread Stephen J. Butler
On Thu, May 26, 2011 at 1:35 PM, Stephen J. Butler
 wrote:
> You might want to abandon that approach and not add objects from the
> background thread directly to the shared array. Instead, you could
> "signal" the main thread that a new object is ready to be processed.
> Some common methods:

- Just thought of this: blocks and dispatch queues. There's a special
one just for the main thread. I suppose this is the most modern way to
do it!
___

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

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

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

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


Re: Drawing an arc fill inside an image

2011-05-26 Thread Conrad Shultz
The OP wants a solution for iOS. lock/unlockFocus only exist in NSView, not 
UIView. 

FWIW, I think you (that is, the OP) should start with the simplest solution 
available (e.g. Steve's suggestion), test performance, and only optimize if 
needed. Don't try to optimize if it's not actually required!

--
Conrad Shultz
www.synthetiqsolutions.com

On May 26, 2011, at 11:40, Jens Alfke  wrote:
> [image lockFocus];
> …draw stuff…
> [image unlockFocus];

___

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

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

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

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


IKScannerDeviceView transferMode set to memory

2011-05-26 Thread Tom Hohensee
I am currently rewiring a scanner application which I originally wrote some 
years ago using the TWAIN driver directly into the more modern ImageKit 
IKScannerDeviceView .  I thought that I could customize it enough to meet my 
needs without having to build it using ImageCaptureCore framework with 
extremely limited docs.   I am gathering most of my info from the headers which 
is not to poorly documented but still limited.  Before I abandon the 
convenience of IKScannerDeviceView, I want to confirm some troubles I am having 
with it to be sure that I am not missing some undocumented methods or 
workaround. I have been googling for days through this process but have turned 
up empty.

The goal of my app is to have a scan (or multiple scans) go into memory and 
converted to a multi PDF document by my controller class.  Limited UI settings 
needed.
 
1.  Memory Mode. 
Setting up purely in IB using an IKDeviceBrowserView to discover the scanner(s) 
and setting IKScannerDeviceView as it's delegate works well.  However, setting 
the transferMode to memory in IB does not work.  Basically what I end up with 
is the Image capture app (file mode only). 

 I have tried setting my controller as the delegate and handling the 
IKDeviceBrowserView delegate - (void)deviceBrowserView:(IKDeviceBrowserView 
*)deviceBrowserView selectionDidChange:(ICDevice *)device  Here I set the 
transferMode manually and it works.  However if I change the functionalUnit on 
the scanner using the standard IKScannerDeviceView (ie from flat bed to 
document feeder) I am back to file mode permanently. 
 I am not sure why this is happening as from what I can tell from the headers 
the functional unit change simple makes multiple (1 per page or image in doc 
feeder mode) calls to IKScannerDeviceView delegate - 
(void)scannerDeviceView:(IKScannerDeviceView *)scannerDeviceView 
didScanToURL:(NSURL *)url fileData:(NSData *)data error:(NSError *)error.   
There seems to be no other place to set the transferMode that would affect 
this.  I have tried various other customizations in IKDeviceBrowser delegate 
method and they work as well as survive the functionalUnit change.

2.  UI elements.  
In IB I am able to choose between Simple and Advance modes, Post processing and 
various UI other options.  Setting them in IB works.  However, the checkbox for 
"select separate items"   is the only UI item that is not able to be set or 
removed.  I find this odd as It is the only element  that is not an option in 
IB or documented in the headers.  

Are these Bugs in IKScannerView IB or am I just missing something?

Thanks
Tom___

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

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

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

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


Re: Drawing an arc fill inside an image

2011-05-26 Thread Alex Kac
Sure, I get the idea of only optimizing if needed. That said, experience (15 
years) tells me very strongly that if I know that X will be slow and Y will be 
fast and either way works properly, I'd probably choose Y. So I prefer to stand 
on the shoulders of giants where possible. I've got a working solution - thanks 
guys!

On May 26, 2011, at 2:46 PM, Conrad Shultz wrote:

> The OP wants a solution for iOS. lock/unlockFocus only exist in NSView, not 
> UIView. 
> 
> FWIW, I think you (that is, the OP) should start with the simplest solution 
> available (e.g. Steve's suggestion), test performance, and only optimize if 
> needed. Don't try to optimize if it's not actually required!
> 
> --
> Conrad Shultz
> www.synthetiqsolutions.com
> 
> On May 26, 2011, at 11:40, Jens Alfke  wrote:
>> [image lockFocus];
>> …draw stuff…
>> [image unlockFocus];
> 

Alex Kac - President and Founder
Web Information Solutions, Inc.

"Patience is the companion of wisdom."
--Anonymous




___

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

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

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

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


Re: Why do things wind up under the nav bar after rotation?

2011-05-26 Thread G S
>> Kinda seems like the framework would call that, but I guess not.
>
> It should and this shouldn't be necessary. A bug report would be good here.

Yes, I'm going to file one.  While this workaround straightens the
layout after rotation, it's a little janky because things snap into
place after the rotation's done instead of animating smoothly into
place.

Also, it doesn't work with anything but custom view controllers.  For
example, I present a simple information panel in a UIView, but that's
illegible after rotation because it's shoved up under the nav bar.  To
fix that, I'm going to have to derive a whole class from
UIViewController (or make a category) just to call layoutSubviews
after a rotation.  Lame.
___

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

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

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

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


Re: Why do things wind up under the nav bar after rotation?

2011-05-26 Thread David Duncan
On May 26, 2011, at 2:39 PM, G S wrote:

>>> Kinda seems like the framework would call that, but I guess not.
>> 
>> It should and this shouldn't be necessary. A bug report would be good here.
> 
> Yes, I'm going to file one.  While this workaround straightens the
> layout after rotation, it's a little janky because things snap into
> place after the rotation's done instead of animating smoothly into
> place.
> 
> Also, it doesn't work with anything but custom view controllers.  For
> example, I present a simple information panel in a UIView, but that's
> illegible after rotation because it's shoved up under the nav bar.  To
> fix that, I'm going to have to derive a whole class from
> UIViewController (or make a category) just to call layoutSubviews
> after a rotation.  Lame.


This makes me wonder how your view controllers are laid out. I don't suppose 
you added the contents that are having trouble by taking a view from one view 
controller and adding it as a subview to a view owned (directly or indirectly) 
by another view controller?
--
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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

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


Using an iPhone to control a Mac- source code?

2011-05-26 Thread Tom Jeffries
This may be the wrong forum for this question- if so, please let me know.

I want to use an iPhone to act as mouse and keyboard for a Mac. It looks
like the best connection is through a network, although Bluetooth might also
work.  There are other apps that do this. I'd love some sample code so I
don't have to wade through the whole networking protocol.

Suggestions?

Thanks, Tom Jeffries
___

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

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

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

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


Seeding random() randomly

2011-05-26 Thread Graham Cox
I'm using random(), but every time I run my app I get the same sequence, 
despite having this code in my app delegate's -appDidFinishLaunching method. 
Clearly I'm not seeding it right, though I can't see why - I get a different 
value for seed every time. What gives?


unsigned seed = (unsigned)([NSDate timeIntervalSinceReferenceDate] * 
1.0);

NSLog(@"launched, seed = %ld", seed );
srandom( seed );


--Graham


___

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

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

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

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


Re: Seeding random() randomly

2011-05-26 Thread Dave Keck
> I'm using random(), but every time I run my app I get the same sequence, 
> despite having this code in my app delegate's -appDidFinishLaunching method. 
> Clearly I'm not seeding it right, though I can't see why - I get a different 
> value for seed every time. What gives?
>
>
>        unsigned seed = (unsigned)([NSDate timeIntervalSinceReferenceDate] * 
> 1.0);
>
>        NSLog(@"launched, seed = %ld", seed );
>        srandom( seed );

I'm not sure what your problem is, but I believe arc4random() has
superseded random() for a while now.
___

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

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

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

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


Re: Seeding random() randomly

2011-05-26 Thread Ken Thomases
On May 26, 2011, at 8:00 PM, Graham Cox wrote:

> I'm using random(), but every time I run my app I get the same sequence, 
> despite having this code in my app delegate's -appDidFinishLaunching method. 
> Clearly I'm not seeding it right, though I can't see why - I get a different 
> value for seed every time. What gives?
> 
> 
>   unsigned seed = (unsigned)([NSDate timeIntervalSinceReferenceDate] * 
> 1.0);
>   
>   NSLog(@"launched, seed = %ld", seed );
>   srandom( seed );

Put a breakpoint on srandom() and setstate().  Maybe something else is 
re-seeding it (with a constant!) after you.  If you want to be really paranoid, 
make sure that your calls to random() are really going to the libSystem 
routine, instead of being covered or hidden by a macro or a routine in another 
library.

Also, consider using srandomdev() instead of srandom().  It's more random, 
although slower, but probably not enough slower that you'd notice one call.

Regards,
Ken

___

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

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

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

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


Re: Seeding random() randomly

2011-05-26 Thread Quincey Morris
On May 26, 2011, at 18:00, Graham Cox wrote:

>   unsigned seed = (unsigned)([NSDate timeIntervalSinceReferenceDate] * 
> 1.0);
>   
>   NSLog(@"launched, seed = %ld", seed );

Also, be careful here, because %ld is the wrong format specifier for type 
'unsigned'. Whether it logs the right value is going to be architecture 
dependent.


___

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

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

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

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


Re: Seeding random() randomly

2011-05-26 Thread David Duncan
On May 26, 2011, at 6:15 PM, Dave Keck wrote:

> I'm not sure what your problem is, but I believe arc4random() has superseded 
> random() for a while now.

Incorrect. There are many reason to have a seedable PRNG, the least of which is 
the ability to reasonably debug the randomness. That an arc4random() is meant 
for cryptographic security, and as such using it suffers a performance tradeoff.

As an example of "debugging the randomness" I recently created a graphical 
effect that relied heavily on random number generation. I needed to debug an 
issue that occurred 2 minutes into the sequence and relatively rare. The only 
reason I could reasonably debug the issue like this was because I had control 
over the sequence of numbers that I was seeing.
--
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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

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


Re: Seeding random() randomly

2011-05-26 Thread Graham Cox

On 27/05/2011, at 11:23 AM, Quincey Morris wrote:

> On May 26, 2011, at 18:00, Graham Cox wrote:
> 
>>  unsigned seed = (unsigned)([NSDate timeIntervalSinceReferenceDate] * 
>> 1.0);
>>  
>>  NSLog(@"launched, seed = %ld", seed );
> 
> Also, be careful here, because %ld is the wrong format specifier for type 
> 'unsigned'. Whether it logs the right value is going to be architecture 
> dependent.

Ok, then that raises the question what should I use? I'm confused about how to 
correctly write format specifiers for both 32 and 64-bit runtimes. The 64-bit 
porting guide doesn't spell it out (yet you end up with code peppered with 
warnings that you should examine the use of the format specifier without docs 
properly explaining their correct use). It's also not clear to me whether just 
'unsigned' is a fixed-size quantity or not, depending on architecture.

Someone mentioned that random() has been superseded. Again??! It seems to me 
that random number generators get superseded every other week. How is anyone 
supposed to know what is considered current best practice? Especially as for 
such functions there doesn't seem to be a simple way to see in man pages or 
other documentation what's deprecated.

--Graham___

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

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

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

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


Re: Seeding random() randomly

2011-05-26 Thread Ken Thomases
On May 26, 2011, at 8:32 PM, Graham Cox wrote:

> 
> On 27/05/2011, at 11:23 AM, Quincey Morris wrote:
> 
>> On May 26, 2011, at 18:00, Graham Cox wrote:
>> 
>>> unsigned seed = (unsigned)([NSDate timeIntervalSinceReferenceDate] * 
>>> 1.0);
>>> 
>>> NSLog(@"launched, seed = %ld", seed );
>> 
>> Also, be careful here, because %ld is the wrong format specifier for type 
>> 'unsigned'. Whether it logs the right value is going to be architecture 
>> dependent.
> 
> Ok, then that raises the question what should I use?

%u

> I'm confused about how to correctly write format specifiers for both 32 and 
> 64-bit runtimes. The 64-bit porting guide doesn't spell it out (yet you end 
> up with code peppered with warnings that you should examine the use of the 
> format specifier without docs properly explaining their correct use). It's 
> also not clear to me whether just 'unsigned' is a fixed-size quantity or not, 
> depending on architecture.

Just "unsigned" is shorthand for "unsigned int".  Between the Mac's 32-bit and 
64-bit architectures, int doesn't change size.  That can't be generalized, 
although it's darn-near universal.

However, that's irrelevant.  The format specifiers don't indicate a size.  They 
indicate a type.  For "unsigned", you use "%u".  That's the end of the story.


> Someone mentioned that random() has been superseded. Again??! It seems to me 
> that random number generators get superseded every other week. How is anyone 
> supposed to know what is considered current best practice? Especially as for 
> such functions there doesn't seem to be a simple way to see in man pages or 
> other documentation what's deprecated.

random() has not been deprecated or even superseded.  arc4random() has higher 
quality pseudo-randomness, which is probably what prompted the claim, but as 
David Duncan said that doesn't justify the claim.  It's a question of 
tradeoffs.  arc4random() is slower and non-reproducible.  (The slowness may 
matter in this case, where I asserted it doesn't matter when seeding, because 
you usually seed once and generate many times.)

Regards,
Ken

___

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

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

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

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


Re: Seeding random() randomly

2011-05-26 Thread Graham Cox
Weird.

Setting a breakpoint on srandom, setstate or srandomdev never triggers except 
for my own call of it. Using srandomdev doesn't change anything.

Switching to arc4random() gives me a varying random sequence, so that's a 
usable solution to my problem. But the behaviour with random() I'm seeing is 
mysterious.

--Graham




On 27/05/2011, at 11:15 AM, Dave Keck wrote:

>> I'm using random(), but every time I run my app I get the same sequence, 
>> despite having this code in my app delegate's -appDidFinishLaunching method. 
>> Clearly I'm not seeding it right, though I can't see why - I get a different 
>> value for seed every time. What gives?
>> 
>> 
>>unsigned seed = (unsigned)([NSDate timeIntervalSinceReferenceDate] * 
>> 1.0);
>> 
>>NSLog(@"launched, seed = %ld", seed );
>>srandom( seed );
> 
> I'm not sure what your problem is, but I believe arc4random() has
> superseded random() for a while now.

___

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

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

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

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


Re: Seeding random() randomly

2011-05-26 Thread Roland King
I don't think random/srandom are superseded. I use them myself for game 
creation. The game just has one number associated with it, I use that to seed 
random and I can completely recreate the whole game from that one number. 

I use the slightly more complicated initstate version. I see no reason why your 
method isn't working however. 

Two things to try. Print the first few randoms right after you seed to prove to 
yourself that you are seeding. Put a breakpoint on srandom, initstate and 
setstate to see if another piece of code is stomping yours. 




On May 27, 2011, at 9:32, Graham Cox  wrote:

> 
> On 27/05/2011, at 11:23 AM, Quincey Morris wrote:
> 
>> On May 26, 2011, at 18:00, Graham Cox wrote:
>> 
>>>unsigned seed = (unsigned)([NSDate timeIntervalSinceReferenceDate] * 
>>> 1.0);
>>>
>>>NSLog(@"launched, seed = %ld", seed );
>> 
>> Also, be careful here, because %ld is the wrong format specifier for type 
>> 'unsigned'. Whether it logs the right value is going to be architecture 
>> dependent.
> 
> Ok, then that raises the question what should I use? I'm confused about how 
> to correctly write format specifiers for both 32 and 64-bit runtimes. The 
> 64-bit porting guide doesn't spell it out (yet you end up with code peppered 
> with warnings that you should examine the use of the format specifier without 
> docs properly explaining their correct use). It's also not clear to me 
> whether just 'unsigned' is a fixed-size quantity or not, depending on 
> architecture.
> 
> Someone mentioned that random() has been superseded. Again??! It seems to me 
> that random number generators get superseded every other week. How is anyone 
> supposed to know what is considered current best practice? Especially as for 
> such functions there doesn't seem to be a simple way to see in man pages or 
> other documentation what's deprecated.
> 
> --Graham___
> 
> Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)
> 
> Please do not post admin requests or moderator comments to the list.
> Contact the moderators at cocoa-dev-admins(at)lists.apple.com
> 
> Help/Unsubscribe/Update your Subscription:
> http://lists.apple.com/mailman/options/cocoa-dev/rols%40rols.org
> 
> This email sent to r...@rols.org
___

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

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

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

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


Re: Seeding random() randomly

2011-05-26 Thread Graham Cox

On 27/05/2011, at 11:53 AM, Ken Thomases wrote:

> %u
> 
>> I'm confused about how to correctly write format specifiers for both 32 and 
>> 64-bit runtimes. The 64-bit porting guide doesn't spell it out (yet you end 
>> up with code peppered with warnings that you should examine the use of the 
>> format specifier without docs properly explaining their correct use). It's 
>> also not clear to me whether just 'unsigned' is a fixed-size quantity or 
>> not, depending on architecture.
> 
> Just "unsigned" is shorthand for "unsigned int".  Between the Mac's 32-bit 
> and 64-bit architectures, int doesn't change size.  That can't be 
> generalized, although it's darn-near universal.
> 
> However, that's irrelevant.  The format specifiers don't indicate a size.  
> They indicate a type.  For "unsigned", you use "%u".  That's the end of the 
> story.


Thanks Ken, very helpful.

I just looked again at the 'string format specifiers' page in the docs. Seems 
it's been much fleshed out since I last looked, and sure enough it's now much 
clearer what to use when.

--Graham

___

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

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

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

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


Re: Seeding random() randomly

2011-05-26 Thread Kevin Bracey
I think this was from some programming book I have, sorry I can site it:

srandom(time(NULL));

cheers
Kevin


___

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

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

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

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


Address Book Error with Exchange Contacts

2011-05-26 Thread Gerry Beggs
I've made an iOS app that allows users to organize their contacts into groups 
using the AddressBook Framework.

It is working great, except I am getting reports that it is failing when trying 
to add a contact to a group if the contact was imported from an Exchange server.

I am using ABGroupAddMember to add a contact to a group.

Apple's documentation gives no information on when this API might fail, so it 
wasn't expected that it would fail for contacts imported from an Exchange 
server.

One of my users went through the trouble of confirming this for me by 
de-linking his exchange contacts, then created a few contacts. When he did 
this, my app worked fine.
When he re-synced the exchange contacts again, it failed to add the contacts to 
groups.

Is this a known "issue"? Or is this expected behaviour, and should I just warn 
my users that they cannot organize Exchange contacts?

Any pointers would be appreciated. Thanks.

-- Gerry___

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

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

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

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


Re: TransformProcessType() still doesn't show menu (Bug ID# 5905139)

2011-05-26 Thread Jerry Krinock
I just thought I'd lift my head up long to say thank you, Anders.  
Unfortunately, your code doesn't work in my app.  Tried several mutations; 
still no good.

Another thing I learned is that programmatically switching apps, simulating the 
user typing cmd-tab, which works when the user does it, does not work when the 
program does it.  I hard-coded pids of several running programs, activated each 
for 1 second, then activated my app.  Looked very impressive until it got to my 
app, and the menu bar continued to show the previously-activated app.

Jerry

___

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

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

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

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


Re: TransformProcessType() still doesn't show menu (Bug ID# 5905139)

2011-05-26 Thread Jim Correia
On May 26, 2011, at 7:21 PM, Jerry Krinock wrote:

> I just thought I'd lift my head up long to say thank you, Anders.  
> Unfortunately, your code doesn't work in my app.  Tried several mutations; 
> still no good.
> 
> Another thing I learned is that programmatically switching apps, simulating 
> the user typing cmd-tab, which works when the user does it, does not work 
> when the program does it.  I hard-coded pids of several running programs, 
> activated each for 1 second, then activated my app.  Looked very impressive 
> until it got to my app, and the menu bar continued to show the 
> previously-activated app.

This is an unfortunate bug, but you should be able to work around it with this 
sequence:

[[NSApplication sharedApplication] hide: nil];

ProcessSerialNumber psn = {0, kCurrentProcess};
verify_noerr(TransformProcessType(&psn, 
kProcessTransformToForegroundApplication));

[[NSApplication sharedApplication] 
activateIgnoringOtherApps:YES];

—Jim

___

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

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

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

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


Re: Seeding random() randomly

2011-05-26 Thread Chase Latta
unsigned seed = (unsigned)([NSDate timeIntervalSinceReferenceDate] * 1.0);

You are trying to set seed to a value that is something like
3,281,585,690,000; seed cannot handle this value so it will be set to
4294967295, at least on my machine.

You are using the same seed each time you run the program so you are
getting the same values.  Try getting rid of the "* 1.0".

Chase

On Thu, May 26, 2011 at 7:15 PM, Kevin Bracey  wrote:
> I think this was from some programming book I have, sorry I can site it:
>
> srandom(time(NULL));
>
> cheers
> Kevin
>
>
> ___
>
> Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)
>
> Please do not post admin requests or moderator comments to the list.
> Contact the moderators at cocoa-dev-admins(at)lists.apple.com
>
> Help/Unsubscribe/Update your Subscription:
> http://lists.apple.com/mailman/options/cocoa-dev/chaselatta%40gmail.com
>
> This email sent to chasela...@gmail.com
>
___

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

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

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

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


Re: Seeding random() randomly

2011-05-26 Thread Conrad Shultz
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

On 5/26/11 6:00 PM, Graham Cox wrote:
> I'm using random(), but every time I run my app I get the same
> sequence, despite having this code in my app delegate's
> -appDidFinishLaunching method. Clearly I'm not seeding it right,
> though I can't see why - I get a different value for seed every time.
> What gives?
> 
> 
> unsigned seed = (unsigned)([NSDate timeIntervalSinceReferenceDate] *
> 1.0);  NSLog(@"launched, seed = %ld", seed ); srandom( seed );

(See end of message for a download URL for a sample project.)

I'm pretty sure your problem has to do with overflowing your data types.
 "unsigned" is getting treated as "unsigned int", which will be too
small to hold the value after you, for some reason I'm not clear on,
multiply by 1.

When I wrote some sample code that used NSUInteger instead, everything
worked properly.  When I compiled using 32-bit settings (instead of
native), the time interval produced using your code was wrong (and
constant, explaining your problem).

This makes sense: in 32 bit, NSUInteger is typedef'd to unsigned int, in
64 it is unsigned long, which _can_ accommodate .

The srandom() manpage indicate it expects an unsigned (int) but that the
legacy (BSD) version expects an unsigned long.  This might be worth
paying attention to as well.

I have posted a working sample project (using NSUInteger, and with a GUI
and all!) to http://dl.dropbox.com/u/5847625/RandomTest.zip



- -- 
Conrad Shultz

Synthetiq Solutions
www.synthetiqsolutions.com
-BEGIN PGP SIGNATURE-
Version: GnuPG v1.4.7 (Darwin)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iD8DBQFN3xeCaOlrz5+0JdURAt1rAJ9m+JNb/Fd5fKOB8Icrg4yvSON3/QCdFp8F
zV9DgdPunL5cUujQm/SKX4s=
=+Yjz
-END PGP SIGNATURE-
___

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

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

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

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


Re: Seeding random() randomly

2011-05-26 Thread Eeyore
I've seen gnu documentation for srandom that suggest the equivalent of Kevin's 
suggestion, namely "srandom(time(0))". Not sure if using the NSDate has any 
advantage over a call to time() and it would avoid this type of thing (gnu is 
likely to ensure time() and srandom() work correctly together).

Aaron

On May 26, 2011, at 8:10 PM, Chase Latta wrote:

> unsigned seed = (unsigned)([NSDate timeIntervalSinceReferenceDate] * 1.0);
> 
> You are trying to set seed to a value that is something like
> 3,281,585,690,000; seed cannot handle this value so it will be set to
> 4294967295, at least on my machine.
> 
> You are using the same seed each time you run the program so you are
> getting the same values.  Try getting rid of the "* 1.0".
> 
> Chase
> 
> On Thu, May 26, 2011 at 7:15 PM, Kevin Bracey  wrote:
>> I think this was from some programming book I have, sorry I can site it:
>> 
>> srandom(time(NULL));
>> 
>> cheers
>> Kevin
>> 
>> 
>> ___
>> 
>> Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)
>> 
>> Please do not post admin requests or moderator comments to the list.
>> Contact the moderators at cocoa-dev-admins(at)lists.apple.com
>> 
>> Help/Unsubscribe/Update your Subscription:
>> http://lists.apple.com/mailman/options/cocoa-dev/chaselatta%40gmail.com
>> 
>> This email sent to chasela...@gmail.com
>> 
> ___
> 
> Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)
> 
> Please do not post admin requests or moderator comments to the list.
> Contact the moderators at cocoa-dev-admins(at)lists.apple.com
> 
> Help/Unsubscribe/Update your Subscription:
> http://lists.apple.com/mailman/options/cocoa-dev/eeyore%40monsterworks.com
> 
> This email sent to eey...@monsterworks.com
> 

___

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

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

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

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


Re: Seeding random() randomly

2011-05-26 Thread Jens Alfke

On May 26, 2011, at 7:15 PM, Kevin Bracey wrote:

> srandom(time(NULL));

It’s never a good idea to seed a RNG with something guessable like this. (An 
old exploit against the Netscape browser’s SSL implementation was made possible 
in part by doing exactly that.)

All you have to do is call srandomdev() once; that will seed the generator used 
by random() with some extremely random (“high-entropy”) data read from 
/dev/random, which is generated by the kernel through all kinds of black magic.

—Jens

smime.p7s
Description: S/MIME cryptographic signature
___

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

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

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

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


Re: Seeding random() randomly

2011-05-26 Thread Scott Ribe
On May 26, 2011, at 9:32 PM, Jens Alfke wrote:

> It’s never a good idea to seed a RNG with something guessable like this.

Not all applications of random() have anything to do with security...

-- 
Scott Ribe
scott_r...@elevated-dev.com
http://www.elevated-dev.com/
(303) 722-0567 voice




___

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

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

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

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


Re: Seeding random() randomly

2011-05-26 Thread Graham Cox

On 27/05/2011, at 1:16 PM, Conrad Shultz wrote:

> I'm pretty sure your problem has to do with overflowing your data types.
> "unsigned" is getting treated as "unsigned int", which will be too
> small to hold the value after you, for some reason I'm not clear on,
> multiply by 1.
> 
> When I wrote some sample code that used NSUInteger instead, everything
> worked properly.  When I compiled using 32-bit settings (instead of
> native), the time interval produced using your code was wrong (and
> constant, explaining your problem).
> 
> This makes sense: in 32 bit, NSUInteger is typedef'd to unsigned int, in
> 64 it is unsigned long, which _can_ accommodate .


This makes complete sense. However, it seems not to be the case. I found out 
why I'm getting the same random numbers each time - explain in a sec.

But this code does *appear* to give random results (having fixed the format 
specifier issue):

unsigned seed = (unsigned)([NSDate timeIntervalSinceReferenceDate] * 
1.0);

NSLog(@"seed: %u", seed );

srandom( seed );

long r = random();

NSLog(@"random: %ld", r );


I should mention this is in a 64-bit build, so doesn't that mean that 
'unsigned' is 64 bits? However, the problem with a 32-bit build is definitely 
an issue, so I'll revise the code anyway.

The x1 is an attempt (probably misguided) to ensure a truly varying seed 
since casting to an int would only give a value that changed every second 
because NSTimeInterval is a floating point value in seconds. That is in fact 
entirely sufficient - you can't launch the app more than once a second!

The *real* reason I was getting the same sequence from random() is that this is 
a document-based app (actually a simple game, random is used to set up a 
variable initial game state) and the first document is created before 
-applicationDidFinishLaunching: is invoked. Creating the document loads the nib 
and initialises the data structures for the game, including the 'random' 
initial state. This order of initialisation during launch is something I've run 
into before, but had forgotten about - I was assuming that the app launched, 
then it opened the first document.

Moving the seeding to -applicationWillFinishLaunching: instead solved the 
problem since this is definitely called prior to creating the first document.

Thanks to everyone for helping straighten this out - 32/64 bit issues are still 
rather new to me.

--Graham


___

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

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

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

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


Re: Seeding random() randomly

2011-05-26 Thread Clark Cox
On Thu, May 26, 2011 at 9:30 PM, Graham Cox  wrote:
>
> I should mention this is in a 64-bit build, so doesn't that mean that 
> 'unsigned' is 64 bits?

No. 'unsigned' is the same size on both 32- and 64-bit The only
built-in types that are different between 32- and 64-bits are:

signed long
long (which is really the same as "signed long")
unsigned long
and any pointer type

All other built-in types remain the same size between the two.

-- 
Clark S. Cox III
clarkc...@gmail.com
___

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

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

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

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


Re: Seeding random() randomly

2011-05-26 Thread Graham Cox

On 27/05/2011, at 2:42 PM, Clark Cox wrote:

> No. 'unsigned' is the same size on both 32- and 64-bit The only
> built-in types that are different between 32- and 64-bits are:
> 
> signed long
> long (which is really the same as "signed long")
> unsigned long
> and any pointer type
> 
> All other built-in types remain the same size between the two.


Thankyou - a definitive answer. I will print it out and frame it :)

This suggest that Conrad's analysis is not quite right then, since even if I'm 
overflowing the 32-bit integer, there's still enough variation in what remains 
to give a valid and usable seed:

2011-05-27 14:25:14.689 Squaresgame[83159:a0f] seed: 276132753
2011-05-27 14:25:14.691 Squaresgame[83159:a0f] random: 1826068185
2011-05-27 14:49:36.081 Squaresgame[83217:a0f] seed: 290746671
2011-05-27 14:49:36.083 Squaresgame[83217:a0f] random: 162579918


--GRaham


___

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

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

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

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


Re: encoding of file names

2011-05-26 Thread Andrew Thompson

> However, in practical terms, the indexable string elements are components, 
> not codepoints.
> 
> It seems to me the single hardest thing to come to grips with when newly 
> approaching NSString is understanding that 'unichar's (and "characters" in 
> the sense of [characterAtIndex:]) *aren't* codepoints. In fact, AFAICT the 
> only way to *represent* a codepoint in NSString is indirectly, as a 
> single-Unicode-character string where you happen to know from general Unicode 
> knowledge that the character is represented uniquely by a single codepoint.
> 
> Unfortunately, I believe, most people newly arrived at NSString will assume 
> that 'unichar'/[characterAtIndex:] is a Unicode codepoint***, and have no 
> reason to study the documentation carefully enough to see that this is a 
> false assumption.
> 
> 
> 
> 
> *** I think that's what they'd assume if they know a fair bit about Unicode. 
> If they know less than that, they'll likely assume 'unichar' is a Unicode 
> character, which is even further from the 

I believe this stems from a period in history when the unicode group believed 
that they'd be able to fit all practical scripts into 65536 code points. Which 
meant you could get away with all kinds of assumptions like 16 bit types and 
UCS-2. 

As it became clear that wasn't going to be enough code points the additional 
planes were defined and ucs2 fell out of favor being replaced by UTF16 which 
can model the higher planes. 

Both Java's String and Objective C's NSString have these sorts of API speed 
bumps because I think they were originally created in the ucs2 era where a 
16bit code point was effectively a character and the mapping was simple. UTF16 
was retrofitted over the existing API. 

I actually built a Category for NSString that gives it methods that return 
UTF32 chars by handling surrogate pairs. 
___

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

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

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

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


Re: encoding of file names

2011-05-26 Thread Quincey Morris
On May 26, 2011, at 22:56, Andrew Thompson wrote:

> I believe this stems from a period in history when the unicode group believed 
> that they'd be able to fit all practical scripts into 65536 code points. 
> Which meant you could get away with all kinds of assumptions like 16 bit 
> types and UCS-2. 
> 
> As it became clear that wasn't going to be enough code points the additional 
> planes were defined and ucs2 fell out of favor being replaced by UTF16 which 
> can model the higher planes. 

That would explain the parting of the ways between "code unit" and "code 
point", but not really the distinction between "code point" and "[Unicode] 
character". My memory of the days when Unicode first started to get a foothold 
(the early 90s IIRC) is very hazy, but I think there were actually two things 
going on:

-- The belief, exactly as you describe, that 65536 was enough.

-- A vagueness (or perhaps a deliberate lack of definition) about what should 
be called a "character".

This seems to have been resolved now, and we have this hierarchy, at least in 
Unicode/Apple terms:

code unit -> code point -> character -> grapheme -> (whatever the 
grouping is called upon which transformations like upper and lower case are 
performed)

It's not ultimately so hard, just a bit perilous for the unwary. That's the 
reason I've been going on about this ad nauseam. If we shine some light on it, 
we may help demystify it.

___

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

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

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

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