View swap using "push" animation

2009-11-09 Thread PCWiz
I want to swap out one view with another by pushing the old view aside  
to slide in a new view (the kCATransitionPush type). To use  
CoreAnimation I need to work with CALayers for my views. The problem  
is that attaching a backing layer to my window content view through  
setWantsLayer distorts everything in the view.


I'm not sure if this has something to do with the fact that I'm using  
a subclass of NSWindow called MAAttachedWindow (http://mattgemmell.com/source 
), which is a HUD style transparent popup window of sorts that  
attaches to another object.


I can provide screenshots of this distortion if needed. I got the  
animation working using NSViewAnimation, but as many others have  
experienced, NSViewAnimation is terribly slow. I'd rather use  
CoreAnimation, but this issue prevents me from using it.


Any insight is greatly appreciated
Thanks


___

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

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

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

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


Re: beginner question, NSNumber, NSDecimalAsNumber

2009-11-09 Thread Andrew Farmer

On 9 Nov 2009, at 10:49, Jeffrey Oleander wrote:

Last I looked, 1-bit count was an assembly/
hardware instruction.  Getting the highest
order on-bit required a little cleverness.


Take a look at __builtin_clz(). (It maps to 'bsr' on x86.)
___

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

Please do not post 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: Cocoa Sounds

2009-11-09 Thread Damien Cooke

Hi all,
I may be way off but in my iPhone game I used SystemSoundID and  
AudioServicesCreateSystemSoundID I am not sure if that is helpful at  
all but it did not seem to have a delay but it does not support many  
formats either.  So if you are happy to convert your format this may  
be an option?


it looks like this

SystemSoundID wrongLetter;
AudioServicesCreateSystemSoundID((CFURLRef) [[NSURL alloc]  
initFileURLWithPath:[[NSBundle mainBundle]  
pathForResource:@"wrongLetter" ofType:@"aiff"]], &wrongLetter);


AudioServicesPlaySystemSound(wrongLetter);

//when finished
AudioServicesDisposeSystemSoundID(wrongLetter);



Regards
Damien
On 10/11/2009, at 12:27 PM, Matt Neuburg wrote:

On Mon, 9 Nov 2009 14:16:14 -0500, "Sean McBride" >

said:

On 11/9/09 10:50 AM, Jens Alfke said:


I ran into this too. A decent workaround is to preload the sound:
create an NSSound object for the audio file you want to play, set  
its

volume to zero, then play it. After that it's "warmed up" and will
play instantly.


I just tried this, and it seems to work well.  One catch is that  
'play'

is asynchronous, so you have to restore the volume to non-0 in the
sound:didFinishPlaying: delegate callback.

Altogether quite annoying.

And this won't help fix the same problem with NSBeep.


Correct. I'm already doing various dances to try to "prime the pump"  
for my
own NSSounds, but I have not found a way to "prime the pump" for an  
ordinary

NSBeep. m.

--
matt neuburg, phd = m...@tidbits.com, 
A fool + a tool + an autorelease pool = cool!
AppleScript: the Definitive Guide - Second Edition!
http://www.tidbits.com/matt/default.html#applescriptthings



___

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

Please do not post 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/damien.cooke%40internode.on.net

This email sent to damien.co...@internode.on.net


___

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

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

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

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


Re: Cocoa Sounds

2009-11-09 Thread Matt Neuburg
On Mon, 9 Nov 2009 14:16:14 -0500, "Sean McBride" 
said:
>On 11/9/09 10:50 AM, Jens Alfke said:
>
>>I ran into this too. A decent workaround is to preload the sound:
>>create an NSSound object for the audio file you want to play, set its
>>volume to zero, then play it. After that it's "warmed up" and will
>>play instantly.
>
>I just tried this, and it seems to work well.  One catch is that 'play'
>is asynchronous, so you have to restore the volume to non-0 in the
>sound:didFinishPlaying: delegate callback.
>
>Altogether quite annoying.
>
>And this won't help fix the same problem with NSBeep.

Correct. I'm already doing various dances to try to "prime the pump" for my
own NSSounds, but I have not found a way to "prime the pump" for an ordinary
NSBeep. m.

-- 
matt neuburg, phd = m...@tidbits.com, 
A fool + a tool + an autorelease pool = cool!
AppleScript: the Definitive Guide - Second Edition!
http://www.tidbits.com/matt/default.html#applescriptthings



___

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

Please do not post 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: Cocoa Sounds

2009-11-09 Thread Jens Alfke


On Nov 9, 2009, at 4:43 PM, Chunk 1978 wrote:


i've also only read about the complexity of OpenAL, which i assume is
even more low level in the sense that CoreAudio to OpenAL it's
anologous to CoreAnimation to OpenGL.


Not really; it might even be the other way around. OpenAL is a cross- 
platform API that, on Mac, is implemented on top of CoreAudio. The  
CoreAudio APIs have varying degrees of complexity, but most of them  
are pretty low-level, i.e. you're dealing directly with buffers full  
of samples and shoveling them around on background threads.


There is unfortunately nothing comparable to CoreAnimation for audio.  
You get NSSound, where you can play a canned sound in one line but  
can't do anything interesting with it; QTKit, which gives you  
multimedia support; AudioQueue and AudioFile, where you can write  
several pages of C code to load, play and record audio data; and  
AudioUnits where you can write pages and pages of gnarly C++ code to  
perform fancy real-time audio processing. (That's not strictly  
accurate, but I think it's a fair ballpark view.)


—Jens___

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

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

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

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


Re: code data export import strategies

2009-11-09 Thread Rob Keniger

On 09/11/2009, at 5:03 PM, Martin Hewitson wrote:

> Thanks, Rob. I do have this book, but I sort of skipped the section about 
> multithreading (where the export example is buried), but I've found it now.


Yes, it's kind of a shame that it's buried in there. I initially skipped it too.

In my case I don't need to use multithreading and it was easy to adapt the code 
to a non-threaded implementation.

--
Rob Keniger



___

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

Please do not post 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: Cocoa Sounds

2009-11-09 Thread Chunk 1978
i've also only read about the complexity of OpenAL, which i assume is
even more low level in the sense that CoreAudio to OpenAL it's
anologous to CoreAnimation to OpenGL.

regardless, is this NSSound lag a filed bug?  it's seems really
unfortunate that there is a 1-second lag in loading/executing a 30kb
sound file for some apps using NSSound.  while that previously
mentioned workaround is more ideal than a lag, since it's problematic
on macbooks it's not really a seamless solution.

On Mon, Nov 9, 2009 at 7:30 PM, Jens Alfke  wrote:
>
> On Nov 9, 2009, at 3:35 PM, Chunk 1978 wrote:
>
> thanks.  haven't had time to test the workaround yet.  i'll check out
> coreaudio.
>
> You really don't want to get into CoreAudio unless you're planning on doing
> some serious audio work. The APIs are low-level and complex and will take
> quite a while to learn.
> The preloading workaround for NSSound should suffice if all you care about
> is avoiding a delay before playing the sound.
> —Jens
___

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

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

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

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


Re: Cocoa Sounds

2009-11-09 Thread Jens Alfke


On Nov 9, 2009, at 3:35 PM, Chunk 1978 wrote:

thanks.  haven't had time to test the workaround yet.  i'll check  
out coreaudio.


You really don't want to get into CoreAudio unless you're planning on  
doing some serious audio work. The APIs are low-level and complex and  
will take quite a while to learn.


The preloading workaround for NSSound should suffice if all you care  
about is avoiding a delay before playing the sound.


—Jens___

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

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

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

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


Re: Cocoa Sounds

2009-11-09 Thread Chunk 1978
thanks.  haven't had time to test the workaround yet.  i'll check out coreaudio.

On Mon, Nov 9, 2009 at 6:32 PM, Sean McBride  wrote:
> On 11/9/09 6:25 PM, Chunk 1978 said:
>
>>so, is there some other lightweight 3rd party framework that could
>>substitute for cocoa's NSSound?
>
> Did you try the workaround Jens and I suggested?  Did you look at
> CoreAudio, as I also suggested?  There's also:
> 
>
> --
> 
> Sean McBride, B. Eng                 s...@rogue-research.com
> Rogue Research                        www.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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

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


Re: [iPhone] EditableDetailView sample code

2009-11-09 Thread Chunk 1978
Dave Mark and Jeff LaMarche wrote a pretty awesome book called
"Beginning iPhone Development" which covers editable detail views.
def check out the book.  you can download source code on the product's
website, but you have to register with the forums to do so.  the book
is really great, though.  you should def buy it.
http://www.iphonedevbook.com/

On Mon, Nov 9, 2009 at 4:06 PM, Tharindu Madushanka
 wrote:
>
> Hi
>
> I am finding it difficult to find previous sampe codes in apple site. How
> can I find sample code for Editable Detail View
>
> Kind Regards,
>
> Tharindu Madushanka
> ___
>
> Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)
>
> Please do not post 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/chunk1978%40gmail.com
>
> This email sent to chunk1...@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: Cocoa Sounds

2009-11-09 Thread Sean McBride
On 11/9/09 6:25 PM, Chunk 1978 said:

>so, is there some other lightweight 3rd party framework that could
>substitute for cocoa's NSSound?

Did you try the workaround Jens and I suggested?  Did you look at
CoreAudio, as I also suggested?  There's also:


--

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

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


Re: Cocoa Sounds

2009-11-09 Thread Chunk 1978
so, is there some other lightweight 3rd party framework that could
substitute for cocoa's NSSound?

On Mon, Nov 9, 2009 at 2:40 PM, lbland  wrote:

> hi-
>
>
> On Nov 9, 2009, at 12:58 PM, Chunk 1978 wrote:
>
>  one thing i've always had an issue with is sound lag, which always
>> (yet only) happens during a first sound.  after the initial lag,
>> sounds will play on time.  at first i though it was my code, but
>> recently i've noticed that it happens in Calculator.
>>
>> if you open Calculator, then choose Speech > Speak Button Pressed,
>> you'll notice a lag when you first press a button.
>>
>> how is it possible to avoid this?  are there other 3rd frameworks for
>> sound that would be more ideal to use other than what's available in
>> cocoa?
>>
>
> It happens in our Cocoa apps. It also happens with the Apple Mail app.
>
> Click "Get Mail" and after Activity stops and 4 seconds later there is the
> beep.
>
> This is on Mac OS X 10.6.1 and the latest and fully loaded MacBook Pro
> computers.
>
> So, I think the lag is simply what you get.
>
> ... the good news is that other people have the problem. The bad news is:
> since reading this post (and the one a few days ago) every time I check my
> mail I now notice that the sound really lags!
>
> thanks!-
>
> -lance
>
>
___

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

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

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

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


Re: avoiding spagetti code

2009-11-09 Thread Rob Keniger

On 10/11/2009, at 8:04 AM, Oftenwrong Soong wrote:

> In the MVC style, I want to avoid connecting directly between a view and a 
> model. However I have a custom NSView subclass that renders a graphical view 
> of the model and therefore it needs information from the model. I think it is 
> considered bad practice to put a pointer to the model directly in my NSView 
> subclass. However how can this type of coupling be avoided if the view needs 
> the information?


I struggled with this for a while, but you just need to look at some of the 
built-in complex views to see how this can be done. 

In particular, have a look at the datasource and delegate methods for 
NSTableView, for instance. The view publishes protocols which a controller 
object can use to control how the view is displayed. You can do exactly the 
same thing for your own custom view.

You use the controller object to supply the view with the information that it 
needs to be able to draw representations of your model objects.

--
Rob Keniger



___

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

Please do not post 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: Trouble with initial position of NSScrollView

2009-11-09 Thread Graham Cox


On 10/11/2009, at 7:10 AM, Oftenwrong Soong wrote:

Unfortunately each time I swap a view, the vertical scrollbar goes  
all the way to the bottom, meaning that I have to manually scroll  
back up to bring the view into view.


What did I do wrong?



Nothing, as far as I can see. But NSScrollView works this way when its  
document view is not flipped, so you'll need to return YES from - 
isFlipped for that view to have it default to the top, left scroll  
position instead of the bottom, left.


--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: avoiding spagetti code

2009-11-09 Thread Richard Somers

On Nov 9, 2009, at 3:04 PM, Oftenwrong Soong wrote:

In the MVC style, I want to avoid connecting directly between a view  
and a model. However I have a custom NSView subclass that renders a  
graphical view of the model and therefore it needs information from  
the model. I think it is considered bad practice to put a pointer to  
the model directly in my NSView subclass. However how can this type  
of coupling be avoided if the view needs the information?


The following prior post may be of help which discusses the drawing of  
model objects.


http://www.mail-archive.com/cocoa-dev@lists.apple.com/msg46045.html

On Oct 13, 2009, at 7:58 AM, Erik Buck wrote:

There is ample precedent for adding View specific capabilities to  
Model objects via categories.  AppKit adds string drawing methods to  
NSString.


You definitely don't want your View subsystem constantly asking  
Model objects what kind they are in order to present information.   
If you have ifs or switches based on the class of objects or even  
based on an attribute of an Entity, you are doing it wrong.


It is much cleaner to use the built in language polymorphism.  Just  
keep View related code implementation within the View.



Richard

___

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

Please do not post 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: avoiding spagetti code

2009-11-09 Thread Jason Stephenson

Oftenwrong Soong wrote:

Hi all,

In the MVC style, I want to avoid connecting directly between a view 
and a model. However I have a custom NSView subclass that renders a 
graphical view of the model and therefore it needs information from 
the model. I think it is considered bad practice to put a pointer to 
the model directly in my NSView subclass. However how can this type 
of coupling be avoided if the view needs the information?




Have an actual controller class handle the interaction between the View
and the Model. Most of the MVC examples you find for Cocoa are actually 
MC/V where model and controller are wrapped in 1 class. This is very 
often easier to implement in a standalone application.


However, if you want real separation between the view and the model, 
then you'll need a real controller class to query the model and pass 
information to the view when the view needs the model data. The 
controller could also do any transforms on the data required by the view.


In this way, the model doesn't have to know about the view, the view 
doesn't have to know about the model, but the controller does know about 
both.


HTH,
Jason




Thanks, Soong




___

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

Please do not post 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/jason%40sigio.com


This email sent to ja...@sigio.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


avoiding spagetti code

2009-11-09 Thread Oftenwrong Soong
Hi all,

In the MVC style, I want to avoid connecting directly between a view and a 
model. However I have a custom NSView subclass that renders a graphical view of 
the model and therefore it needs information from the model. I think it is 
considered bad practice to put a pointer to the model directly in my NSView 
subclass. However how can this type of coupling be avoided if the view needs 
the information?

Thanks,
Soong



  
___

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

Please do not post 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: Core Data Disable Undo

2009-11-09 Thread Richard Somers

On Nov 9, 2009, at 11:46 AM, BJ Homer wrote:


[[managedObjectContext undoManager] disableUndoRegistration];


Thank you.

On Nov 9, 2009, at 11:49 AM, Kyle Sluder wrote:


The NSPersistentDocument Core Data tutorial tells you exactly how to
do it: 
http://developer.apple.com/mac/library/documentation/Cocoa/Conceptual/NSPersistentDocumentTutorial/04_Department/department.html

Or you could just look at NSUndoManager, since that's the thing that  
does undo.


Thanks for the reply.

Either way, you should have been able to find your answer rather  
quickly without needing to ask the list.


Sorry, I was not thinking very clearly today.

Richard

___

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

Please do not post 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


[iPhone] EditableDetailView sample code

2009-11-09 Thread Tharindu Madushanka
Hi

I am finding it difficult to find previous sampe codes in apple site. How
can I find sample code for Editable Detail View

Kind Regards,

Tharindu Madushanka
___

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

Please do not post 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


NSArrayController -addObjects and undo

2009-11-09 Thread jonat...@mugginsoft.com

My Entry objects are an NSManagedObject subclass.

I create an NSArray of N Entries and add them to my array controller  
like so.

[self.arrayController addObjects:newEntries];

I am observing [self.arrayController arrangedObjects] and receive a  
single observation following the above call.


However, when I undo this operation I get N observations of  
[self.arrayController arrangedObjects].


Is this expected behaviour or am I screwing up on my KVO somewhere?
I have not changed the default undo manager grouping behaviour.

Running OS X 10.6

Regards

Jonathan Mitchell

Developer
http://www.mugginsoft.com






___

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

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

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

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


Re: iPhone: NSOperation and UITableVIews

2009-11-09 Thread Alex Kac
One good reason not to cancel is if a user is going to go up/down the  
list then going ahead and storing the image you got (caching) is a  
better deal. That way you aren't continuously reloading that image or  
canceling or what not. Finally if you use an NSOperation, try to let  
it work in sequence or at most 2-3 concurrent operations.


On Nov 9, 2009, at 2:13 PM, John Michael Zorko wrote:



Dave, Alex ...

An alternative implementation might be to have each cell queue up  
an operation when it needs to load an image (not the view  
controller). Then, each cell could cancel it's operation in  
[UITableViewCell prepareForReuse].



Cool -- I learned something today :-)  I did this, so now the  
NSOperation * is stored in the cell, hence I can get it from  
prepareToReuse and call cancel on it.  Nifty!  I also set the tag of  
the cell and get it back in my refresh method, which means i'm only  
telling the cells currently displayed to load their artwork.  The  
scrolling is still a bit jerky, though much much better, and nothing  
i've not seen in other apps on this device (first gen 8G iPod touch,  
running OS 2.2.1). I'm sure it will perform much better on a more  
recent device like my iPhone 3GS, but I like to test with the oldest  
thing I can :-)


Regards,

John

Falling You - exploring the beauty of voice and sound
http://www.fallingyou.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/alex%40webis.net

This email sent to a...@webis.net


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

"Forgiveness is not an occasional act: it is a permanent attitude."
-- Dr. Martin Luther King




___

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

Please do not post 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: iPhone: NSOperation and UITableVIews

2009-11-09 Thread John Michael Zorko


Dave, Alex ...

An alternative implementation might be to have each cell queue up an  
operation when it needs to load an image (not the view controller).  
Then, each cell could cancel it's operation in [UITableViewCell  
prepareForReuse].



Cool -- I learned something today :-)  I did this, so now the  
NSOperation * is stored in the cell, hence I can get it from  
prepareToReuse and call cancel on it.  Nifty!  I also set the tag of  
the cell and get it back in my refresh method, which means i'm only  
telling the cells currently displayed to load their artwork.  The  
scrolling is still a bit jerky, though much much better, and nothing  
i've not seen in other apps on this device (first gen 8G iPod touch,  
running OS 2.2.1). I'm sure it will perform much better on a more  
recent device like my iPhone 3GS, but I like to test with the oldest  
thing I can :-)


Regards,

John

Falling You - exploring the beauty of voice and sound
http://www.fallingyou.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


Trouble with initial position of NSScrollView

2009-11-09 Thread Oftenwrong Soong
Hi all,

My app's UI was swapping views into a NSBox (a la Hillegass's book). Now I 
decided to replace the NSBox with a NSScrollView. No big difference there. I 
only made three changes: In IB, I got rid of the NSBox and dropped a 
NSScrollView in its place. In my document controller class, I modified the 
IBOutlet, which I call everChangingView, to point to a NSScrollView instead of 
a NSBox. Finally, in the method that swaps the view, I call [everChangingView 
setDocumentView:v] instead of [everChangingView setContentView:v].

The views do swap into the NSScrollView as they should.

Unfortunately each time I swap a view, the vertical scrollbar goes all the way 
to the bottom, meaning that I have to manually scroll back up to bring the view 
into view.

What did I do wrong?

Thanks,
Soong



  
___

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

Please do not post 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: Cocoa Sounds

2009-11-09 Thread Sean McBride
On 11/9/09 10:50 AM, Jens Alfke said:

>I ran into this too. A decent workaround is to preload the sound:
>create an NSSound object for the audio file you want to play, set its
>volume to zero, then play it. After that it's "warmed up" and will
>play instantly.

I just tried this, and it seems to work well.  One catch is that 'play'
is asynchronous, so you have to restore the volume to non-0 in the
sound:didFinishPlaying: delegate callback.

Altogether quite annoying.

And this won't help fix the same problem with NSBeep.

>(Actually not entirely instantly on laptops, which will turn off the
>audio hardware when it hasn't been used in a few minutes, to save
>battery power. Turning it back on delays the sound a fraction of a
>second and creates a slight 'pop'.)

Ugh.

--

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

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


Re: Cocoa Sounds

2009-11-09 Thread Chunk 1978
i dont' believe there are any special processes running, but this iMac has
always had issues since i got it.  i've had it "fixed" 3 times for problems
concerning the screen and video card, it's broken again so i'm scheduled to
have it entirely replaced.  perhaps there are some other underlying issues
that aren't as obvious that is causing this sound lag problem?

NSSound *theSound = [[NSSound alloc] initWithContentsOfFile:@"mySound.m4a"
byReference:NO];


would loading the sound into memory as above really make the first sound
play on time?  the size of my sound files average 40kb, so it doesn't seem
reasonable to me.

On Mon, Nov 9, 2009 at 1:51 PM, Sean McBride wrote:

> On 11/9/09 12:58 PM, Chunk 1978 said:
>
> >one thing i've always had an issue with is sound lag, which always
> >(yet only) happens during a first sound.  after the initial lag,
> >sounds will play on time.  at first i though it was my code, but
> >recently i've noticed that it happens in Calculator.
> >
> >if you open Calculator, then choose Speech > Speak Button Pressed,
> >you'll notice a lag when you first press a button.
> >
> >how is it possible to avoid this?  are there other 3rd frameworks for
> >sound that would be more ideal to use other than what's available in
> >cocoa?
>
> I have this problem too.  It even happens with NSBeep (which someone
> posted about the other day).  Maybe you could 'preflight' your sound by
> calling setVolume:0.0 then playing it, then restoring the volume.  (Of
> course, the VM system may page out your sound later anyway...).  Perhaps
> CoreAudio has a better solution.
>
> --
> 
> 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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

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


Re: Pausing an NSThread

2009-11-09 Thread Jens Alfke


On Nov 8, 2009, at 2:17 AM, Roland King wrote:

Or look at NSOperation/NSOperationQueue which absolves you of the  
need to care about threads, it's done for you (and I believe makes  
use of Grand Central Dispatch on current versions of OSX). Just  
package up whatever it is you need to do and send it off and some  
thread somewhere will do it for you.


For the record: +1 to this. Let NSOperationQueue manage concurrency  
for you instead of using NSThread, unless you really know what you're  
doing with multithreading. It's much easier and safer.


—Jens___

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

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

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

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


Re: Compile error using @synchronized on methods that return values

2009-11-09 Thread Jens Alfke


On Nov 8, 2009, at 12:11 PM, Stuart Malin wrote:

But I suspect that from the posters comments in the post I reference  
below, it isn't a bug. The problem is, you can't return up the  
calling chain while being synchronized. Do whatever work it is that  
needs to be performed in a synchronized way, then return whatever  
result needs to be returned.


No, that's not true. It's safe to return out of an @synchronized  
block. It's conceptually the same as a local C++ object whose  
destructor fires whenever the block exits.


As Clark said, the warning is simply due to a bug in the compiler's  
control-flow analysis — it doesn't realize that it's safe for the  
function not to have a 'return' on its last line.


—Jens___

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

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

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

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


Re: NSString of selected text in NSTextView

2009-11-09 Thread Kyle Sluder
On Mon, Nov 9, 2009 at 9:50 AM, Douglas Davidson  wrote:
> Please do.

Filed as 7377361.

--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: Creating a small timer?

2009-11-09 Thread Jens Alfke


On Nov 9, 2009, at 9:19 AM, Michael Abendroth wrote:


How can I create such a timer?  I mean, it probably isn't very
efficient to redraw the whole view every second just to get the timer
to update.


Drawing a view once a second shouldn't be a problem. Look at all the  
stuff iTunes' pseudo-LCD status view updates multiple times a second  
while a track is playing.


It's always a good idea to tell the view to redraw only the bounding  
box of the area that needs to update, though.


But is creating a separate thread just for the timer necessary (I  
doubt that)?


Don't create a thread. Use an NSTimer.

—Jens___

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

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

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

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


Re: Cocoa Sounds

2009-11-09 Thread Sean McBride
On 11/9/09 12:58 PM, Chunk 1978 said:

>one thing i've always had an issue with is sound lag, which always
>(yet only) happens during a first sound.  after the initial lag,
>sounds will play on time.  at first i though it was my code, but
>recently i've noticed that it happens in Calculator.
>
>if you open Calculator, then choose Speech > Speak Button Pressed,
>you'll notice a lag when you first press a button.
>
>how is it possible to avoid this?  are there other 3rd frameworks for
>sound that would be more ideal to use other than what's available in
>cocoa?

I have this problem too.  It even happens with NSBeep (which someone
posted about the other day).  Maybe you could 'preflight' your sound by
calling setVolume:0.0 then playing it, then restoring the volume.  (Of
course, the VM system may page out your sound later anyway...).  Perhaps
CoreAudio has a better solution.

--

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

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


Re: Cocoa Sounds

2009-11-09 Thread Jens Alfke
I ran into this too. A decent workaround is to preload the sound:  
create an NSSound object for the audio file you want to play, set its  
volume to zero, then play it. After that it's "warmed up" and will  
play instantly.


(Actually not entirely instantly on laptops, which will turn off the  
audio hardware when it hasn't been used in a few minutes, to save  
battery power. Turning it back on delays the sound a fraction of a  
second and creates a slight 'pop'.)


—Jens___

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

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

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

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


Re: beginner question, NSNumber, NSDecimalAsNumber

2009-11-09 Thread Jeffrey Oleander
> On Mon, 2009/11/09, Alastair Houghton  wrote:
> From: Alastair Houghton 
> Subject: Re: beginner question, NSNumber, NSDecimalAsNumber
> To: "Thomas Wetmore" 
> Cc: "list-cocoa-dev List" 
> Date: Monday, 2009 November 9, 5:55
>> On 2009 Nov 09, at 10:49, Thomas Wetmore wrote:
>> The approach found by Ron prints the bits in
>> correct order...
>
> Or you can calculate the number of bits and
> fill the buffer in reverse.  It's pretty
> easy to do a bit count on a fixed-size word
> (no need for a loop, in fact).

Last I looked, 1-bit count was an assembly/
hardware instruction.  Getting the highest
order on-bit required a little cleverness.



___

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

Please do not post 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: Core Data Disable Undo

2009-11-09 Thread Kyle Sluder
On Mon, Nov 9, 2009 at 10:20 AM, Richard Somers
 wrote:
> How do you insert an object into a managed object context with undo
> disabled?

The NSPersistentDocument Core Data tutorial tells you exactly how to
do it: 
http://developer.apple.com/mac/library/documentation/Cocoa/Conceptual/NSPersistentDocumentTutorial/04_Department/department.html

Or you could just look at NSUndoManager, since that's the thing that does undo.

Either way, you should have been able to find your answer rather
quickly without needing to ask the list.

--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: Core Data Disable Undo

2009-11-09 Thread BJ Homer
[[managedObjectContext undoManager] disableUndoRegistration];

-BJ
___

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

Please do not post 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: Cocoa Sounds

2009-11-09 Thread Klaus Backert


On 9 Nov 2009, at 19:25, Chunk 1978 wrote:


humm... i'm running 10.5.8 on 2008 iMac C2D, but i never though it
could have been the computer.  would like to hear from others.


Did you check whether there are certain "special" processes running on  
your machine?


Klaus

___

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

Please do not post 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: Cocoa Sounds

2009-11-09 Thread Chunk 1978
also, i tried implementing a dummy sound (dead air .m4a file) during
application launch, but that didn't help.  the first real sound is still
always lagged.

On Mon, Nov 9, 2009 at 1:37 PM, Chunk 1978  wrote:

> i'm using Cocoa's NSSound.  here's is how i play sounds:
>
> -=-=-=-=-
>
> if ([[soundRadioGroup cellWithTag:1] state] == NSOnState)
>
> {
>
> NSSound *theSound = [NSSound soundNamed:@"mySound.m4a"];
>
> if ([theSound isPlaying])
>
> [theSound stop];
>
>
>  [theSound play];
>
> }
>
> -=-=-=-=-
>
>
> the first sound is always lagged.  for example, if i press a button to play
> a sound, the button's pressed state will remain until the sound is loaded
> and played.  after the first sound plays, all other sounds will play without
> lag.
>
> On Mon, Nov 9, 2009 at 1:30 PM, Shawn Erickson  wrote:
> >
> >
> > On Mon, Nov 9, 2009 at 10:25 AM, Chunk 1978  wrote:
> >>
> >> humm... i'm running 10.5.8 on 2008 iMac C2D, but i never though it
> >> could have been the computer.  would like to hear from others.
> >
> > What sound API are you using?
> > -Shawn
>
>
___

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

Please do not post 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: Cocoa Sounds

2009-11-09 Thread Dave DeLong
That makes sense, because NSSound has to go find the resource named  
"mySound.m4a", load it into memory, and then play it.


Have you tried preloading the sound, so that by the time you want to  
play it, it's already in memory?


Dave

On Nov 9, 2009, at 11:37 AM, Chunk 1978 wrote:


i'm using Cocoa's NSSound.  here's is how i play sounds:

-=-=-=-=-

if ([[soundRadioGroup cellWithTag:1] state] == NSOnState)

{

NSSound *theSound = [NSSound soundNamed:@"mySound.m4a"];

if ([theSound isPlaying])

[theSound stop];


[theSound play];

}

-=-=-=-=-


the first sound is always lagged.  for example, if i press a button  
to play
a sound, the button's pressed state will remain until the sound is  
loaded
and played.  after the first sound plays, all other sounds will play  
without

lag.


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: Cocoa Sounds

2009-11-09 Thread Chunk 1978
i'm using Cocoa's NSSound.  here's is how i play sounds:

-=-=-=-=-

if ([[soundRadioGroup cellWithTag:1] state] == NSOnState)

{

NSSound *theSound = [NSSound soundNamed:@"mySound.m4a"];

if ([theSound isPlaying])

[theSound stop];


 [theSound play];

}

-=-=-=-=-


the first sound is always lagged.  for example, if i press a button to play
a sound, the button's pressed state will remain until the sound is loaded
and played.  after the first sound plays, all other sounds will play without
lag.

On Mon, Nov 9, 2009 at 1:30 PM, Shawn Erickson  wrote:
>
>
> On Mon, Nov 9, 2009 at 10:25 AM, Chunk 1978  wrote:
>>
>> humm... i'm running 10.5.8 on 2008 iMac C2D, but i never though it
>> could have been the computer.  would like to hear from others.
>
> What sound API are you using?
> -Shawn
___

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

Please do not post 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: Cocoa Sounds

2009-11-09 Thread Shawn Erickson
On Mon, Nov 9, 2009 at 10:25 AM, Chunk 1978  wrote:

> humm... i'm running 10.5.8 on 2008 iMac C2D, but i never though it
> could have been the computer.  would like to hear from others.


What sound API are you using?

-Shawn
___

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

Please do not post 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: Cocoa Sounds

2009-11-09 Thread Chunk 1978
humm... i'm running 10.5.8 on 2008 iMac C2D, but i never though it
could have been the computer.  would like to hear from others.

On Mon, Nov 9, 2009 at 1:18 PM, Klaus Backert  wrote:
>
> On 9 Nov 2009, at 18:58, Chunk 1978 wrote:
>
>> one thing i've always had an issue with is sound lag, which always
>> (yet only) happens during a first sound.  after the initial lag,
>> sounds will play on time.  at first i though it was my code, but
>> recently i've noticed that it happens in Calculator.
>>
>> if you open Calculator, then choose Speech > Speak Button Pressed,
>> you'll notice a lag when you first press a button.
>
> Well, I do not notice this -- on ppc and on intel.
>
>> how is it possible to avoid this?  are there other 3rd frameworks for
>> sound that would be more ideal to use other than what's available in
>> cocoa?
>
> Klaus
>
>
___

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

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

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

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


Core Data Disable Undo

2009-11-09 Thread Richard Somers
How do you insert an object into a managed object context with undo  
disabled?


I have objects that are added to a new document that need to be there  
but should not make the document dirty or be undoable by the user.


Richard

___

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

Please do not post 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: Less verbose way to localize a string with a default value?

2009-11-09 Thread BJ Homer
You can use the -s flag to genstrings to tell it to use your own prefix
instead of "NSLocalizedString".  For example, passing "-s MyString"  would
catch calls to MyString(), MyStringFromTable(), MyStringWithDefaultValue(),
etc.  However, these functions must take the same arguments as the default
NSLocalizedString macros, so you don't really gain much if you're just
looking to reduce verbosity without changing functionality.

More info here:
http://developer.apple.com/Mac/library/documentation/Cocoa/Conceptual/LoadingResources/Strings/Strings.html#//apple_ref/doc/uid/1051i-CH6-SW11

-BJ
___

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

Please do not post 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: beginner question, NSNumber, NSDecimalAsNumber

2009-11-09 Thread Thomas Wetmore

Yes, yours is much nicer.

TW

On Nov 9, 2009, at 12:32 PM, Alastair Houghton wrote:


On 9 Nov 2009, at 17:20, Thomas Wetmore wrote:

I offer the following as a "Cocoa solution" to the OP's query,  
whatever that might be taken to mean...


(For extra credit: why must the parameter be unsigned?)

Tom Wetmore

NSString* binaryRepresentation (NSUInteger number)
{
unichar buffer[64];
NSUInteger n = 0;
while (number) {
buffer[n++] = (number & 1) + '0';
number >>= 1;
}
NSInteger i = 0, j = n - 1;
while (i < j) {
unichar temp = buffer[j];
buffer[j] = buffer[i];
buffer[i] = temp;
i++, j--;
}
return [NSString stringWithCharacters: buffer length: n];
}


Surely

 NSString *binaryRepresentation (NSUInteger number) {
   unichar buf[64];
   unichar *ptr = buf + 64;

   do {
 *--ptr = (number & 1) ? '1' : '0';
   } while ((number >>= 1));

   return [NSString stringWithCharacters:ptr length:buf + 64 - ptr];
 }

is simpler, as well as actually working when you pass in 0 (yours  
doesn't).  (I should add that I haven't tested this at all; I just  
wrote it in Mail.app...)


Kind regards,

Alastair.

--
http://alastairs-place.net





___

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

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

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

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


Adding new rules to policy database

2009-11-09 Thread Mazen M. Abdel-Rahman

Hi All,

I know that one can add a new right specification to the policy  
database via the function AuthorizationRightSet.  Is there any  
functions or APIs for adding new rule specifications?


I want to create a new group - and allow only members of that group to  
access parts of my application.  To do that I added a new rule  
directly to the policy database - and then created a new rights  
specification that uses that rule.  The rule specifies that the user  
be a member of the group I created.  I modeled it on the "is- 
developer" rule.


Anyways - I just want to check if there's an API I can use in my code  
to add new rules instead of doing it directly through an editor.


Thanks,
Mazen Abdel-Rahman
___

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

Please do not post 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: NSTreeController and object retain counts

2009-11-09 Thread Mads Paulin

Hi,

What I initally did was exactly to log from the dealloc method of my  
node class. Experiencing that it never got called, I started to log  
from retain and release to try to get deeper into the problem.


I stumbled on the problem when integrating some C++ code into my cocoa  
project. Every node object in the NSMutableArray would hold a pointer  
to a quite large C++ representation of a 3D model. Each of these  
models allocated approc 0.5 mb of memory, and this show up quite  
signifaicantly in instruments when allocating and deallocating objects  
through the NSTreeController. Unfortunately, the memory consumption  
only goes up when allocating and never down when removing nodes  
because the dealloc method of the node is never called and my 3D model  
hence never deleted.


Funny enough, if I replace the TreeController with an Arraycontroller  
everything works as expected.


/Mads

On Nov 9, 2009, at 12:38 , Graham Cox wrote:



On 09/11/2009, at 10:31 PM, Mads Paulin wrote:


Adding a node object through this method creates a node object in the
document array member with a retain count of 2. The remove:sender  
method
correctly removes the object from the document's array but only  
decrements
the node object's retain count to 1 - meaning that the objects are  
never
dealloc. As I see it, this is a memory leak in NSTreeController as  
all "my"

external references to the Node objects are lost.



You can't meaningfully debug by peeking at retain counts. Instead  
try logging from the -dealloc method if possible, or use the leaks  
Instrument to find out if the objects are really not being  
deallocated. There's no requirement that the retain count is  
actually decremented to 0 - the code may merely predict that it  
would be and call -dealloc, rather than actually doing it.


--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


Cocoa Sounds

2009-11-09 Thread Chunk 1978
one thing i've always had an issue with is sound lag, which always
(yet only) happens during a first sound.  after the initial lag,
sounds will play on time.  at first i though it was my code, but
recently i've noticed that it happens in Calculator.

if you open Calculator, then choose Speech > Speak Button Pressed,
you'll notice a lag when you first press a button.

how is it possible to avoid this?  are there other 3rd frameworks for
sound that would be more ideal to use other than what's available in
cocoa?
___

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

Please do not post 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: NSString of selected text in NSTextView

2009-11-09 Thread Douglas Davidson


On Nov 9, 2009, at 9:37 AM, Kyle Sluder wrote:

On Mon, Nov 9, 2009 at 9:28 AM, Douglas Davidson  
 wrote:
Yes, that's correct.  Within a given text view, the character  
indexes are
the same between the text storage and its underlying string, and  
these are

the character indexes used by the layout manager and the text view.


The documentation seems to be in conflict on this point.
-[NSAttributedString string] says the following:

This method doesn’t strip out attachment characters; use NSText's  
string method to extract just the linguistically significant  
characters.


That doesn't sound right.

For performance reasons, this method returns the current backing  
store of the attributed string object. If you want to maintain a  
snapshot of this as you manipulate the returned string, you should  
make a copy of the appropriate substring.


But -[NSText string] also says this:

For performance reasons, this method returns the current backing  
store of the text object. If you want to maintain a snapshot of  
this as you manipulate the text storage, you should make a copy of  
the appropriate substring.


This is correct.


Which implies that -[NSText string] is implemented to just return
[[self textStorage] string], which would defy -[NSAttributedString
string]'s documentation.  I think NSAttributedString is in error here;
will file a doc bug soon.


Please do.

Douglas Davidson___

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

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

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

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


Re: NSString of selected text in NSTextView

2009-11-09 Thread Kyle Sluder
On Mon, Nov 9, 2009 at 9:28 AM, Douglas Davidson  wrote:
> Yes, that's correct.  Within a given text view, the character indexes are
> the same between the text storage and its underlying string, and these are
> the character indexes used by the layout manager and the text view.

The documentation seems to be in conflict on this point.
-[NSAttributedString string] says the following:

> This method doesn’t strip out attachment characters; use NSText's string 
> method to extract just the linguistically significant characters.
>
> For performance reasons, this method returns the current backing store of the 
> attributed string object. If you want to maintain a snapshot of this as you 
> manipulate the returned string, you should make a copy of the appropriate 
> substring.

But -[NSText string] also says this:

> For performance reasons, this method returns the current backing store of the 
> text object. If you want to maintain a snapshot of this as you manipulate the 
> text storage, you should make a copy of the appropriate substring.

Which implies that -[NSText string] is implemented to just return
[[self textStorage] string], which would defy -[NSAttributedString
string]'s documentation.  I think NSAttributedString is in error here;
will file a doc bug soon.

--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: Creating a small timer?

2009-11-09 Thread Nick Zitzmann


On Nov 9, 2009, at 10:19 AM, Michael Abendroth wrote:


How can I create such a timer?  I mean, it probably isn't very
efficient to redraw the whole view every second just to get the timer
to update.


Then don't. When it comes time to draw the change, make it so that it  
only redraws the part that needs to be redrawn using the - 
setNeedsDisplayInRect: method.


Nick Zitzmann


___

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

Please do not post 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: beginner question, NSNumber, NSDecimalAsNumber

2009-11-09 Thread Alastair Houghton

On 9 Nov 2009, at 17:20, Thomas Wetmore wrote:

I offer the following as a "Cocoa solution" to the OP's query,  
whatever that might be taken to mean...


(For extra credit: why must the parameter be unsigned?)

Tom Wetmore

NSString* binaryRepresentation (NSUInteger number)
{
unichar buffer[64];
NSUInteger n = 0;
while (number) {
buffer[n++] = (number & 1) + '0';
number >>= 1;
}
NSInteger i = 0, j = n - 1;
while (i < j) {
unichar temp = buffer[j];
buffer[j] = buffer[i];
buffer[i] = temp;
i++, j--;
}
return [NSString stringWithCharacters: buffer length: n];
}


Surely

  NSString *binaryRepresentation (NSUInteger number) {
unichar buf[64];
unichar *ptr = buf + 64;

do {
  *--ptr = (number & 1) ? '1' : '0';
} while ((number >>= 1));

return [NSString stringWithCharacters:ptr length:buf + 64 - ptr];
  }

is simpler, as well as actually working when you pass in 0 (yours  
doesn't).  (I should add that I haven't tested this at all; I just  
wrote it in Mail.app...)


Kind regards,

Alastair.

--
http://alastairs-place.net



___

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

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

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

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


Re: NSString of selected text in NSTextView

2009-11-09 Thread Douglas Davidson


On Nov 9, 2009, at 9:02 AM, Jens Alfke wrote:


On Nov 7, 2009, at 7:49 PM, Todd Heberlein wrote:

Yeah, one of the concerns I had was whether the selected NSRange is  
preserved when -string is called.


I've always assumed it is. That is, all character indexes that  
appear in the NSText[View] API correspond to character positions in  
the textStorage's string. It seems that this has to be true, because  
there's no other meaningful way to define the character indexes.


Yes, that's correct.  Within a given text view, the character indexes  
are the same between the text storage and its underlying string, and  
these are the character indexes used by the layout manager and the  
text view.  Processes such as copying and pasting, on the other hand,  
may not preserve character indexes.


Douglas Davidson

___

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

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

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

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


Re: beginner question, NSNumber, NSDecimalAsNumber

2009-11-09 Thread Alastair Houghton

On 9 Nov 2009, at 16:42, Thomas Wetmore wrote:

These functions return how many one bits there are in a number, not  
how many bit positions are needed to represent the number as a bit- 
string with no leading zeros. They are fun but have no utility in  
solving the OP's question.


Not true.  Consider:

  // Assumes n is 32-bits
  n |= n >> 1;
  n |= n >> 2;
  n |= n >> 4;
  n |= n >> 8;
  n |= n >> 16;
  bits = count_bits (n);

Anyway, while neat, bit twiddling isn't really a subject for  
beginners, so to that extent I agree with you.


Kind regards,

Alastair.

--
http://alastairs-place.net



___

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

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

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

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


Re: Dialog boxes with dynamic contents

2009-11-09 Thread Kevin Brock

Kyle Sluder wrote:

On Mon, Nov 9, 2009 at 9:10 AM, Kevin Brock  wrote:
  

I'm pretty sure that I could just do it programmatically, creating and
laying things out on the fly, but I'm hoping there's a simpler way.  Most of
the application is standard windows in a nib file.



You could take the NSPredicateEditor approach and create different
views for each kind of thing that will be displayed in the dialog.
Then it's just a matter of unfreezing these views from their nibs and
arranging them at runtime, rather than arranging every single control.
  


I don't know the higher level arrangements in advance either...  It 
really is down to the per-control level.

If you need finer-grained control than even that, you could do the
loading using a subclass of NSViewController and put your
view-rearrangement logic in that object, which would be the nib's
file's owner.
  


I'll take a look at that.  Thanks.

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


Less verbose way to localize a string with a default value?

2009-11-09 Thread Dave DeLong

Hi everyone,

I want to use the NSLocalizedStringWithDefaultValue macro in my code  
(so I can see the proper strings in the UI as I debug), but it's  
awfully verbose.  For example:


NSLocalizedStringWithDefaultValue(@"LibraryFolderTitle", (nil),  
[NSBundle mainBundle], @"Library", @"Library folder title")


I created a simple macro called DDLocalizedStringWithDefaultValue that  
just takes the key and the default value, and inserts the (nil) and  
[NSBundle mainBundle] bits for me.  The problem is that genstrings  
doesn't recognize my macro.


Is there a way I can allow for localized strings with a default value,  
not have to be so verbose, but still have it be recognized by  
genstrings?


Thanks,

Dave

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: beginner question, NSNumber, NSDecimalAsNumber

2009-11-09 Thread Thomas Wetmore
I offer the following as a "Cocoa solution" to the OP's query,  
whatever that might be taken to mean...


(For extra credit: why must the parameter be unsigned?)

Tom Wetmore

NSString* binaryRepresentation (NSUInteger number)
{
unichar buffer[64];
NSUInteger n = 0;
while (number) {
buffer[n++] = (number & 1) + '0';
number >>= 1;
}
NSInteger i = 0, j = n - 1;
while (i < j) {
unichar temp = buffer[j];
buffer[j] = buffer[i];
buffer[i] = temp;
i++, j--;
}
return [NSString stringWithCharacters: buffer length: n];
}
___

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

Please do not post 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


Creating a small timer?

2009-11-09 Thread Michael Abendroth
Hi,

I would like to create a small timer. Basically, the timer sits in a
view. When the view is shown, the timer should start, and when the
view is hidden / closed, the timer should stop. While the view is
visible, the user should be able to access controls / manipulate
values inside the view.
How can I create such a timer?  I mean, it probably isn't very
efficient to redraw the whole view every second just to get the timer
to update. But is creating a separate thread just for the timer
necessary (I doubt that)?
Thanks for any input,

Mike
___

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

Please do not post 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: Dialog boxes with dynamic contents

2009-11-09 Thread Kyle Sluder
On Mon, Nov 9, 2009 at 9:10 AM, Kevin Brock  wrote:
> I'm pretty sure that I could just do it programmatically, creating and
> laying things out on the fly, but I'm hoping there's a simpler way.  Most of
> the application is standard windows in a nib file.

You could take the NSPredicateEditor approach and create different
views for each kind of thing that will be displayed in the dialog.
Then it's just a matter of unfreezing these views from their nibs and
arranging them at runtime, rather than arranging every single control.

If you need finer-grained control than even that, you could do the
loading using a subclass of NSViewController and put your
view-rearrangement logic in that object, which would be the nib's
file's owner.

--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: Hardware UUID

2009-11-09 Thread Chris Parker
Please remember that gethostuuid() has all the same caveats mentioned  
in TN1103.


.chris

On 8 Nov 2009, at 3:13 PM, Grigutis, John A wrote:


Also look at gethostuuid:

int gethostuuid(uuid_t id, const struct timespec *wait)

I don't think it was around when that technote was last updated.

--  
John Anthony Grigutis

Systems Analyst/Programmer/Mac Specialist
Indiana University : UITS : Communication & Support : SDD

On Nov 8, 2009, at 3:53 PM, Brent Smith wrote:


Thanks Jerry,
This is exactly what I needed.

On Nov 8, 2009, at 12:14 PM, Jerry Krinock wrote:



On 2009 Nov 08, at 11:05, Brent Smith wrote:


Is there a simple way to obtain and hardware uuid of the mac?


Read this first:

http://developer.apple.com/mac/library/technotes/tn/tn1103.html
___

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

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

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

This email sent to liare...@hack3r.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/grigutis
%40indiana.edu

This email sent to grigu...@indiana.edu


___

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

Please do not post 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/ctp%40apple.com

This email sent to c...@apple.com


___

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

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

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

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


Dialog boxes with dynamic contents

2009-11-09 Thread Kevin Brock
I'm looking for some pointers to information on creating dialog boxes 
with content (# and type of controls) determined at runtime.


All that I really know ahead of time is that there will be a dialog box 
to gather some data, and that the UI objects in the dialog come from a 
small, well defined set of types of objects.  I don't know what order 
they're going to be in, or how many there will be (small number, almost 
always), either in aggregate or or each type.


I'm pretty sure that I could just do it programmatically, creating and 
laying things out on the fly, but I'm hoping there's a simpler way.  
Most of the application is standard windows in a nib file.


What I'm wondering is whether there are tools that would help with 
this...  Although I've done some basic GUI work on OS X I know that 
there are plenty of things in the toolkit that I'm not aware of.


Anyone know of anything that would make this simpler?

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


Re: NSString of selected text in NSTextView

2009-11-09 Thread Jens Alfke


On Nov 7, 2009, at 7:49 PM, Todd Heberlein wrote:

Yeah, one of the concerns I had was whether the selected NSRange is  
preserved when -string is called.


I've always assumed it is. That is, all character indexes that appear  
in the NSText[View] API correspond to character positions in the  
textStorage's string. It seems that this has to be true, because  
there's no other meaningful way to define the character indexes.


—Jens

___

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

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

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

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


Re: beginner question, NSNumber, NSDecimalAsNumber

2009-11-09 Thread Thomas Wetmore
These functions return how many one bits there are in a number, not  
how many bit positions are needed to represent the number as a bit- 
string with no leading zeros. They are fun but have no utility in  
solving the OP's question.


TW

There are some examples of how to do this here, including some  
really, really clever methods.


http://gurmeetsingh.wordpress.com/2008/08/05/fast-bit-counting-routines/


___

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

Please do not post 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: iPhone: NSOperation and UITableVIews

2009-11-09 Thread Dave Camp

On Nov 8, 2009, at 8:35 PM, John Michael Zorko wrote:

I have an indexed table view with -- surprise -- images that take a  
long time to load. So, I put the loading into an NSOperation-derived  
subclass and have the main() method send a "refresh" msg to my main  
thread, telling it to reload the table.  This works, but the problem  
is that if the user scrolls quickly, a whole bunch of NSOperations  
get queued up, even for cells that the user scrolled far past i.e.  
they're not anywhere close to being on the screen. This has the bad  
effect of making my "refresh" msg get send for cells that have long  
since passed, making the app really slow to scroll (which really  
defeats the purpose of this whole exercise).


I would like to cancel these extra NSOperation instances, but my app  
is targeting OS 2.2.1 and:


1. I can't seem to see a way of determining if a cell is going to be  
drawn or not i.e. I don't see a way to cancel the NSOperations that  
aren't relevant to the portion of the table view that would be shown  
on the screen.


2. I thought maybe -UITableView reloadRowsAtIndexPaths would help  
(instead of calling -UITableView reloadData every time, which is why  
scrolling is so slow now), but that method is OS 3.1 only.


An alternative implementation might be to have each cell queue up an  
operation when it needs to load an image (not the view controller).  
Then, each cell could cancel it's operation in [UITableViewCell  
prepareForReuse].


Dave

___

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

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

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

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


Re: Best pattern for similar objects with differences

2009-11-09 Thread Paul Bruneau

Thanks all for your help-

I wasn't clear enough, I agree, and sorry about that, but there was a  
hint hidden in my text:
> (I'm going to have categories to handle drawing, material takeoff,  
pricing, etc for each door type).


We manufacture entrances (and many doors). The users of this app enter  
data from customer orders and my app generates pricing and build  
information. The users do need to be able to change the type of door  
(because often the customer will change it during the process). It's  
extra nice not to lose any data during these changes (although some  
properties get reset during a type change).


I think the direction I'm going to go is to put all the properties of  
all the door types into the base class, but still have subclasses so  
that I can separate out all the various methods and categories that  
are going to be specific to each door type.


I'm sorry if this was borderline not cocoa (and more obj-c or data  
structure theory or something), but I definitely want to utilize  
patterns that are most compatible with Cocoa so I felt it was  
reasonable that it be asked here.


Thank you all again, I have read each of your responses 5 times :)

On Nov 4, 2009, at 1:47 PM, Paul Bruneau wrote:


Hi-

I'm in early development of an app (non-core data, NSDocument app)  
that will deal with a lot of doors. I have created a door object,  
SLDoor, which currently contains all of the properties that might be  
used by any of the several types of doors.


There is a doorType property which is what determines which of the  
types of doors a particular instance is.


This means that if you choose a door type, many properties that are  
only used by any of the other types will go unused. On the other  
hand, it's very good for if the user wants to change the door type-- 
the properties are all there ready and waiting.


But I did have the idea that I should make SLDoor a superclass of  
new classes, one for each type of door. So I would have  an  
SLFlushDoor, an SLMonumentalDoor, and an SLPlankDoor for example,  
all subclasses of SLDoor.


In this way, I can really separate out all kinds of code and  
properties that are specific to a certain type of door, while  
keeping in the superclass all the properties that are shared among  
several or all of the types of door (I'm going to have categories to  
handle drawing, material takeoff, pricing, etc for each door type).


So this is very attractive, but I keep worrying about how I would  
change a door from one type to another if I utilize these  
subclasses. Any ideas the best pattern to use? I can't figure out  
how I would take an existing object of say SLFlushDoor and convert  
it to an SLMonumentalDoor (and possibly back again) with anything  
close to the ease that I currently do it with the doorType property  
(but I shudder to think of all the if() statements I would have  
strewn through all my code if I stick with this pattern.)


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


Re: iPhone: NSOperation and UITableVIews

2009-11-09 Thread Alex Kac
There is no need to reload the table. If you simply change the  
UIImageVIew that the image is assigned to, that will refresh. So  
you're using a very heavy handed method right now which isn't even  
needed.


Second, if you simply store into your NSOperation-derived subclass the  
tag of each imageview (assign each cell's imageView a tag of the row  
number), then sure that subclass will be doing work of getting the  
image (that you can then cache), but when you call viewForTag - it'll  
come back nil and it'll be a no-op.



On Nov 8, 2009, at 10:35 PM, John Michael Zorko wrote:



Hello, all ...

I have an indexed table view with -- surprise -- images that take a  
long time to load. So, I put the loading into an NSOperation-derived  
subclass and have the main() method send a "refresh" msg to my main  
thread, telling it to reload the table.  This works, but the problem  
is that if the user scrolls quickly, a whole bunch of NSOperations  
get queued up, even for cells that the user scrolled far past i.e.  
they're not anywhere close to being on the screen. This has the bad  
effect of making my "refresh" msg get send for cells that have long  
since passed, making the app really slow to scroll (which really  
defeats the purpose of this whole exercise).


I would like to cancel these extra NSOperation instances, but my app  
is targeting OS 2.2.1 and:


1. I can't seem to see a way of determining if a cell is going to be  
drawn or not i.e. I don't see a way to cancel the NSOperations that  
aren't relevant to the portion of the table view that would be shown  
on the screen.


2. I thought maybe -UITableView reloadRowsAtIndexPaths would help  
(instead of calling -UITableView reloadData every time, which is why  
scrolling is so slow now), but that method is OS 3.1 only.


Any pointers are appreciated!  What is available in OS 2.2.1 to help  
me solve this?


Regards,

John

Falling You - exploring the beauty of voice and sound
http://www.fallingyou.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/alex%40webis.net

This email sent to a...@webis.net


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

"You cannot build a reputation on what you intend to do."
-- Liz Smith




___

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

Please do not post 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: beginner question, NSNumber, NSDecimalAsNumber

2009-11-09 Thread Andy Lee

On Nov 9, 2009, at 9:55 AM, Jay Swartzfeger wrote:

On Mon, Nov 9, 2009 at 9:52 AM, Alastair Houghton
 wrote:


Anyway, there are lots of neat tricks of this nature.

(All of this probably isn't for newbie C programmers, though it's  
perfectly

possible that a newbie ObjC programmer might not be new to C or C++.)


Where I'm still confused, there have been many alternatives offered --
what solution would be used in a Cocoa context?


The answer, as is usual when there are many alternatives, is "It  
depends."


Personally, I would skip all the clever solutions.  I would start with  
an empty NSMutableString and modify Graham's code to prepend "0" or  
"1" to the string, thus addressing the "backwards" issue.  As a  
reminder, here's what Graham posted:


- (NSString *)  to_binary( int n )
{
   do
putchar(( n & 1 )? '1' : '0');
   while( n >>= 1 );
}

Maybe put the NSMutableString code in a category of NSString.  I think  
this is would be a useful exercise for a Cocoa newcomer.


--Andy

___

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

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

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

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


Re: beginner question, NSNumber, NSDecimalAsNumber

2009-11-09 Thread Jay Swartzfeger
On Mon, Nov 9, 2009 at 9:52 AM, Alastair Houghton
 wrote:
>
> Anyway, there are lots of neat tricks of this nature.
>
> (All of this probably isn't for newbie C programmers, though it's perfectly
> possible that a newbie ObjC programmer might not be new to C or C++.)

Where I'm still confused, there have been many alternatives offered --
what solution would be used in a Cocoa context?

Jay
___

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

Please do not post 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: beginner question, NSNumber, NSDecimalAsNumber

2009-11-09 Thread Alastair Houghton

On 9 Nov 2009, at 12:08, Graham Cox wrote:


On 09/11/2009, at 10:55 PM, Alastair Houghton wrote:

It's pretty easy to do a bit count on a fixed-size word (no need  
for a loop, in fact).


There are some examples of how to do this here, including some  
really, really clever methods. Is this what you had in mind Alastair?


http://gurmeetsingh.wordpress.com/2008/08/05/fast-bit-counting-routines/


Yes, those kinds of things.

Also, I neglected to point out that for binary and hexadecimal, it's  
possible to do more than one digit at a time, even if you don't want  
leading zeroes (for the non-leading-zeroes case, you just need two  
tables of results, one with leading zeroes and one without, then the  
first time you encounter a one bit, you swap from the no-leading- 
zeroes table to the one with leading zeroes).


Anyway, there are lots of neat tricks of this nature.

(All of this probably isn't for newbie C programmers, though it's  
perfectly possible that a newbie ObjC programmer might not be new to C  
or C++.)


Kind regards,

Alastair.

--
http://alastairs-place.net



___

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

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

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

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


Re: beginner question, NSNumber, NSDecimalAsNumber

2009-11-09 Thread Jay Swartzfeger
On Mon, Nov 9, 2009 at 7:08 AM, Graham Cox  wrote:
>
> There are some examples of how to do this here, including some really,
> really clever methods. Is this what you had in mind Alastair?
>
> http://gurmeetsingh.wordpress.com/2008/08/05/fast-bit-counting-routines/
>
> --Graham

Thanks all, great stuff and a lot for me to chew on/experiment with.

Jay
___

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

Please do not post 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: NSTreeController and object retain counts

2009-11-09 Thread Andy Lee

On Nov 9, 2009, at 8:16 AM, Mads Paulin wrote:
What strikes me as odd is that all Nodes in the document array are  
created
and removed directly via the add and remove actions on the  
treecontroller.
- I dont have a single "external" access to these objects. I would  
hence

expect the controller to "clean up after itself".


It isn't a matter of the controller "cleaning up" so much as following  
the memory management rules. If you follow the memory management  
rules, it's the Objective-C runtime that does the cleaning up by (1)  
releasing objects that you asked to be autoreleased and (2)  
dealloc'ing objects when their retain count reaches zero.


The newObject method returns an object that the caller owns and is  
therefore responsible for eventually releasing.  If NSTreeController  
uses newObject in its implementation of add:, then it is responsible  
for releasing it somewhere.  It sounds like it is not doing so.


In dealing with this issue, make sure you understand the concept of  
objects you "own" vs. objects you don't own: . This is how you should be thinking about memory management, *not*  
by looking at retain counts in isolation, because retain counts can be  
misleading.  That said, I think it is okay to resort to brute force  
and look at when retain and release are called, and to make sure every  
retain is eventually balanced by a release.  You can use NSLog like  
you did, or Instruments.


--Andy



Lets hope there is a couple of NSTtreeController gurus on this list  
who

are able to explain the problem.

Regards,
Mads


On Nov 9, 2009, at 6:31 AM, Mads Paulin wrote:

Hi,

Yes my Document class releases the array in its dealloc method and
all Node
objects in the array are properly dealloc'ed when deallocing the
document.

However, I think the problem is unrelated to the retaining of the
array
member of the document class but rather to the retaining of elements
added
to the array via NSTreeControllers add:sender and remove:sender  
class.


Yes, this is how I understood your problem.



Adding a node object through this method creates a node object in  
the

document array member with a retain count of 2. The remove:sender
method
correctly removes the object from the document's array


This is the first thing I was going to suggest checking -- whether  
the

object is actually removed from the array.  Since it is...


but only decrements
the node object's retain count to 1 - meaning that the objects are
never
dealloc. As I see it, this is a memory leak in NSTreeController as
all "my"
external references to the Node objects are lost.


I've never used NSTreeController but something in the doc for add:
struck me as odd:

"If the receiver is in object mode newObject is called and the
returned object is added to the collection."

Since newObject returns a retained object, if this is the literal
sequence of events (call newObject, then add to collection), it sure
seems like a memory leak to me.  Or arguably not, since the sequence
of events is documented, but then it's a serious API inconsistency,
since AFAIK NSArrayController doesn't have the same issue.

I do know NSTreeController is a frequently-complained-about class.   
If
this is the issue you're running into, surely someone who's dealt  
with

it more extensively should be able to either confirm the issue or say
it's a red herring (in which case it's a documentation bug).

--Andy




Thanks,
Mads




Mads Paulin wrote:


#import 

@interface MyDocument : NSDocument
{
NSMutableArray *array;
}

@property (readonly) NSMutableArray* array;

@end

All I changed in the doc impl is
@synthesize array
and
array =[ [NSMutableArray]alloc init]; in the init method.



Does your MyDocument implementation ever release array?  If not,  
then

what happens to the NSMutableArray and what it contains when
MyDocument is dealloc'ed?  I don't think @synthesize will  
synthesize

any cleanup for you.

 -- GG
___

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

Please do not post admin requests or moderator comments to the  
list.

Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/mads%40madspaulin.dk

This email sent to m...@madspaulin.dk



___

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

Please do not post 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/aglee%40mac.com

This email sent to ag...@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 

Re: NSTreeController and object retain counts

2009-11-09 Thread Mads Paulin
Hi Andy,

Thank you for your input.

I did actually try to exchange the OutlineView with a TableView and the
TreeController with an ArrayController and the problem went away meaning
that all elements in the collection was correctly dealloced when calling
remove:sender on the controller.

What strikes me as odd is that all Nodes in the document array are created
and removed directly via the add and remove actions on the treecontroller.
- I dont have a single "external" access to these objects. I would hence
expect the controller to "clean up after itself".

Lets hope there is a couple of NSTtreeController gurus on this list who
are able to explain the problem.

Regards,
Mads

> On Nov 9, 2009, at 6:31 AM, Mads Paulin wrote:
>> Hi,
>>
>> Yes my Document class releases the array in its dealloc method and
>> all Node
>> objects in the array are properly dealloc'ed when deallocing the
>> document.
>>
>> However, I think the problem is unrelated to the retaining of the
>> array
>> member of the document class but rather to the retaining of elements
>> added
>> to the array via NSTreeControllers add:sender and remove:sender class.
>
> Yes, this is how I understood your problem.
>
>>
>> Adding a node object through this method creates a node object in the
>> document array member with a retain count of 2. The remove:sender
>> method
>> correctly removes the object from the document's array
>
> This is the first thing I was going to suggest checking -- whether the
> object is actually removed from the array.  Since it is...
>
>> but only decrements
>> the node object's retain count to 1 - meaning that the objects are
>> never
>> dealloc. As I see it, this is a memory leak in NSTreeController as
>> all "my"
>> external references to the Node objects are lost.
>
> I've never used NSTreeController but something in the doc for add:
> struck me as odd:
>
> "If the receiver is in object mode newObject is called and the
> returned object is added to the collection."
>
> Since newObject returns a retained object, if this is the literal
> sequence of events (call newObject, then add to collection), it sure
> seems like a memory leak to me.  Or arguably not, since the sequence
> of events is documented, but then it's a serious API inconsistency,
> since AFAIK NSArrayController doesn't have the same issue.
>
> I do know NSTreeController is a frequently-complained-about class.  If
> this is the issue you're running into, surely someone who's dealt with
> it more extensively should be able to either confirm the issue or say
> it's a red herring (in which case it's a documentation bug).
>
> --Andy
>
>
>>
>> Thanks,
>> Mads
>>
>>
>>
>>> Mads Paulin wrote:
>>>
 #import 

 @interface MyDocument : NSDocument
 {
NSMutableArray *array;
 }

 @property (readonly) NSMutableArray* array;

 @end

 All I changed in the doc impl is
 @synthesize array
 and
 array =[ [NSMutableArray]alloc init]; in the init method.
>>>
>>>
>>> Does your MyDocument implementation ever release array?  If not, then
>>> what happens to the NSMutableArray and what it contains when
>>> MyDocument is dealloc'ed?  I don't think @synthesize will synthesize
>>> any cleanup for you.
>>>
>>>   -- GG
>>> ___
>>>
>>> Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)
>>>
>>> Please do not post admin requests or moderator comments to the list.
>>> Contact the moderators at cocoa-dev-admins(at)lists.apple.com
>>>
>>> Help/Unsubscribe/Update your Subscription:
>>> http://lists.apple.com/mailman/options/cocoa-dev/mads%40madspaulin.dk
>>>
>>> This email sent to m...@madspaulin.dk
>>>
>>
>> ___
>>
>> Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)
>>
>> Please do not post 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/aglee%40mac.com
>>
>> This email sent to ag...@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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

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


Re: beginner question, NSNumber, NSDecimalAsNumber

2009-11-09 Thread Graham Cox


On 09/11/2009, at 10:55 PM, Alastair Houghton wrote:

It's pretty easy to do a bit count on a fixed-size word (no need for  
a loop, in fact).



There are some examples of how to do this here, including some really,  
really clever methods. Is this what you had in mind Alastair?


http://gurmeetsingh.wordpress.com/2008/08/05/fast-bit-counting-routines/

--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: NSTreeController and object retain counts

2009-11-09 Thread Andy Lee

On Nov 9, 2009, at 6:31 AM, Mads Paulin wrote:

Hi,

Yes my Document class releases the array in its dealloc method and  
all Node
objects in the array are properly dealloc'ed when deallocing the  
document.


However, I think the problem is unrelated to the retaining of the  
array
member of the document class but rather to the retaining of elements  
added

to the array via NSTreeControllers add:sender and remove:sender class.


Yes, this is how I understood your problem.



Adding a node object through this method creates a node object in the
document array member with a retain count of 2. The remove:sender  
method

correctly removes the object from the document's array


This is the first thing I was going to suggest checking -- whether the  
object is actually removed from the array.  Since it is...



but only decrements
the node object's retain count to 1 - meaning that the objects are  
never
dealloc. As I see it, this is a memory leak in NSTreeController as  
all "my"

external references to the Node objects are lost.


I've never used NSTreeController but something in the doc for add:  
struck me as odd:


"If the receiver is in object mode newObject is called and the  
returned object is added to the collection."


Since newObject returns a retained object, if this is the literal  
sequence of events (call newObject, then add to collection), it sure  
seems like a memory leak to me.  Or arguably not, since the sequence  
of events is documented, but then it's a serious API inconsistency,  
since AFAIK NSArrayController doesn't have the same issue.


I do know NSTreeController is a frequently-complained-about class.  If  
this is the issue you're running into, surely someone who's dealt with  
it more extensively should be able to either confirm the issue or say  
it's a red herring (in which case it's a documentation bug).


--Andy




Thanks,
Mads




Mads Paulin wrote:


#import 

@interface MyDocument : NSDocument
{
NSMutableArray *array;
}

@property (readonly) NSMutableArray* array;

@end

All I changed in the doc impl is
@synthesize array
and
array =[ [NSMutableArray]alloc init]; in the init method.



Does your MyDocument implementation ever release array?  If not, then
what happens to the NSMutableArray and what it contains when
MyDocument is dealloc'ed?  I don't think @synthesize will synthesize
any cleanup for you.

  -- GG
___

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

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

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/mads%40madspaulin.dk

This email sent to m...@madspaulin.dk



___

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

Please do not post 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/aglee%40mac.com

This email sent to ag...@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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

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


Re: beginner question, NSNumber, NSDecimalAsNumber

2009-11-09 Thread Alastair Houghton

On 9 Nov 2009, at 10:49, Thomas Wetmore wrote:

The approach found by Ron prints the bits in correct order. The  
suggested replacement prints them backwards. Other correct solutions  
can be done without recursion, but require a char buffer that must  
either be reversed or printed in reverse order.


Or you can calculate the number of bits and fill the buffer in  
reverse.  It's pretty easy to do a bit count on a fixed-size word (no  
need for a loop, in fact).


Kind regards,

Alastair.

--
http://alastairs-place.net



___

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

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

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

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


Re: NSBitmapImageRepresentation image generation and saving resulting in image with much noise

2009-11-09 Thread Rob Keniger

On 09/11/2009, at 7:28 PM, Michael Robinson wrote:

> I'm getting images with a lot of noise in them, I was wondering if
> anyone has any ideas why this would be?  I've attached a screenshot of
> the noisy images I've been getting. The shot is of four images that 
> well shouldn't have any noise at all.


An NSBitmapImageRep is not guaranteed to be empty when you create it and in 
general it's just full of random bits. You need to clear it explicitly if you 
are drawing non-opaque content:

void ClearBitmapImageRep(NSBitmapImageRep* bitmap) 
{
unsigned char* bitmapData = [bitmap bitmapData];
if (bitmapData != NULL)
{
bzero(bitmapData, [bitmap bytesPerRow] * [bitmap pixelsHigh]);
}
}

--
Rob Keniger



___

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

Please do not post 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: NSTreeController and object retain counts

2009-11-09 Thread Graham Cox


On 09/11/2009, at 10:31 PM, Mads Paulin wrote:


Adding a node object through this method creates a node object in the
document array member with a retain count of 2. The remove:sender  
method
correctly removes the object from the document's array but only  
decrements
the node object's retain count to 1 - meaning that the objects are  
never
dealloc. As I see it, this is a memory leak in NSTreeController as  
all "my"

external references to the Node objects are lost.



You can't meaningfully debug by peeking at retain counts. Instead try  
logging from the -dealloc method if possible, or use the leaks  
Instrument to find out if the objects are really not being  
deallocated. There's no requirement that the retain count is actually  
decremented to 0 - the code may merely predict that it would be and  
call -dealloc, rather than actually doing it.


--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: NSTreeController and object retain counts

2009-11-09 Thread Mads Paulin
Hi,

Yes my Document class releases the array in its dealloc method and all Node
objects in the array are properly dealloc'ed when deallocing the document.

However, I think the problem is unrelated to the retaining of the array
member of the document class but rather to the retaining of elements added
to the array via NSTreeControllers add:sender and remove:sender class.

Adding a node object through this method creates a node object in the
document array member with a retain count of 2. The remove:sender method
correctly removes the object from the document's array but only decrements
the node object's retain count to 1 - meaning that the objects are never
dealloc. As I see it, this is a memory leak in NSTreeController as all "my"
external references to the Node objects are lost.

Thanks,
Mads



> Mads Paulin wrote:
>
>> #import 
>>
>> @interface MyDocument : NSDocument
>> {
>>  NSMutableArray *array;
>> }
>>
>> @property (readonly) NSMutableArray* array;
>>
>> @end
>>
>> All I changed in the doc impl is
>> @synthesize array
>> and
>> array =[ [NSMutableArray]alloc init]; in the init method.
>
>
> Does your MyDocument implementation ever release array?  If not, then
> what happens to the NSMutableArray and what it contains when
> MyDocument is dealloc'ed?  I don't think @synthesize will synthesize
> any cleanup for you.
>
>-- GG
> ___
>
> Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)
>
> Please do not post admin requests or moderator comments to the list.
> Contact the moderators at cocoa-dev-admins(at)lists.apple.com
>
> Help/Unsubscribe/Update your Subscription:
> http://lists.apple.com/mailman/options/cocoa-dev/mads%40madspaulin.dk
>
> This email sent to m...@madspaulin.dk
>

___

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

Please do not post 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: beginner question, NSNumber, NSDecimalAsNumber

2009-11-09 Thread Graham Cox


On 09/11/2009, at 9:49 PM, Andy Lee wrote:


Won't this output the digits in reverse order?



Yes it will, but as I mentioned in an off-list message, the use of  
putchar is probably not very useful for a real-world implementation  
either, so you can compensate for the order when accumulating the  
result into a string (or whatever).


I guess as a former hardware guy the heavy stack use for such a  
trivial purpose just red-flagged me. Old habits die hard ;-)


--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: beginner question, NSNumber, NSDecimalAsNumber

2009-11-09 Thread Andy Lee

Won't this output the digits in reverse order?

--Andy

On Nov 9, 2009, at 5:27 AM, Graham Cox  wrote:



On 09/11/2009, at 9:01 PM, Ron Fleckner wrote:


void to_binary(int n)
{

  int r;
  r = n % 2;
  if (n >= 2)
  to_binary(n / 2);
  putchar('0' + r);
  return;

}


The above sledgehammer-hammer-ammer-mmer-mer-er is not required to  
crack such a nut:



voidto_binary( int n )
{
   do
   putchar(( n & 1 )? '1' : '0');
   while( n >>= 1 );
}


--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/aglee%40mac.com

This email sent to ag...@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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

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


Re: beginner question, NSNumber, NSDecimalAsNumber

2009-11-09 Thread Thomas Wetmore
The approach found by Ron prints the bits in correct order. The  
suggested replacement prints them backwards. Other correct solutions  
can be done without recursion, but require a char buffer that must  
either be reversed or printed in reverse order.


Tom Wetmore

On Nov 9, 2009, at 5:27 AM, Graham Cox wrote:



On 09/11/2009, at 9:01 PM, Ron Fleckner wrote:


void to_binary(int n)
{

  int r;
  r = n % 2;
  if (n >= 2)
  to_binary(n / 2);
  putchar('0' + r);
  return;

}


The above sledgehammer-hammer-ammer-mmer-mer-er is not required to  
crack such a nut:



voidto_binary( int n )
{
   do
putchar(( n & 1 )? '1' : '0');
   while( n >>= 1 );
}


--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/ttw4%40verizon.net

This email sent to t...@verizon.net


___

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

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

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

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


Re: beginner question, NSNumber, NSDecimalAsNumber

2009-11-09 Thread Graham Cox


On 09/11/2009, at 9:01 PM, Ron Fleckner wrote:


void to_binary(int n)
{

   int r;
   r = n % 2;
   if (n >= 2)
   to_binary(n / 2);
   putchar('0' + r);
   return;

}


The above sledgehammer-hammer-ammer-mmer-mer-er is not required to  
crack such a nut:



voidto_binary( int n )
{
do
putchar(( n & 1 )? '1' : '0');
while( n >>= 1 );
}


--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: beginner question, NSNumber, NSDecimalAsNumber

2009-11-09 Thread Ron Fleckner


On 09/11/2009, at 3:53 AM, Jay Swartzfeger wrote:


Hi all, I'm an absolute beginner to Objective-C (and programming in
general). I have lots of books on order, but I've been messing with
Xcode/Cocoa/iPhone SDK with online resources while I wait.

My question -- for my next project, I want to do a simple number <->
binary converter. Is this handled via the superclass NSNumber, or the
more specific NSDecimalAsNumber? I've been looking for examples online
and have come up empty handed. Thanks!

Jay


Hi Jay,

here is the code for a routine to go from decimal to binary  
representation from Stephen Prata, _C Primer Plus_ third edition:


/*
binary.c -- prints integer in binary form
From Steven Prata, "C Primer Plus", page 306-307
Prata says there, "the expression '0' + r evaluates to the  
character '0' if r is 0 and to the character '1' if r is 1."

*/
#include 
#include 

void to_binary(int n);

int main(void)
{

int num;
printf("Enter an integer (q to quit): \n");
while (scanf("%d", &num) == 1)
{
printf("Binary equivalent: ");
to_binary(num);
putchar('\n');
printf("Enter an integer (q to quit): \n");
 }

 return 0;
}

void to_binary(int n)
{

int r;
r = n % 2;
if (n >= 2)
to_binary(n / 2);
putchar('0' + r);
return;

}

Hope that helps,

Ron

___

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

Please do not post 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


NSBitmapImageRepresentation image generation and saving resulting in image with much noise

2009-11-09 Thread Michael Robinson

Hi List,

I'm attempting to create  a bunch of png or jpg images based on user-set
options.

I'm getting images with a lot of noise in them, I was wondering if
anyone has any ideas why this would be?  I've attached a screenshot of
the noisy images I've been getting. The shot is of four images that 
well shouldn't have any noise at all.

Is there a common mistake that can cause these noisy images?

This is some of the code for generating images:

- (void)generateImage{

 theImage = [[NSBitmapImageRep alloc] initWithBitmapDataPlanes:NULL
pixelsWide:imageSize.width pixelsHigh:imageSize.height
  bitsPerSample:8 samplesPerPixel:4
hasAlpha:YES isPlanar:NO
  colorSpaceName:NSDeviceRGBColorSpace
bytesPerRow:0 bitsPerPixel:0];

 [NSGraphicsContext saveGraphicsState];
 [NSGraphicsContext setCurrentContext:[NSGraphicsContext
graphicsContextWithBitmapImageRep:theImage]];

 //create a path delineating the outline of the image
 NSBezierPath *outlinePath = [self createOutlinePath];

 //create a path delineating the border line - if no border then
this will be equal to the outline
 if(hasBackgroundImage&&  !drawBGImageOverBG){//draw image below
gradient, background color
 [self drawBGImage:outlinePath];
 hasAnImage = YES;
 }
 if(hasBackgroundColor&&  !cssOnly){//if user wants a background
color and they don't want it with css
 [self fillImageWithBGColor:outlinePath];
 hasAnImage = YES;
 }
 if(hasGradient&&  !cssOnly){
 [self fillImageWithGradient:outlinePath];
 hasAnImage = YES;
 }
 if(hasBackgroundImage&&  drawBGImageOverBG){//draw image above
gradient, background color
 [self drawBGImage:outlinePath];
 hasAnImage = YES;
 }
 //Draw border... if the user wants one
 if(!cssOnly){
 [self drawBorder]; //border is created then painted onto
theImage
 hasAnImage = YES;
 }

 [NSGraphicsContext restoreGraphicsState];

}

Saving is done like:

- (NSString *)saveImage:(NSString*)dir:(NSString*)pageID:(NSString *)name{

 NSData *data = [NSData alloc];

 if(fileType == FILETYPE_PNG){
 data = [theImage representationUsingType:NSPNGFileType
properties:nil];
 fileName = [NSString stringWithFormat:@"%...@_%@.png", name, pageID];
 }
 else if(fileType == FILETYPE_JPG){
 data = [theImage representationUsingType:NSJPEGFileType
properties:nil];
 fileName = [NSString stringWithFormat:@"%...@_%@.jpg", name, pageID];
 }

 [data writeToFile:[NSString stringWithFormat:@"%@/%@", dir,
fileName] atomically:NO];

 return fileName;
}
This is part of a class that is instantiated once per image - should I
be doing something to ... clear a whatchamacall it or clean a thingameejig?

The first image that's created is OK, subsequent ones are not.

Is something being held back in memory maybe, spraying itself rudely
into each image?

Thanks list,

Mike


<>___

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

Please do not post 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