Re: printing arrays

2012-11-02 Thread Greg Guerin

Gerriet M. Denkmann wrote:


2012-...]  Bad Array: (
\U0e01\U0e38\U0e0d\U0e41\U0e08,
\U0e04\U0e38\U0e13\U0e04\U0e48\U0e32
)



For a very long time, the -description method of NSArray (and other  
collection classes) has produced the old-style ASCII plist format.   
Since that format has no direct representation for non-ASCII  
characters, the output is produced in escaped Unicode form.


See the description of Representations here:
http://en.wikipedia.org/wiki/Property_list

I don't know if collections have always done this, but they've acted  
that way for so long that I don't feel motivated to boot up an old  
PPC Mac and track it back into the dawn of history.


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

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


Re: Finder Info

2012-08-24 Thread Greg Guerin

koko wrote:

I forgot to add that the deployment target is 10.4  … which is why  
I asked …



Look at NSFileManager's deprecated methods, and find  
changeFileAttributes:atPath: .


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

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

Re: How do I get memory usage numbers?

2012-08-15 Thread Greg Guerin

Charlie Dickman wrote:

What I want to do is determine the ratio of inactive to free in  
order to determine when to execute the purge command to free up the  
inactive memory before the system gets into trouble.



It's unnecessary to purge or free Inactive memory.

Quoting from:
http://support.apple.com/kb/HT1342


Inactive:

This information is in RAM but it is not actively being used, it  
was recently used.


For example, if you've been using Mail and then quit it, the RAM  
that Mail was using is marked as Inactive memory. EMPHASIS  
ADDEDInactive memory is available for use by another  
application, just like Free memory.  However, if you open Mail  
before its Inactive memory is used by a different application, Mail  
will open quicker because its Inactive memory is converted to  
Active memory, instead of loading it from the slower drive.



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

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


Re: Document Based Application

2012-07-08 Thread Greg Guerin

koko wrote:

I have 29 file types and wanted to get away from the if or switch  
to open them and let NSDocument pick the right class for me.


As I understand it, an Item in the Document types array of the  
plist contains and entry for an NSDocument class.


And yes, each type has a unique extension (possibly multiple).   
I.e. type phobia has extensions pho, pho12, pho15 all mapped to  
NSDocument subclass MYPhobia.



Use an NSDictionary.  The key is the file extension.  The value is  
the subclass name, or the actual Class object.  Cost is one  
dictionary lookup.  Plus it's extensible, and can be revised without  
altering code.


You can also add a level of indirection.  The key is still file  
extension, but the value is a number (int).  Use the number as an  
index into an NSArray of classname strings, or the actual Class objects.


The dictionary and/or array can be stored as plists in your app's  
Resources sub-dir.


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

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


Re: byte orders question

2011-11-26 Thread Greg Guerin

Koen van der Drift wrote:


u_int32_t value;
[base64DecodedData getBytes:value range:NSMakeRange 
(n*4, sizeof(u_int32_t))];


u_int32_t res = CFSwapInt32HostToBig(value);

float f;

memcpy(f, res, sizeof(f));
NSLog(@%f, f);



Since you're just doing a memcpy(), you can simply cast the bits and  
avoid the copying.  Try this:


float f = *((float*) res);

Or try defining a C union:

union foo {  float f;  u_int32_t u;  };
union foo bar;
bar.u = CFSwapInt32HostToBig(value);
float f = bar.f;

  -- 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/archive%40mail-archive.com

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


Re: Calling a Cocoa library from C

2011-11-12 Thread Greg Guerin

Nathan Sims wrote:

Hmm, if not a global, where would the declaration go? The C  
function certainly shouldn't return it, so if it is to remain  
persistent across calls, wouldn't the logical (the only?) place for  
it be as a global in the library's .m file?



Why shouldn't the C function return it?  As far as C is concerned, an  
object pointer is just an opaque pointer.  Handle it like any other  
opaque pointer.


Example:

void * setup_data()
{
return (void *) [[ObjcCode alloc]init];
}
int get_float_data( void * ptrFrom_setup_data, float *result1, float  
*result2)

{
ObjcCode *obj = (ObjcCode *) ptrFrom_setup_data;

NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];

[obj call];
*result1 = [more stuff];
etc.;

[pool drain];
return 0;
}
void quit_data( void * ptrFrom_setup_data )
{
[(ObjcCode *)ptrFrom_setup_data release];
}

  -- 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/archive%40mail-archive.com

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


Re: Blocks vs. life, the universe and everything

2011-10-15 Thread Greg Guerin

Quincey Morris wrote:

The problem is that the documentation clearly states that  
exceptions must not try to escape across dispatch queue operation  
boundaries. AFAICT, this means that for every one of the tiny code  
block fragments I write, not only does my fragment need to be  
wrapped in a '@try' block, I must also deal with the exception by  
(say) logging its description before leaving the block. Every time.  
That seems like an awful lot of boilerplate code, and it makes the  
blocks-based approach very unpalatable.



Suppose an @try was required at all times.  One logical approach  
would be factor it out, instead of pasting in boilerplate code.   
Factoring suggests writing a new function that takes the same args,  
but which wraps the incoming block inside another block that has @try/ 
@catch.  Just thinking out loud.


  -- 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/archive%40mail-archive.com

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


Re: -dateWithTimeIntervalSinceNow: 64-bits may overflow

2011-10-12 Thread Greg Guerin

Jerry Krinock wrote:

Not necessarily.  Multiple overflows tend toward a random number  
generator.


Doubles overflow to +INF, as do floats.  Arithmetic on INFs typically  
yields one of the INFs (+INF or -INF).  It is decidedly non-random.


It would be an interesting experiment, though.

  -- 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/archive%40mail-archive.com

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


Re: How to get mount options of a mounted volume

2011-10-11 Thread Greg Guerin

Oleg Krupnov wrote:


I'd like to get the mount options of a particular volume (like rw,
nobrowse, automounted etc.) of a mounted volume, like those I get
when I run mount command in the Terminal.



See the C function statfs().
See the include file sys/mount.h, struct statfs, member f_flags.
See the Darwin source for the 'mount' command.

But only if NSWorkspace getFileSystemInfoForPath doesn't return  
enough info.


  -- 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/archive%40mail-archive.com

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


Re: diskutil info -plist via Cocoa object?

2011-10-11 Thread Greg Guerin

Todd Heberlein wrote:

If not, does anyone know how is diskutil getting this information?  
For example getfsstat(), statfs(), ...?  I'm having troubles  
finding the equivalent of BusProtocol and Internal values in  
these structures.



BusProtocol is probably worked out from the device pathname (/dev/ 
something).  That's in struct statfs as f_mntfromname.


There's probably some munging to turn that path into an IOKit node,  
and from that, one of the ancestor nodes would identify the bus.  For  
example, look at the plist keys that contain Device as a prefix.   
The DeviceTreePath key has a value that identifies things like PCI  
and SATA (on my machine).


  -- 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/archive%40mail-archive.com

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


Re: creating multiple NSTimers

2011-09-29 Thread Greg Guerin

Gordon Apple wrote:

 There must already be an array for the table, so just iterate the  
array every
 minute or whatever (single repeating timer), compare the times to  
[NSDate
 date} and start or shut down whatever has not been started or shut  
down.  Much

 easier than trying to manage timers.

You don't have to iterate the whole array, either.  Sort it by  
ascending order of turn-off time.  Keep a current position (index).   
If the time of day is less than the turn-off time of the device at  
the current position, do nothing.  If time of day = turn-off time of  
current position, then turn it off and advance position until time of  
day is again less than the turn-off time of device at the current  
position.  Only needs one timer, and scales to as large an array as  
you want to keep.


  -- 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/archive%40mail-archive.com

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


Re: Why does Xcode define IBOutlet with @synthesize?

2011-09-24 Thread Greg Guerin

Charles Srstka wrote:

It’s a little disturbing that private instance variables can be  
altered so easily, but then I suppose the same thing could just as  
easily be done by a third-party monkeying with the ivar in a category.



No programming language with direct memory access is ever entirely  
safe.  And one that's defined as a strict superset of C can't ever be  
more safe than C itself is.  Since C lets you typecast pointers  
indiscriminately, that's a pretty big barn door to close after the  
horses have bolted.


  -- 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/archive%40mail-archive.com

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


Re: Task dispatching

2011-09-13 Thread Greg Guerin

Jon Sigman wrote:

Also, won't I need to increase shmmax in the kernel, especially if  
I have numerous flavors of the 1GB matrix to load?


What is a flavor of a matrix?

You need to explain what you're doing in terms of the data and its  
representation.  How is the matrix data represented on disk?  How  
does it need to be represented in memory?  How does a matrix's  
flavor affect its representation on disk and/or in memory?


For example, if every load of the matrix from disk to memory parses  
from textual representation to double representation, then you might  
be able to save a lot of time by parsing it once, writing the double  
representation to disk, then using mmap() or some other mechanism to  
load that file.


That's just an example.  I'm guessing at representations and at what  
needs to be done.  Without knowing exactly what your data  
representation is, and what needs to be done with it in memory,  
guessing at possible solutions isn't worth anything.


  http://www.perlmonks.org/index.pl?node_id=542341
.. You want to do X, and you think Y is the best way of doing it.
.. Instead of asking about X, you ask about Y.

  -- 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/archive%40mail-archive.com

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


Re: Follow-up on localizing Keychain names

2011-08-12 Thread Greg Guerin

Sean Leonard wrote:

Does anybody know how the display names for these keychains are  
localized, and how I can use this behavior for another keychain?



What have you tried?

Maybe it's the same way other file-system names are localized:

http://developer.apple.com/library/mac/#documentation/MacOSX/ 
Conceptual/BPInternational/Articles/LocalizingPathnames.html


  -- 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/archive%40mail-archive.com

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


Re: Writing global preferences file into /Library/Preferences (OS X Lion)

2011-07-21 Thread Greg Guerin

Peter C wrote:

Graham, I used to store serial number codes for all users, in this  
directory.


Looks like I have change it to save it user library directory.



The /Users/Shared/ directory is public-writable, with sticky-bit set  
(unless that changed in Lion, too).  See 'man sticky' for an  
explanation of the sticky-bit.  See the sample code CFPrefTopScores  
for example code.


The convention is to create a sub-directory there, not write files  
directly into /Users/Shared/.  If you put a globally readable file  
there, and you want any user to be able to modify it, be sure to  
apply the correct permissions to the sub-dir and to the prefs file  
itself.


  -- 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/archive%40mail-archive.com

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


Re: problem with dataWithContentsOfFile on Lion

2011-07-21 Thread Greg Guerin

Wilker wrote:

Before Lion, it really works well and fast, even on Wifi external  
drive

(through Airport Extreme), but now it get's really slow... I did some
checks, and now its reading the entire file... instead of just read  
128kb
(start and end). Anyone have an ideia on why its happening now? And  
how to

make it works as before on Snow Leopard?



You could use fopen(), fseek(), fread(), fclose().

Who knows, it might even be faster, since it doesn't have to call mmap 
().  Worst case, you call mmap() yourself.


  -- 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/archive%40mail-archive.com

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


Re: Optimizing a loop

2011-07-19 Thread Greg Guerin

Eric E. Dolecki wrote:

//Get the very best match there is to be found for  
song.

if(match  currentFoundValue){
currentFoundValue = match;
test = [songsDictionary objectForKey:thisSong];
dis = [NSArray arrayWithObject:test];
collection = [[MPMediaItemCollection alloc]
initWithItems:dis];
}
}



You never release the 'collection' variable in the surrounding 'for'  
loop, so if there happens to be more than one candidate match during  
the search, you'll leak all but one MPMediaItemCollection object.


Personally, I'd just defer the array-making (dis) and collection- 
making (collection) until after the 'for' loop finds the closest  
match.  Only do those things in the loop that are relevant to the  
loop: which is finding the closest matching MPMediaItem.  If it's not  
relevant to that search, defer it until after the closest match is  
found.


BTW, if you haven't profiled your code, you should do that first,  
before making any changes at all.  You haven't posted any evidence  
that the fuzzy matching of your StringDistance class is the cause of  
the performance problem.  It could just as easily be the making of  
dis and collection that's the problem.  Or it could be that the  
problem is better solved by improving the code of StringDistance  
(which you haven't posted).  There's no way of knowing without  
profiling first.


  -- 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/archive%40mail-archive.com

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


Re: Adding Spotlight comment data to folder/file

2011-07-11 Thread Greg Guerin

Kevin Muldoon wrote:

Well, as I indicated, it's only a bit of icing on the cake. I'm  
just a bit shocked such an trivial task in a scripting language  
requires such heavy lifting in Obj-C (or more accurately, C).



The Finder's spotlight comment is stored as an xattr attached to  
the file.


To test: make a file, add a comment to it in Finder's Get Info  
window, then in Terminal:


xattr -l /path/to/commentedFile

The xattr name is com.apple.metadata:kMDItemFinderComment.  The  
contents is a bplist (binary plist) containing the comment data.   
Maybe google the xattr name for more info.  Also see the output of  
'xattr -h' (xattr cmd's builtin help summary).


There are C functions for working with xattrs, which I've found were  
quite easy to use.  See 'man getxattr' and then check the other xattr  
functions listed under SEE ALSO.  Also check the output of: 'apropos  
xattr'.


  -- 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/archive%40mail-archive.com

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


Re: App Delegate Methods

2011-07-07 Thread Greg Guerin

koko wrote:

So, is there really an   
NSApplicationWillFinishLaunchingNotification or is Apple just  
pulling my leg?



From the reference doc for the NSApplicationDelegate protocol:
applicationWillFinishLaunching:

Sent by the default notification center immediately ***before the  
application object is initialized***.  (*'s added for emphasis)




What do you hope to accomplish with this event that you can't  
accomplish with applicationDidFinishLaunching: ?


  -- 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/archive%40mail-archive.com

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


Re: Using a Soundex category...

2011-07-06 Thread Greg Guerin

Eric E. Dolecki wrote:


http://www.cocoadev.com/index.pl?NSStringSoundex

However, when I tried it out I get strange results...

//someString is set to different strings each time tested
BOOL test = [someString soundsLikeString:@Face];
NSLog(@sounds like Face: %d,test);

Place = 0
Ace = 0
Mace = 0
Fake = 1
Testing = 0
Brake = 0

It would seem something is off to get negatives on Place, Ace  Mace.



There's this comment in the -soundexString method:

	 Replace consonants with digits as follows (but do not change the  
first letter):

 b, f, p, v = 1
 c, g, j, k, q, s, x, z = 2
 d, t = 3
 l = 4
 m, n = 5
 r = 6
 Collapse adjacent identical digits into a single digit of that value.
 Remove all non-digits after the first letter.
	 Return the starting letter and the first three remaining digits. If  
needed, append zeroes to make it a letter and three digits.


Assuming the code works as the comment says, and you should read the  
code to confirm this, then it doesn't change the first letter.  So it  
seems to me that Face won't match place, ace, or mace.


Maybe you could print the value of the -soundexString method instead  
of blindly relying on the boolean of soundsLikeString:.


  -- 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/archive%40mail-archive.com

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


Re: dealloc and scarce resources

2011-06-30 Thread Greg Guerin

James Merkel wrote:


Everyone doesn't approach this stuff with the same background.
We find from Kernighan and Ritchie (KR) second edition, section  
8.1 that a file descriptor is a small non-negative integer that  
refers to a file and is maintained by the system.


Wikipedia is also a useful reference.

When I select the words file descriptors on a web page, contextual- 
click it (right click, secondary click, control click), then choose  
Search with Google from the contextual menu, Wikipedia's page is the  
top hit.


  -- 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/archive%40mail-archive.com

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


Re: dealloc and scarce resources

2011-06-30 Thread Greg Guerin

Jeffrey Walton wrote:


Wikipedia is hardly the definitive reference. SEO comes to mind.


Luckily, I didn't say Wikipedia was a definitive reference.  I said  
useful reference.  And anyone at all familiar with it knows full  
well that its accuracy (and usefulness) can vary widely.  I, for one,  
would never use it as a definitive reference for any algorithm,  
though I may well use its links at the end of an article to begin my  
search for definitive references.


My main point was more that there is a very easy way to search for  
unknown terms that one encounters when reading documentation on the  
web.  This is on the same level as pointing out that nearly every  
reference page on developer.apple.com has Feedback buttons at the  
bottom of the page, where complaints about unknown terms can easily  
be filed.


  -- 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/archive%40mail-archive.com

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


Re: tableView: objectValueForTableColumn: row: method not getting called

2011-06-23 Thread Greg Guerin

Sandeep Mohan Bhandarkar wrote:


Have i missed anything else...??


All the protocol's methods are declared @optional.  That means the  
compiler won't check whether you've spelled your implementation's  
method-name correctly.  I have seen more than one case where it was  
misspelled, despite an absolute certainty it was correct.


  -- 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/archive%40mail-archive.com

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


Re: Automatically mirroring folders

2011-06-19 Thread Greg Guerin

Leonardo wrote:

2) During the period of time the stream is off, if some new files  
arrive

within the folder /A, I lose the notification to copy it.

How to workaround that?



Make a directory adjacent to /A and /B to use as a staging area for  
copying.  Only copy into the staging area.


http://en.wikipedia.org/wiki/Staging_area

When the copying of a file is complete, get its inode number.  Then  
rename the copy from the staging area into the actual target folder.   
After the copying is complete, and the rename is ready to occur,  
ignore all events that have the file's inode number.


  -- 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/archive%40mail-archive.com

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


Re: Retrieve NSTable DataSource from AppController

2011-06-18 Thread Greg Guerin

Kevin Muldoon wrote:

I have an NSTable which receives its dataSource from  
MyTableController.m. However, my AppController.m needs the data  
MyTableController.m holds. Since AppController.m hasn't explicitly  
instantiated MyTableController (MyTableController being an NSObject  
within IB with appropriate delegates and such) how does  
AppController.m access MyTableController.m data? Thanks for the help.



How many MyTableController instances will there be at once?

If it's one, then you can use a Singleton pattern rooted in  
AppController.  Simply make AppController own and manage the data  
source object (i.e. the Model for the table's View).  AppController  
is already a singleton (presumably), so giving it the responsibility  
for other application-wide singletons isn't crazy.  MyTableController  
then calls on the single AppController instance to obtain the data  
source object.


If there are multiple MyTableController instances at once, then you  
can have them register themselves with the single AppController when  
they are opened, and also unregister when closed.  AppController  
maintains a collection of these, and depending on which table data  
source it wants, uses some mechanism to identify the corresponding  
MyTableController.  An example mechanism might be sequence number (1,  
2, 3), name, etc. stored as keys in a dictionary, where the value is  
the MyTableController instance.


You can use the register/unregister approach if there's a single  
MyTableController, too, but it's more complex, and there's no need  
when a perfectly good Singleton relationship will work.


  -- 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/archive%40mail-archive.com

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


Re: Release a NSWindowController after the window is closed

2011-06-18 Thread Greg Guerin

Matt Neuburg wrote:


Why are we able to do that? m.



Because ARC is public knowledge:

http://clang.llvm.org/docs/AutomaticReferenceCounting.html

  -- 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/archive%40mail-archive.com

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


Re: Parent-child Design Pattern

2011-06-12 Thread Greg Guerin

Martin Hewitson wrote:

What I'm unsure about is, how to deal with the children objects. I  
will, in principle, have a ChildView. This raises some questions:


1) Should I have a ChildViewController class?



I don't think there's a single answer.  Parent/child relationships  
can be presented in many ways.  For example, see here:


http://designingwebinterfaces.com/designing-web-interfaces-12-screen- 
patterns


Many of those designs have some form of hierarchical data models, yet  
the views and view controllers may not have the same structure.


You should figure out what the view relationships are, then design  
view controllers accordingly. The role of the class is a VIEW  
controller, not a MODEL controller; it doesn't have to mirror the  
MODEL's structure.


  -- 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/archive%40mail-archive.com

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


Re: Mac OS Leopard: how to spawn an child application?

2011-06-11 Thread Greg Guerin

Nick wrote:

This per user idea does not let me use any advertisement-based   
IPCs (like
user domain sockets or bonjour). I need some per user only IPC -  
so other
user's instance of the process does  not interfere with the current  
user's

one.



A Unix domain socket can be placed anywhere in the file-system,  
AFAIK.  So put it in the user's home directory, probably best in a  
sub-dir like ~/Library/Application Support/YourAppNameHere/.  A  
location under user's home dir also ensures that access permissions  
are applied when addressing the socket.  The name need not be  
advertised if both parties already know its pathname.


http://en.wikipedia.org/wiki/Unix_domain_socket
UNIX domain sockets use the file system as address name space.

Also, Bonjour service type names may incorporate unique identifiers.   
For example, the user-name or user id, or a GUID known to both  
parties.  (Obey limits on service type name length, and consider  
vulnerability to spoofing attacks.)


  -- 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/archive%40mail-archive.com

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


Re: How disable Special Characters menu item?

2011-06-06 Thread Greg Guerin

McLaughlin, Michael P wrote:

I have a Cocoa app (Xcode 3.2.6) which displays text output in a  
window.  This is pure output not meant to be edited by the user.   
Accordingly, the textfield is marked as not editable or selectable  
in IB.



Speaking as a possible user, it is often useful to be able to select  
text and copy it to the clipboard, even if the text is pure output  
and isn't editable.  For example, Terminal.app allows this for all  
the text displayed in a shell window.


  -- 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/archive%40mail-archive.com

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


Re: Why does NSArray count return NSUInteger?

2011-05-30 Thread Greg Guerin

julius wrote:


My question is
Why did Cocoa developers make NSArray count return NSUInteger?



It's impossible to answer with certainty.  The person or persons who  
made that decision are not on this list (AFAIK).  Nor have they  
documented the rationale behind their design decisions for posterity.


Several hypotheses have been proposed.  The simplest one is that the  
returned type is consistent with the parameter types of all the other  
methods that have an index parameter.


You have countered with reasons why the various hypotheses are not  
compelling (in your opinion).  Others have countered with reasons why  
your reasons are not compelling (in their opinion).  Your taste is  
not theirs, nor is theirs yours.


In a practical sense, none of this matters.  The decision was made  
long, long ago.  It is what it is.  You're too late to save that  
sheep from drowning.


  -- 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/archive%40mail-archive.com

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


Re: add crlf to UITextView

2011-05-25 Thread Greg Guerin

koko wrote:

I had changed the string I was appending to @\n\nText to Add  
which also did not work.



You need to identify whether your string is a literal string in your  
Objective-C source, or whether it's something loaded from somewhere  
else.


If it's loaded from somewhere else, you need to identify whether it  
contains the literal characters backslash-Small-Letter-R-backslash- 
Small-Letter-N, or whether it contains the actual character codes for  
CR and LF.


You can do all these things by writing some code that dumps out the  
hex representations of every unichar in the string you are about to  
append.  Put this code immediately before the point where you call  
stringByAppendingString:.  Post what the hex output is.


If your string is a literal @\n\nText in an Objective-C source  
file, then that should be getting converted to LF-LF-Text, because  
the compiler will convert backslash-escaped characters.  Refer to the  
C rules on backslash used as an escape character in strings.  If  
you're not compiling the string with some kind of C compiler, then  
backslash has no special meaning, and what you will get is a literal  
backslash.


  -- 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/archive%40mail-archive.com

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


Re: Recursive search for files

2011-05-23 Thread Greg Guerin

James Merkel wrote:

I was trying to come up with a way to prevent the user from  
starting at the wrong place. (Putting up an Alert that says you  
can't start there). There's a method in the NSFileManager class  
called isDeletableFileAtPath. I am thinking that all of those  
volumes and higher level directories that I want to avoid are not  
deletable. Therefore I could use this as a filter.



You should test that assumption.  Test it when logged in as both a  
non-admin user and an admin user.  You might be surprised.


You also might be surprised if Apple changes anything in permissions,  
ACLs, etc. and suddenly you get a whole lot more files than you  
planned for.  So the whole premise seems a little shaky to me.


I'm not sure why you can't allow the user to start at the volume  
level, if by that you mean the root filesystem whose pathname is /.   
If you want to limit depth, give the user a control to limit depth.   
If you want to limit number of files, give the user a control for  
that.  Set reasonable defaults, but otherwise don't artificially  
limit what users can do.  You don't know how they've setup their  
storage, and arbitrary limitations are obnoxious.


If your concern is traversing every mounted volume, there's an easy  
way to detect that: it's the device-id in the struct filled in by stat 
() (see man page for stat(2)).  You don't have to decipher the device- 
id, you just have to check for a change in device-id to some value  
that differs from the device-id of where you started.  For an example  
of controlling depth, traversal of volumes, etc. look at the man page  
for the 'find' command.


There are also readable attributes (flags and xattrs) that can offer  
clues as to whether a directory is hidden from the GUI or not.  See  
man chflags, and man xattr.  The idea here is to not traverse hidden  
dirs unless the user says it should.  Some of these are also  
available as Spotlight metadata, so read up on that, too.


And don't put up any alert that says You can't start there.  Simply  
dim or don't show any items that should not be traversed.  Few things  
are worse than a cycle of You can't do that alerts, when the proper  
course is to only show things that can be done.


  -- 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/archive%40mail-archive.com

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


Re: Communicate Between CocoaAsyncSocket and Java Socket

2011-05-08 Thread Greg Guerin

Bing Li wrote:


I believe TCP can be used between Java and iOS. However, I worry that
particular serialization exists in CocoaAsyncSocket so that Java  
cannot

deserialize successfully. Do you think the issue exists?



No.  If there is an issue, it's almost certainly in your code.

First, I have used CocoaAsyncSocket to communicate with Java sockets,  
and had no problems.  I have sent and received binary data, lines of  
text, JSON data, and XML data.  It all worked fine.


Second, CocoaAsyncSocket doesn't have any particular  
serialization.  It's just a socket, and it works with bytes in  
NSData.  There is no other serialization, other than the in-memory  
layout of multibyte data structures you pass to and from NSData.  If  
you don't know exactly what the in-memory structure of the NSData  
bytes is, then you don't really know what you're sending or receiving.


If your Java code needs a particular serialization, then that's  
because your Java code is written a particular way.  The  
CocoaAsyncSocket must serialize data the same way.  If you change the  
Java code to produce or expect some other serialization format, then  
your CocoaAsyncSocket code must match it.


You will need to define the order of bytes in your protocol, by which  
I mean the order of bytes in the messages or streams exchanged  
between the two sides.  If you don't define the order of bytes, then  
there is no clearly defined common ground between the two sides.


  -- 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/archive%40mail-archive.com

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


Re: How to detect string encoding before reading a file in NSString?

2011-04-26 Thread Greg Guerin

Laurent Daudelin wrote:

I've found different ways to do that (some pure Cocoa, some using  
Carbon) but I was wondering about the wisdom of this list as to  
what is the best way to detect the encoding of a file before  
passing it to NSString initWithContentsOfFile:encoding:error:?



You might not have to guess at all, if the file has an xattr of  
com.apple.TextEncoding attached to it.  I don't know if any of the  
NSString encoding-guessing methods use this xattr or not.  It's easy  
to test, though: TextEdit.app writes the xattr when you Save As and  
choose an encoding.


The contents of the xattr is a text-encoding name (such as utf-8),  
then a semicolon, then a longish decimal number.


You can see a file's xattrs with the xattr command in Terminal.  Type  
'xattr -h' for a summary of options and args.  The xattr API works  
great in C (BSD functions, exist since OS 10.4 Tiger).


Google search terms:
xattr site:developer.apple.com

  -- 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/archive%40mail-archive.com

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


Re: Looking for help scanning entire drives

2011-02-23 Thread Greg Guerin

Laurent Daudelin wrote:

I need to write an application that will scan entire drives and  
compare files between the 2 drives.



man rsync

See the --dry-run, --stats, and --progress options in particular.

rsync can also run as a daemon, which may be easier than trying to  
control it with NSTask.


  -- 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/archive%40mail-archive.com

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


Re: inter-process locks

2011-02-19 Thread Greg Guerin

Alexander Cohen wrote:

Is there anyway to do interprocess locks using cocoa ( like a Mutex  
in Win32 )? The best i've found is not cocoa and uses flock but the  
man pages say its advisory only which is kindof scary.



man semget
man semop
man semctl

They're part of the Posix IPC functions, so obviously work across  
processes.


Like other Posix IPC functions, the proper use of the semaphore  
functions can be inscrutable.  I recommend searching for working  
examples rather than puzzling it out from man pages alone.


  -- 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/archive%40mail-archive.com

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


Re: -[NSSet containsObject:] returns NO when it should return YES

2011-02-19 Thread Greg Guerin

Michael Crawford wrote:

The following gdb console output demonstrates an instance of a  
media-item persistent-ID property that, when queried gives a large  
unsigned number.  When I ask again using the -longLongValue method,  
I get the answer I was expecting.  When I look inside the set, you  
will see that the value -1748299021286640132 is in the set.   
However, when -containsObject is called, it returns NO.



If the persistent-ID is unsigned, then longLongValue seems like the  
wrong type to use.  There are NSNumber methods for working with  
unsigned long long types.  Try using those exclusively and see if it  
changes anything.


NSNumber has a method that returns the type encoding as a C string (- 
objCType).  The long long type has a different value from the  
unsigned long long type: q vs. Q.


There's also this special consideration (see NSNumber class reference  
doc):
The returned type does not necessarily match the method the receiver  
was created with.


http://developer.apple.com/library/mac/#documentation/Cocoa/Reference/ 
Foundation/Classes/NSNumber_Class/Reference/Reference.html%23// 
apple_ref/occ/cl/NSNumber


The type encodings reference:
http://developer.apple.com/library/mac/#documentation/Cocoa/ 
Conceptual/ObjCRuntimeGuide/Articles/ocrtTypeEncodings.html%23// 
apple_ref/doc/uid/TP40008048-CH100-SW1



If nothing else works, convert the persistent-ID number to NSString,  
using an encoding like BASE64 or simply hex in a consistent upper or  
lower case.  I doubt that the performance cost for a string would be  
so high that making your own NSValue subclass would be worthwhile.


  -- 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/archive%40mail-archive.com

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


Re: readInBackgroundAndNotify and rsync output

2011-01-29 Thread Greg Guerin

Robert DuToit wrote:

I have been googling around and not sure how to do this - is it  
with NSData or NSStream perhaps?



You can use standard C's stdio lib: fopen(), fread(), fseek(), etc.   
Objective-C is a superset of C.  You can use any C library in  
Objective-C, exactly the same way you'd use it in C.


One advantage of using stdio is you can easily find tutorials,  
examples, etc.


  -- 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/archive%40mail-archive.com

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


Re: lots of find/replace in text file

2011-01-22 Thread Greg Guerin

Jeremy Matthews wrote:

I can't help but think there might be a better (and more efficient  
way) of handling this?



How much better (and more efficient) does it have to be?

It's a simple game, right?  Is it currently too slow or memory- 
consuming?  If not, why change it?


If you want a different design for some reason, maybe look into doing  
the template-file parsing only once.  Break it into a sequence of  
literal strings and replaceable strings in an NSArray.  To produce  
output, walk the array and output either a literal string or a  
replaced string at each element.  Or make a mutable copy of the array  
and use componentsJoinedByString: after replacing the replaceable  
items with their replacement strings.  That won't necessarily be  
better or more efficient, just different.


  -- 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/archive%40mail-archive.com

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


Re: sending data to a view not yet displayed

2011-01-16 Thread Greg Guerin

Shane wrote:


So I guess my question is, how do I make sure my view is able to
receive the data I want sent to it before it is ever displayed. I hope
that makes sense.



Send the data to a Model, not a View.  If the View and Model are the  
same object, then the only way to have a Model is to have a View.


If you separate View from Model, then you can create a Model once (or  
whenever it's needed), and send it any data.  It then provides its  
data to any View that wants it, whenever the View wants it  
(typically, initialize the View from the Model's data in  
awakeFromNib).  If the View goes away (dealloc'ed), the Model  
remains.  Or if the Model represents a Document, the Model goes away,  
too.


To start making a separate Model, go through your View and  
ViewController classes and decide whether each method, property, or  
stateful item is part of the logical structure or the visible  
structure.  Logical structure is what the program represents  
regardless of how it's presented.  Visible structure is graphics,  
windows, etc.  If you change something in the logical structure, the  
program's capabilities change.  If you change something in the  
visible structure, that changes how it looks, but the capabilities  
are the same.


Example: you can have a huge visible structure consisting of dialogs,  
palettes, pickers, etc. for setting and applying a font to a single  
string of text.  The logical structure is much simpler: there is a  
chosen font and there is a single string the font is applied to.  The  
Model has a string and a font.  Everything else is part of the View  
and/or ViewController.


  -- 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/archive%40mail-archive.com

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


Re: NSDictionary key types

2011-01-07 Thread Greg Guerin

Jon Sigman wrote:

The underlying issue I was having was how to know when different  
objects used as
keys might be reasonably expected to match, especially if they  
weren't generated

the same way (as with [NSNumber stringValue] and [NSString ...]).



That's easy: they match when isEqual: returns true.

See the NSDictionary class reference:
http://developer.apple.com/library/mac/#documentation/Cocoa/Reference/ 
Foundation/Classes/NSDictionary_Class/Reference/Reference.html


Find isEqual on the page:
  ... no two keys in a single dictionary are equal (as determined  
by isEqual:).


This subtly suggests that key equality is synonymous with isEqual:.

There is also a logical relationship between hash and isEqual, which  
must be maintained.  Objects that are equal must also have equal  
hashes.  Or: equality presupposes hash-identicality.


  -- 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/archive%40mail-archive.com

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


Re: XML to Plist

2010-12-28 Thread Greg Guerin

Sandro Noël wrote:


- (NSDictionary *) plist{
	NSMutableDictionary *resultDict = [[[NSMutableDictionary alloc]  
init] autorelease];

if ([self hasChildren]){
NSMutableArray *child = [[[NSMutableArray alloc]init] 
autorelease];
for (OSXMLElement *element in _children){
// if thiselement has children add them to an array
[child addObject:[element plist]];  

}
[resultDict setValue:child forKey:_elementName];
}
// just a regular node.
else {
[resultDict setValue:_elementText forKey:_elementName];
}
return resultDict;
}


If you don't want nodes stored in an array, then don't use  
NSMutableArray.


I think you need to step back from the coding and do a better  
analysis.  At each step of the logical analysis, given a type of XML  
node as input, write down exactly what actions should occur for the  
desired output.  Don't write code, just write down brief action  
descriptions.


For example, I see no arrays in your desired output, so there  
shouldn't be any need for creating an array.  If you don't create an  
array for children, analyze what is needed instead.


You could also benefit by doing an analysis (i.e. write action  
descriptions) of the code you have now.  When you get to the part  
that says Create array.  Fill it with every child, think about what  
that means.


FWIW, this isn't a Cocoa problem, it's a logic problem.  Get the  
logic right first, then the Cocoa code should be plain.


  -- 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/archive%40mail-archive.com

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


Re: XML to Plist

2010-12-28 Thread Greg Guerin

Sandro Noël wrote:

the glitch that breaks all my current logic is when there are  
elements with the same name at the same level.

for instance in a RSS,

rss
chanel
item
item
item


this breaks the logic I can apply to a NSDictionary, because the  
previous item gets overwritten with the current one.
That is why I've attempted to put them in array's but that had  
adverse effects also.



The obvious omission in your code is a conditional test.  You have to  
examine the child nodes first, to determine WHEN THERE ARE elements  
with the same name at the same level (your statement from above, my  
capitalization).  WHEN THERE ARE such nodes, it should do one thing,  
WHEN THERE AREN'T, it should do another.  All the code you've posted  
does the same thing unconditionally in both cases.  Your code has  
neglected to act on the conditional WHEN THERE ARE ..., even though  
the conditional statement is there in what you wrote.


  -- 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/archive%40mail-archive.com

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


Re: Encoding UIViews take long time..

2010-12-11 Thread Greg Guerin

Gustavo Pizano wrote:

Any way to improve even more performance?, when I have many many  
BCItemView on the scene, (around 120+),   it takes like 10 seconds  
to save. :S



Measure where your code spends its time by running it in  
Instruments.app and using the Time Profiler.  Use the measurements to  
tell you which parts of the code need improvement.


  -- 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/archive%40mail-archive.com

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


Re: label color

2010-12-05 Thread Greg Guerin

Ariel Feinerman wrote:


How to get label color before 10.6?



If you mean using Interface Builder, select a label, choose  
Attributes on the Inspector panel.  Also notice the class of the  
label: NSTextField.


Then look in NSTextField.h:

- (void)setBackgroundColor:(NSColor *)color;
- (NSColor *)backgroundColor;
- (void)setTextColor:(NSColor *)color;
- (NSColor *)textColor;

  -- 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/archive%40mail-archive.com

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


Re: Releasing static variable concurrent data protection questions...

2010-11-15 Thread Greg Guerin

Frederick C. Lee wrote:


2) Static variables on stack -- I was aware of this.



Static and on stack are mutually exclusive.  It's impossible to  
have a variable that is both, so static variables on stack is  
nonsense.


BTW, the C storage specifier for on stack is auto.  You might  
want to look at a C reference book and learn the difference between  
the static and auto storage classes.


You can have a static pointer that points to a stack (auto)  
location.  This will invariably fail, and is simply wrong on any  
semantic level.  That's because auto lifetime is limited to a  
function's lifetime; when the function returns all auto variables die.


You can have a stack pointer (i.e. auto pointer) that points to a  
static location.  There is nothing inherently wrong with this, unless  
you're expecting thread-safety.


If you intend to perform concurrent calculations, I suggest read-only  
inputs (sharable without locking), and single-writer outputs  
(unshared, hence no locking needed).  If the outputs must be  
delivered to a common location, such as a queue, then that (i.e. the  
queue) can be locked, but only for the duration of queueing the  
results data.  If you employ locking, you can quite easily lose any  
concurrency gains by having contested locks.  Then your threads are  
spending all their time coordinating access, instead of doing work.


  -- 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/archive%40mail-archive.com

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


Re: instance fails in its own class

2010-11-07 Thread Greg Guerin

N!K wrote:

However, exactly the same statement fails when pasted into -init of  
Class.m.


Build yields warnings  Class may not respond to -new.



This message suggests you're calling an instance method, not a class  
method, or that's the way the compiler is interpreting it.


Post your actual failing code, in the complete method where it fails.

For example, is your class really named Class?  If so, then that  
won't work.  The reason is that Class is already a defined type, and  
it doesn't descend from NSObject.  See the return type of the  
NSObject method -class.  Look it up in The Objective-C Programming  
Language reference doc, under the heading Defined Types, or see  
the include file objc/objc.h.


Furthermore, since +new is defined as +alloc followed by -init,  
calling +new in -init seems a little recursive to me,  but without  
seeing actual code, it's just a guess.


  -- 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/archive%40mail-archive.com

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


Re: Synchronizing iOS redraw

2010-11-07 Thread Greg Guerin

Rick Mann wrote:

Note that the precision of all this isn't so high as to make this  
hard real time. It just has to be good enough that a person  
watching the display and comparing it (visually) to an accurate  
clock would consider them to be synchronized. I'd like to do no  
worse than 100 ms.


Any ideas?



I can tell you from experience that 100 ms will be visually  
noticeable.  More than you might think.


In any case, to get the display to update ON the second you'd have to  
change the labels and such BEFORE the second actually occurs.


And you'd have to account for any discrepancy between the software's  
clock and the unidentified accurate clock.  If the software doesn't  
know what the accurate clock is, how would it know its accuracy, so  
how could you know that a person won't see a difference, even if the  
display is exactly on the second?


  -- 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/archive%40mail-archive.com

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


Re: NSFileManager and Resource Forks

2010-10-27 Thread Greg Guerin

koko wrote:

NSString *outPath = [nspath stringByAppendingString:@/..namedfork/ 
rsrc];

ok = [fm createFileAtPath:outPath contents:data attributes:nil];



This won't work.  You must first create the file (i.e. create the  
data fork).  Only after the file exists can you open and write to its  
resource fork using the namedfork notation.  This is true even if  
the data fork is intended to be empty, of length zero.


  -- 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/archive%40mail-archive.com

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


Re: NSFileManager and Resource Forks

2010-10-27 Thread Greg Guerin

koko wrote:
although I have implemented a different solution, just to note the  
data fork (the file) does exist, it is nspath in the first line.



I don't see nspath being used to create a data-fork file in any code  
you posted.  It may be in the code you didn't post, or if I've missed  
it, please point it out.


I also realize I wasn't clear.  After the file exists, i.e. after the  
file has been created WITHOUT a namedfork pathname, it's wrong to use  
createFile on the resource fork.  You can, however, open the  
namedfork for writing.  I have done this using C stdio (FILE*) and it  
worked fine.  Obviously, that's not one of the NSFileManager functions.


Finally, the most recent code you posted is leaking the malloc'ed  
buffer holding the resource-fork's bytes.


  -- 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/archive%40mail-archive.com

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


Re: fork/exec vs NSTask

2010-10-24 Thread Greg Guerin

eveningnick wrote::


Basically this is the question about using fork in MacOS. But if there
are other ways to launch a process, i'd appreciate if someone shared
:)



Maybe setup a launchd plist specifying the target executable you want  
to run, then ask launchd to run it by executing  the 'launchctl'  
command in an NSTask.  The plist can be generated dynamically if needed.


One reason for doing this with launchd is it will take care of a lot  
of bookkeeping for you.  There are also a lot of different conditions  
and launch options that can be embedded in a launchd plist.


See 'man launchd.plist', and also TN2083 Daemons and Agents:
  http://developer.apple.com/mac/library/technotes/tn2005/tn2083.html

If your target app has a GUI, it's an agent.  If it has no GUI at  
all, it can be a daemon or an agent.  Read TN2083 for more details; a  
*LOT* more details, including some that affect use of fork/exec.


And since you said you don't have a lot of experience in Mac  
programming, maybe you can explain why you think fork/exec is the  
most appropriate solution.  For example, list your requirements, your  
inter-process communications, etc.  Maybe Distributed Objects is more  
appropriate, but no one would ever suggest it without knowing what  
you're trying to do.


  -- GG


  -- 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/archive%40mail-archive.com

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


Re: NSError help

2010-10-24 Thread Greg Guerin

Dave Carrigan wrote:


This is fine, although the code in the else is useless.



It won't be fine if err is nil.  That's another Cocoa idiom: if the  
NSError** is nil, then no NSError* is returned.


  -- 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/archive%40mail-archive.com

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



Re: NSDictionary allValues not mutable

2010-10-18 Thread Greg Guerin

Trygve Inda wrote:

Or does NSArrayController  somehow bind to a non-array property,  
but one

that responds as if it were an array?



Later in my original post, I suggested subclassing NSMutableArray, so  
it can bind to NSArrayController.  Your new class, i.e. MyDataClass,  
doesn't just respond *as if* it were an array, it *is* an actual  
subclass of NSMutableArray, albeit a specialized one.  The visible  
relationship between MyDataClass and NSMutableArray is *is-a*, not  
*has-a*.


Internally, MyDataClass keeps both an NSMutableArray (to provide the  
array behavior), and an NSMutableDictionary for fast searching.  You  
need to override the minimal methods of any NSMutableArray subclass,  
so it essentially forwards to the internal array.  You also override  
the add/remove methods so objects are added/removed from both the  
internal array and the internal dictionay.  You then override any of  
the find or search methods to use the internal dictionary.  Or you  
can add new methods that perform this fast search, and call those  
when you need fast search as distinct from linear search (a formal  
protocol is optional).


If you have a singleton class whose method you bind to, it could be  
declared as returning NSMutableArray, but it would actually return an  
instance of MyDataClass, i.e. your search-enhanced subclass of  
NSMutableArray.  In other words, you arrange the classes and bindings  
so NSArrayController gets an instance of your specialized data- 
container, instead of an instance of a generic array container.


The singleton whose method you bind to can be another class, or it  
can be an instance of MyDataClass itself.  In the latter case, the  
binded method simply returns self.


  -- 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/archive%40mail-archive.com

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


Re: NSDictionary allValues not mutable

2010-10-18 Thread Greg Guerin

Trygve Inda wrote:

Each dictionary (or object with properties) will need to hold  
roughly 9
textual strings, and there will be on the order of 10,000 objects  
in the
array. I am guessing that dictionary will perform better than a  
predicate

filter given the number of objects.



Never guess at performance.  Always measure.  For one thing, perform  
better may be irrelevant.  Good enough is the only criterion worth  
evaluating.  If worse performance is good enough, then better  
performance serves no purpose (ignoring other tradeoffs, such as  
power consumption).  If array search is 10 msecs, and dictionary  
search is 10 usecs, the user will never perceive the thousand-fold  
difference if the search occurs at most 10 times per sec.


In addition, if the objects are ordered in the array, a binary search  
instead of linear is simpler than managing a parallel dictionary for  
keyed retrieval.  Binary search is O(log2(n)) worst-case.

http://en.wikipedia.org/wiki/Binary_search_algorithm

It almost seems like you're choosing representations and algorithms  
primarily on the existence of classes, instead of what might work  
best.  That is, because predicate filter classes exist, you don't  
have to write that class, so you've decided to use it for searching  
arrays instead of other algorithms that may have substantially better  
performance, but for which you'd have to write non-trivial code (or  
find it on the web).  And the only tradeoffs you're making are  
between varieties of existing Apple-supplied classes, e.g.  
NSDictionary vs. NSArray with predicate-search, rather than looking  
for third-party classes.


  -- 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/archive%40mail-archive.com

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


Re: NSDictionary allValues not mutable

2010-10-18 Thread Greg Guerin

Trygve Inda wrote:

This is probably true since this is a very minor part of my app...  
I simply
need an array to display in a table with the added functionality of  
being
able to locate a record uniquely (each object in the array has a  
unique ID

as one of it's properties).



I recommend doing the simplest thing that could possibly work, then  
measuring performance of that before making any other changes, or  
even thinking about changes.  If simple array searching is fast  
enough, then you've already wasted time by thinking about how to use  
a dictionary, posting on the list, etc.


Furthermore, there are simple additions to linear search of an  
ordered array that can greatly improve speed.  For example, copy the  
search-keys of every 100th element into another ordered array.   
Search it first to decide where to start a linear search in the main  
list, and it's guaranteed you won't have to scan more than 100 main  
elements.  This is effectively a type of tree structure for  
searching, and it can be recursively applied.  Even though it's  
simple, I wouldn't bother coding it unless actual measurements  
indicate a need for it.


  -- 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/archive%40mail-archive.com

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


Re: The dreaded UITableView won't refresh problem.

2010-10-13 Thread Greg Guerin

G S wrote:


Well, this has proven to be a stumper.  In case the XIB was corrupted,
I deleted the whole thing and started over.  Same result.  It's a
deal-breaker, since this is the main interface of my app.  Total
standstill.



I don't recall seeing any of your code that calls reloadData.   
Consider posting that.


The first step for someone else to find the problem is for someone  
else to duplicate the problem.  So do something that makes that  
possible.  For example, make a complete compilable example that  
consistently demonstrates the problem, upload it to a public drop-box  
or pastebin website, and post the URL to the list.


  -- 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/archive%40mail-archive.com

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


Re: NSDictionary allValues not mutable

2010-10-10 Thread Greg Guerin

Trygve Inda wrote:

Ultimately I have a masterDict containing a few thousand dicts (all  
having

the same structure) which I need to convert to an array of dicts to be
displayed in an NSTable.

When I add to this array (quite rarely), I will actually add a new  
dict to
the masterDict and then append this same object to the array  
(managed by an

NSArrayController.

One of the items in each dict is the key that is used to place it  
in the
masterDict so when it is in the array I still know the key that  
refers to it

in the masterDict.

The reason for storing them as dicts in the masterDict instead of  
just an

array is that I really need to be able to find them on a key-by-key
basis The array is only for the ability to put them in an NSTable
w/NSArrayController.



This seems odd to me, but it's difficult to be sure without details  
on what the data is and how it's used.


If the primary organization is of a numbered tabular sequence, as it  
seems to be, then the primary collection should be a numbered tabular  
sequence (NSMutableArray because it's mutable).  Other forms, like B- 
trees, skip-lists, etc. would also be candidates, but those are still  
fundamentally sequences, with a design that improves searching,  
insertion, etc.


Secondarily, it seems you want to be able to search the sequence  
quickly, for which you're using an NSDictionary.  This doesn't  
represent the order of the items, it's only an aid to searching.  If  
the dictionary is only used for speeding up searches, then the  
primary organization is still sequential, and the dictionary is just  
a speed-enhancer.  Again, sorted trees or skip-lists would also speed  
up searches, while presenting a fundamentally sequential nature.


So if the master dictionary and the array for the NSTable are  
encapsulated together in a class, you could use NSMutableArray as the  
primary structure, and encapsulate a hidden NSMutableDictionary used  
only for faster searching.  Both are maintained in parallel by the  
enclosing class, so there's never any need to ask the dictionary for  
its array of values, nor to copy an immutable array to make a mutable  
version for table insertion.  In short, make a class that  
encapsulates all the desired behavior by itself, rather than using a  
naked dictionary and the supplementary arrays it makes.


It's possible that such an encapsulating class could subclass  
NSMutableArray, and maintain an internal dictionary only for fast  
searching.  Then that class could be used directly by  
NSArrayController, while still performing fast searches.


Or maybe the whole thing can be redesigned using NSMutableSet, which  
guarantees uniqueness and is intended for fast searching.  It's  
unordered, so might be unsuitable for use in a table, though it does  
have the ability to produce a sorted array.  See NSSet and NSMutableSet.


  -- 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/archive%40mail-archive.com

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


Re: Making Java Calls from Objective-C !!

2010-10-08 Thread Greg Guerin

Naresh Kongara wrote:

I want to know how to make java calls from Obj-C. (Java Bridge  
Seems to be deprecated).
Is it possible with out bridge ? If yes , Can any body help me on  
Where to start ?



Use JNI.

Also see this Java-Dev message:
http://lists.apple.com/archives/java-dev/2009/Oct/msg00497.html

Google this:
JavaNativeFoundation

And you might get a better answer by asking on Java-Dev:
http://lists.apple.com/mailman/listinfo/java-dev

  -- 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/archive%40mail-archive.com

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


Re: Making Java Calls from Objective-C !!

2010-10-08 Thread Greg Guerin

Nick Zitzmann wrote:

So I found this, which has an answer that is not use the bridge  
but I haven't tried it myself: http://stackoverflow.com/questions/ 
1822549/calling-java-library-from-objective-c-on-mac


One of its answers is use TCP/IP.  I have done that, and it works  
well.  Same-process JVM via JNI's invocation API, or different  
process running /usr/bin/java via NSTask.  For security, confine the  
network to loopback interface (lo0), which is quite easy to do in Java.


I chose JSON as the data format: simple, compact, readily available  
libs for Cocoa and Java.  I also used CocoaAsyncSocket on the  
Objective-C side, which simplified use of sockets and streams.  YMMV.


  -- 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/archive%40mail-archive.com

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


Re: Problem connecting to Oracle with app run from XCode

2010-10-06 Thread Greg Guerin

Timothy Mowlem wrote:

I can run the XCode built app as well from the command line after  
setting LD_LIBRARY_PATH (as a non-admin user and without using sudo).



If that env-var is the cause, then printf() the value of it in both  
cases, and manually compare them.  Use the getenv() C function.


You might also read the Mac OS X man page for 'dyld', if you haven't  
done so yet.

Xcode  Help  Open man Page...

  -- 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/archive%40mail-archive.com

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


Re: Question about architecture

2010-09-09 Thread Greg Guerin

Daniel Lopes wrote:

But what you think about separate custom views in diferent nibs? Is  
that

right?



Try it.  See what happens.  Repeat as needed.

A lot of design questions can only be answered well by experience.   
Either you already have the experience from an earlier project, or  
you plan to get the experience by writing one to throw away.


If you're a newcomer to a language, there is almost no chance that  
you'll do everything right the first time.  You have to try things  
and see what works and what fails. You can read books all day, but  
you will eventually have to try some things that aren't in the book.   
When you do, you will find that every situation has its own unique  
set of constraints, even if they are slight variations on what's in  
the book.  Only the simplest things are exactly the same as what's  
found in books.


All software is exploration.  If someone had already done exactly  
what you want, then you'd be using that existing software instead of  
creating a new thing yourself.


http://en.wikipedia.org/wiki/The_Mythical_Man-Month

  -- 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/archive%40mail-archive.com

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


Re: NSTimer not working in a multithreaded application

2010-09-03 Thread Greg Guerin

Abhijeet Singh wrote:

Hi,I am working on a multithreaded software that runs on a medical  
instrument. The software has 2 parts. GUI and worker threads  
(worker threads sends commands to instrument). The GUI is developed  
using ObjectiveC and Cocoa. Worker threads are all in C and  
Carbon.It is a Cocoa application.I am working on GUI of the  
software.When the application starts it first creates worker  
threads ( that initializes the hardware/instrument). Once the  
threads are created one of the thread sends a message back to main  
thread. My problem isi need to start a timer when the main thread  
receives a message from worker thread. I am starting a timer as  
follows:timer = [[NSTimer scheduledTimerWithTimeInterval:10.0  
target:self selector:@selector(turnOffLight:) userInfo:nil  
repeats:NO] retain];But it does not work. I debugged it and found  
that the timer is created but turnOffLight is never executed.Then  
I created the timer just before worker threads creation and it worked.



You may have been the victim of Cocoa's builtin multithreading locks,  
which are not initialized until multithreaded mode is entered.


See the heading Using Posix Threads in a Cocoa Application, sub- 
heading Protecting the Cocoa Frameworks, in the Thread Management  
section of the Threading Programming Guide.


 --begin-quote--

For multithreaded applications, Cocoa frameworks use locks and other  
forms of internal synchronization to ensure they behave correctly. To  
prevent these locks from degrading performance in the single-threaded  
case, however, Cocoa does not create them until the application  
spawns its first new thread using the NSThread class. If you spawn  
threads using only POSIX thread routines, Cocoa does not receive the  
notifications it needs to know that your application is now  
multithreaded. When that happens, operations involving the Cocoa  
frameworks may destabilize or crash your application.
To let Cocoa know that you intend to use multiple threads, all you  
have to do is spawn a single thread using the NSThread class and let  
that thread immediately exit. Your thread entry point need not do  
anything. Just the act of spawning a thread using NSThread is enough  
to ensure that the locks needed by the Cocoa frameworks are put in  
place.


If you are not sure if Cocoa thinks your application is multithreaded  
or not, you can use the isMultiThreaded method of NSThread to check.


 --end-quote--

http://developer.apple.com/mac/library/documentation/cocoa/conceptual/ 
Multithreading/CreatingThreads/CreatingThreads.html


Since you're mixing Cocoa and Carbon, you should read that entire  
section on Thread Management, and probably the entire Thread  
Management Guide.


  -- 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/archive%40mail-archive.com

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


Re: NSString / NSURL

2010-08-29 Thread Greg Guerin

Amy Heavey wrote:

... I've tried just using strings, but the applicationSupportFolder  
returns a string, which then is immutable so I can't add to it?


There's a significant misconception lurking here.

None of the NSString methods for appending or deleting actually  
modify the NSString they are applied to.  A new NSString instance is  
created that contains a copy of the original's contents plus whatever  
contents is to be appended, or minus the contents to be deleted, or  
with some parts replaced, or whatever the operation is.  The original  
NSString is never modified in any way.


The methods whose name starts with string, as in  
stringByAppendingString, return an NSString object that the caller  
does not own.  See the Memory Management Guide on ownership for the  
consequences (i.e. the uses of retain and release).


Also see the NSString reference doc, and read the descriptions under  
stringByAppendingString and others.  Example:


Returns a new string made by appending a given string to the receiver

The critical words are a new string and made by.

The same is true of NSMutableString, when those same methods are  
applied.  A new NSString is made that contains the altered copy of  
the contents, and that instance is returned.


The only NSMutableString methods that modify the target object are  
the ones listed under Modifying a String in the NSMutableString  
reference doc.  All the methods inherited from NSString are non- 
modifying.


http://developer.apple.com/mac/library/documentation/Cocoa/Reference/ 
Foundation/Classes/NSMutableString_Class/Reference/Reference.html


  -- 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/archive%40mail-archive.com

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


Re: How to assure NSTask termination when parent dies

2010-08-13 Thread Greg Guerin

Process group code:

// launch the task
[task launch];

pid_t group = setsid();
if (group == -1) {
NSLog(@setsid() == -1);
   group = getpgrp();
}
if (setpgid([task processIdentifier], group) == -1) {
   NSLog(@unable to put task into same group as self:  
errno = %i, errno);

}


The current process-group id is inherited across fork() and execve()  
-  see their respective man pages.  So if you reorder the operations  
so setsid() occurs before [task launch], then the child inherits  
automatically.


This doesn't mean the child can't change its own pgid/sid.  And since  
you mention a shell, it's not unusual for shells to do exactly that.


  -- 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/archive%40mail-archive.com

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


Re: NSCountedSet and NSString values question

2010-08-13 Thread Greg Guerin

Philip Mobley wrote:

My question is basically how does NSCountedSet handle string  
values, are they interpreted by their string values or by their  
object values?  If they are by object, then I need to do more work  
to pull the exact key object from the NSDictionary.



NSCountedSet inherits from NSSet and NSMutableSet, both of which use  
the hash and isEqual: methods of contained objects.  See the  
reference docs for each.


In general, docs for a class do not repeat descriptions from a  
superclass, unless there is a difference.  So to fully understand  
what any class does, you must often read the superclass's docs as  
well as the docs of the class you wish to use.


  -- 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/archive%40mail-archive.com

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


Re: NSCountedSet and NSString values question

2010-08-13 Thread Greg Guerin

Philip Mobley wrote:

The author of the article is somewhat unsure whether using - 
isEqual: is safe, but after looking at the [NSString hash]  
documentation I feel confident in my current implementation.


That author is confused, and should consult some reference  
documentation.  It's really quite simple.  In the words of the  
NSObject protocol reference doc, This method defines what it means  
for instances to be equal.  Any concerns over the details of the  
implementation, or reliance upon those details, runs counter to the  
principles of object-oriented programming and encapsulation.



Short answer... yes.  NSSet and subclasses *effectively* compares  
the value of the NSString and not the object address.



Cocoa Fundamentals Guide,
  Cocoa Objects section,
  Introspection sub-section,
  Object Comparison heading.

http://developer.apple.com/mac/library/documentation/Cocoa/Conceptual/ 
CocoaFundamentals/CocoaObjects/CocoaObjects.html


It might be useful to read the whole guide if it's new to you, or  
read it again if you've read it before.  I often find that rereading  
fundamentals gives new insights.


Also see the Discussion under NSString isEqualToString:

“Literal” when applied to string comparison means that various  
Unicode decomposition rules are not applied and Unicode characters  
are individually compared. So, for instance, “Ö” represented as the  
composed character sequence “O” and umlaut would not compare equal to  
“Ö” represented as one Unicode character.

  -- 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/archive%40mail-archive.com

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


Re: [iPhone] Data protection clarification needed.

2010-08-02 Thread Greg Guerin

Sandro Noël wrote:

There is no need for that data to be backed up anywhere, as it is  
retrievable from the web service.
the cached data is used for offline operations and later synced  
back to the web service.


We want to control when the data becomes available in an  
unencrypted format.
and that would be when our application is the active application,  
otherwise in the background or

terminated, the data is encrypted and inaccessible.



Then you need encryption and key management.  When your application  
becomes inactive, the protected data must become inaccessible.  That  
means you must securely delete the decryption key.  When your  
application becomes active, you must securely obtain a decryption  
key, which allows access to the protected data.  There are different  
ways of doing those things.  If you don't have good key management,  
it won't matter how well the data is encrypted, because an easily  
accessible key is the weakest point.


You might get better or more specific advice on the CDSA list:
http://lists.apple.com/mailman/listinfo/apple-cdsa

CDSA = Common Data Security Architecture

  -- 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/archive%40mail-archive.com

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


Re: NSInteger compare - Help Needed

2010-07-17 Thread Greg Guerin

Steve Wetzel wrote:

if ([sender tag]  10) {



The  operator is LEFT-SHIFT.

The  operator is LESS-THAN.

If you want to understand what your code is doing, think about what  
happens when the numbers 0-9 are left-shifted by 10 bits.


  -- 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/archive%40mail-archive.com

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


Re: NSStream Questions

2010-07-16 Thread Greg Guerin

Jon Loeliger wrote:


I'm writing a network server that needs to accept many
simultaneous client connections and keep track of them.
I've written the base server parts, roughly in the style
of the Apple Examples (SimpleNetworkStreamsExample).  These
examples, however, only allow one connected client.  I need
to manage several full duplex NSStream in/out pairs.



CocoaAsyncSocket is a nice building block.

http://code.google.com/p/cocoaasyncsocket/

  -- 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/archive%40mail-archive.com

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


Re: NSStream Questions

2010-07-16 Thread Greg Guerin

John MacMullin wrote:

Create a dictionary with the stream as the key, access and maintain  
the dictionary and stream stuff with the key, (NSValue key), lock  
or synchronize access to the dictionary.  Applies to every pass  
through handleEvent (and everywhere else), ie., any broadcast code.



Exercise caution.  The default behavior for NSMutableDictionary's  
setObject:forKey: is to copy the key.  If the stream is the key, this  
can lead to problems.


  -- 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/archive%40mail-archive.com

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


Re: Reading in UTF-8 to Data

2010-07-15 Thread Greg Guerin

Brad Stone wrote:

Yes, quoted-printable.  That's precisely it but in doing my  
research in the documentation and on the internet it doesn't seem  
like it's a simple process especially for someone like me with 9  
months of Cocoa development experience.



There is nothing apparent in your code that would cause quoted- 
printable to magically appear.  If it's not your code, the next most  
obvious candidate is your data.


Exactly where is your data coming from, and exactly how did it get  
there?  Maybe you have a glitch somewhere along your data-production  
pathway, that's unexpectedly producing quoted-printable.


That pathway includes all uploads, file-transfers, file copies, etc.   
It even includes any editor you used the last time you looked at the  
original XML file.  If the editor is helping you by interpreting  
quoted-printable, then you might want to try something simpler, like  
the 'cat' command in Terminal.app, or even the 'hexdump -C' command.   
If you're not a Terminal person, HexFiend is your friend (google it).


  -- 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/archive%40mail-archive.com

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


Re: Live updating user defaults from a prefpane to a running app

2010-07-14 Thread Greg Guerin

Shamyl Zakariya wrote:

So first off, is there some built-in way to simply 'goose' the app  
and cause its defaults bindings to trigger?



There are any number of ways.  You could send a signal with the  
standard C function kill().  You could send a distributed  
notification (see NSDistributedNotificationCenter).  You could send a  
UDP packet, or a multicast packet.  The list goes on: pipes, file- 
system, shared memory, apple-events, etc.


Each way of sending has a corresponding way of receiving: sigaction 
(), NSDistributedNotificationCenter handler, packet listener, etc.



If not, what's the best practice here? And if I were to use some  
sort of apple event fired from the prefpane or some other technique  
to let the app know its defaults have changed, how do I get the  
user defaults controller in the headless app to apply the updates?



If I understand the question correctly, then when the signal is  
received, your headless app calls -synchronize on the  
NSUserDefaults.  This assumes you don't have any shared-access  
contention issues.

___

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

Please do not post 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: Pass-by value… warning

2010-07-07 Thread Greg Guerin

vincent habchi wrote:

The analyzer does not figure out that the pt array gets initialized  
through the loop by copying values directly from a chunk of memory,  
and spits out the warning about pt [•] not being defined. Maybe I  
should report this to the LLVM team?



That seems like a good idea.

However, also consider that 'dim' may take on values 0 or 1.  If dim  
is 0 or 1, then the local 'pt' array may not have valid elements at pt 
[0] or pt[1].  You may know that dim is never 0 or 1, but the  
analyzer has no way of knowing that.


And I don't know what might happen if dim is negative.

  -- 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/archive%40mail-archive.com

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


Re: Pass-by value… warning

2010-07-07 Thread Greg Guerin

vincent habchi wrote:

That's true, the compiler cannot guarantee that dim  1, which is  
always the case actually.
I am going to put an extra text at the beginning of the method,  
like: if (dim  1) return; and see what happens.



If you need to guarantee dim  1, then your if statement should be:
 if (dim = 1) return

  -- 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/archive%40mail-archive.com

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


Re: How to debug crash on startup of 64-bit build

2010-07-06 Thread Greg Guerin

Jeffrey J. Early wrote:

- The crash does *not* occur when the application (either release  
or debug build) is launched within Xcode.
- The crash *does* occur if I launch the app with gdb from the  
command line (same stack trace).



Inspect and then change things about your executable's runtime  
environment when Xcode launches it.  The most common culprits are  
working directory or environment variables.


You can also try the opposite approach: run from the command-line  
with exactly the same runtime environment.   The 'env' command can  
clear or set env-vars.


Another trick to help find differences: intentionally trigger a SEGV  
signal when running from Xcode.  Compare the full list of libs loaded  
against the full list of libs from the unintentionally crashing app.   
Check the full pathnames of every dylib loaded.


Since the crash is apparently in dyld, maybe the cause is a DYLD_*  
env-var.  There are also some helpful DYLD_* debugging env-vars you  
can try.  See 'man dyld'.


  -- 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/archive%40mail-archive.com

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


Re: Adding secure notes to a keychain programmatically

2010-07-06 Thread Greg Guerin

Brian Marick wrote:

I've not been able to find a way to add a secure note to a keychain  
programmatically. SecItemClass in SecKeyChainItem.h gives no item  
class for secure notes, which makes me wonder if they're not  
actually in the keychain but stored somewhere on disk, encrypted  
with the keychain password (or something). Does anyone know? I  
can't find anything with a web search.



Add a Secure Note to your keychain manually.  It should have a  
distinctive name.  Then use command line:


security dump-keychain login.keychain

and look for your distinctive name.  Also see 'man security'.

  -- 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/archive%40mail-archive.com

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


Re: Run application before Login starts?

2010-07-05 Thread Greg Guerin

kirankumar wrote:


How to run a application before login starts (ie, before when we
enter username and password).



http://developer.apple.com/mac/library/technotes/tn2005/tn2083.html

  -- 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/archive%40mail-archive.com

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



Re: Capturing output from another task with elevated privilages

2010-07-02 Thread Greg Guerin

Eric Hoaglin wrote:


I have the following code:
http://www.pasteit4me.com/763005

I'm trying to capture the output of the task that I run. and from  
what I understand, if you want to do so, you pass a FILE*
to AuthorizationExecuteWithPrivileges and then just read it as a  
normal file (which you can see from lines 29-45



Your code has a serious bug.

if(taskFile != NULL) {
const int BYTES_TO_READ = 64;
char *theCString = malloc(sizeof(char) * BYTES_TO_READ);
int bufferSize = 64;
int bytesRead = 0;
int totalBytes = 0;
	while((bytesRead = fread(theCString, 1, BYTES_TO_READ, taskFile)) !=  
0) {

bufferSize += 64;
theCString = realloc(theCString, bufferSize);
totalBytes += bytesRead;
}
if (taskFile != NULL) { 
NSLog(@Total Bytes Read: %i, totalBytes);
		*tResults = [[NSString alloc] initWithBytesNoCopy:theCString  
length:totalBytes encoding:NSUTF8StringEncoding freeWhenDone:YES];

}

Your fread() is always reading data into the start of the buffer  
'theCString'.  This is wrong.  There should be a separate pointer  
that's advanced by the number of bytes just read.  Or use fread 
(theCString+totalBytes,...).


You also have a stylistic flaw of repeated use of the magic number  
64, despite defining a constant BYTES_TO_READ to represent it.


Another possible problem is you don't test the result returned from  
AEWP().  You go straight into reading the FILE, and only test the  
result later as part of a questionable retry block, not shown  
above. There is a dubious busy loop in the retry, and there may be  
other problems.


Is the fread() bug the cause of the problem you posted about?  I  
don't know.  But it certainly is a significant problem, and it has a  
huge effect on what data gets returned as the output of the task  
string.


You never said what you were actually executing with elevated  
privileges.  If I were you, I'd test your code by running it on /bin/ 
echo or /usr/bin/id.  Both of those executables are well  
characterized and well behaved, and they emit text only on stdout.   
If those fail in the same way, then make a well-isolated fully  
compilable example and post its source.


The first step to solving the problem is to replicate it, but you  
haven't provided enough code to do that.


  -- 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/archive%40mail-archive.com

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


Re: Capturing output from another task with elevated privilages

2010-07-02 Thread Greg Guerin

And you also need to identify what OS version you're running on.

  -- 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/archive%40mail-archive.com

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


Re: Tracking multiple NSURLConnections

2010-06-29 Thread Greg Guerin
If I have lots of connections, say two dozen, or say I'm spawning  
connections continuously, would this be the most efficient way of  
doing this? I'd likely store them in an NSArray and iterate/compare  
until I find the right one. There could be lots of comparisons.



Use NSSet instead of NSArray.  It makes searching and some other  
things faster and simpler.


http://developer.apple.com/mac/library/documentation/Cocoa/Reference/ 
Foundation/Classes/NSSet_Class/Reference/Reference.html



OK, makes sense. But is what I've done so wrong or is it just that  
there are better ways?



It's not really a question of wrong, but one of appropriateness to  
scale.  If you only have one outstanding connection, then you don't  
need to distinguish multiple connections, by definition.  If you do  
need to distinguish multiple connections, then you should use an  
approach that works at that scale.  With a few, simple comparison is  
easy and clear.  Beyond that, it becomes unwieldy.  Beyond multiple  
dozens and into hundreds, you have other problems.


BTW, using a different delegate for each connection can encapsulate  
connection identity.  That is, your delegate object changes depending  
on what the data produced by the connection is intended for.  Each  
connection delivers results to its delegate, which then performs the  
task appropriate for that connection's data.  There is no if  
statement, no array to search, etc. at data-retrieval time.  Each  
paired connection + delegate defines the entire processing path for  
the data.  No repeated lookups or decision-trees are needed.


  -- 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/archive%40mail-archive.com

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


Re: using UTF-32 in NSString.

2010-06-27 Thread Greg Guerin

Georg Seifert wrote:

Does anyone has information on how to use Unicode code points  
higher than 0x.



NSString is UTF-16.  Use surrogate pairs.

  -- 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/archive%40mail-archive.com

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


Re: autorelease: how does this work!? (if at all)

2010-06-18 Thread Greg Guerin

Jens Alfke wrote:

I only saw one error: the method name “GetNSImage” should probably  
be “image” (method names should be lowercase unless they begin with  
a common acronym like “URL” or “TIFF”, and the prefix “get” is not  
used.)



Also See These Methods Three:

 [[frame Camera] ExportFilePrefix], [frame FrameNumber]]

Which May Be Fine In Sharpened C,
Are Ne'er Condoned In Objective-C.

  -- 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/archive%40mail-archive.com

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


Re: FSCopyObjectAsync hogging the thread?

2010-06-10 Thread Greg Guerin

Kevin Boyce wrote:

Sure, it seems like it's just another dispatch from the runloop.  
Which would be fine if it copied like 100K bytes per invocation, or  
something like that. It seems instead to run off and copy vast  
quantities of data before returning. Copying a 4MB MP3 file  
actually completes before the first time anything else in the  
runloop gets any service. I was hoping I had just missed how to  
adjust the time slices it takes.



It may seem crazy, but there is no guarantee that any particular  
FS*Async function performs its operation asynchronously.  The file- 
system operations could proceed entirely synchronously, and the only  
asynchronous part is that you get a callback at the end.


There is certainly no way to specify time slices, or any other kind  
of slice or quantum, for the operation.  If you want that  
granularity, you'll have to provide it yourself.


  -- 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/archive%40mail-archive.com

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


Re: 32bit float array to PNG thanks to NSBitmapImageRep problem

2010-06-08 Thread Greg Guerin

Pierre-Yves Aquilanti wrote:

NSData * binaryData=[NSData dataWithContentsOfFile:binaryPath]; // 
binary is

just a 32bits array full of 1500. and 3000. as described previously



Does the endian-ness of the floats in the file match the endian-ness  
of the processor the code is running on?


Also, in the NSCalibratedWhiteColorSpace, white is 1.0, black is 0.0,  
and grays all lie in the normalized range 0.0 thru 1.0.  So 1500 and  
3000 are whiter than white and will undoubtedly be truncated to  
white (1.0).


It's unclear to me what the white value is in your 1500 and 3000  
values, but if 3000 is white, then you need to divide your raw data  
by 3000 to get it into normalized range.


  -- 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/archive%40mail-archive.com

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


Re: Off Screen bitmap drawing

2010-05-31 Thread Greg Guerin

Development wrote:

What I get is a black rectangle of scrambled colors and no  
discernible resemblance to the page data.

...
void * bitmapData = malloc(byteSize); ag



IIRC, malloc() does not initialize the returned memory.  Since you  
don't seem to do any other initialization, you are effectively  
drawing into a bit-map containing random data.


  -- 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/archive%40mail-archive.com

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


Re: posted notifications are sent twice

2010-05-30 Thread Greg Guerin

Reinhard Segeler wrote:

I post notifications to interchange infos between classes. They are  
always
posted twice, even though they are surely only posted once. Does  
anybody

know why?



Make sure you haven't registered two listeners, or a single listener  
twice.


  -- 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/archive%40mail-archive.com

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


Re: Stealing settings from Mail.app

2010-05-28 Thread Greg Guerin

Chris Idou wrote:

I've got an app that needs to send out emails. I'm trying to import  
mail settings from Mail.app. For some reason my keychain has  
passwords for smtp.gmail.com, but not for smtp.me.com.



AFAIK, there is only the one MobileMe password for all uses.

Double-click your MobileMe password in Keychain Access.app and look  
at its Access Control tab.  Note that Mail.app is always granted  
access by default.


  -- 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/archive%40mail-archive.com

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


Re: subclass overwriting superclass ivar

2010-05-26 Thread Greg Guerin

Jonathan Mitchell wrote:


MGSScriptExecutorManager *scriptExecutorManager;
NSString *tempFilePath;
}

@interface MGS_B : MGS_A {
@private
NSData *stderrData;
}



Change the ivars to something like this:

MGSScriptExecutorManager *scriptExecutorManager;
NSString *tempFilePath;
NSString *watchMe;  // should be nil at all times
}

@interface MGS_B : MGS_A {
@private
NSData *stderrData;
}

Then set a watchpoint on watchMe.

You can also sprinkle in assertions that watchMe is always nil.

  -- 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/archive%40mail-archive.com

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


Re: Getting TextEdit to Recognise UTF-8 Output

2010-05-21 Thread Greg Guerin

K.Darcy Otto wrote:

Question: Is there any header I can put at the beginning of the  
text file to get it automatically recognised as UTF-8?



It's not a header, but there is the com.apple.TextEncoding xattribute.

See post #4 in the following thread:
http://forums.macrumors.com/showthread.php?t=839674

  -- 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/archive%40mail-archive.com

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


Re: singleton design pattern

2010-05-19 Thread Greg Guerin

Abhinay Kartik Reddyreddy wrote:

everytime you ask for a uniqueInstance it looks like it retrieves a  
new instance not the existing instance... since you set the  
uniqueinstance to nil inside that function, your function will  
discard the previous instance if any and then create a new  
instance. Singleton is supposed to return existing instance if any  
and if none create one.


Also i guess the scope of your static is local.

correct me if i am wrong.



Your assertion that a new instance is created every time is wrong.   
It would be right if the storage class were anything but static.  But  
it is static.  So a new instance is created only once, barring any  
thread-unsafe artifacts.


By the way, this is true for plain ordinary standard C.  Objective-C  
does not change it.


  -- 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/archive%40mail-archive.com

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


Re: NSTask and piped commands

2010-05-18 Thread Greg Guerin

appledev wrote:

arguments = [NSArray arrayWithObjects: @-c, @/bin/df -k| / 
usr/bin/grep /dev/ | /usr/bin/awk '{print $1 $4 $5 $6;}',nil];



Your awk syntax is somewhere between quirky and wrong.  Since you  
didn't mention what the problem was, I will assume the output you  
want is not the output you're getting.


I will also assume that you ARE getting some output, despite Alastair  
Houghton previously noted comment that waiting for termination before  
reading stdout can be unsafe.  Unless you have a whole lot of mounted  
disks, the pipe buffer won't fill up and cause deadlock (it's about  
16 KB, empirically determined, in all Mac OS X versions I've tested,  
since 10.0).


Here are the awk problems...

String concatenation in awk is indicated by whitespace.  So this:
print $1 $4 $5 $6

concatenates the strings together, then prints them as a single  
value, followed by the output record separator (newline by default).


If you want the default output field separator, you need this awk line:
print $1, $4, $5, $6

The default output field separator is defined by the awk variable  
named OFS.  To use tab as OFS:

 { OFS=\t; print $1, $4, $5, $6;}

You can discover all this simply by reading awk's man page.

The resulting bash command-line is:
/bin/df -k| /usr/bin/grep /dev/ | \
  /usr/bin/awk '{ OFS=\t; print $1, $4, $5, $6;}'

I have inserted a \ to force a continuation line, so mail doesn't  
line-fold badly.


To encode that properly as an Objective-C string literal, you need to  
escape both the double-quotes and the backslash:

arguments = [NSArray arrayWithObjects:
  @-c,
  @/bin/df -k| /usr/bin/grep /dev/ | /usr/bin/awk '{ OFS=\\\t\;  
print $1, $4, $5, $6;}',

  nil];

(The Objective-C was written in mail and not compiled.  The command- 
line with the modified awk code was tested in bash.)


And I should note that awk is perfectly capable of matching the / 
dev/ pattern by itself with no assistance from grep.  This is left  
as an exercise for the interested reader.


  -- 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/archive%40mail-archive.com

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


Re: AsyncUdpSocket: Receiving duplicate UDP Packet

2010-05-14 Thread Greg Guerin

Todd Burch wrote:

 [aSyncSocket receiveWithTimeout:-1 tag:1];  //Listen for the  
next UDP packet to arrive...which will call this method again in turn.


Don't start another receive.

Handle or ignore the packet, then always return NO from the delegate  
method.  The single outstanding receive will continue receiving  
packets and passing them to the delegate.  Don't return YES until you  
want it to stop receiving callbacks.  It seems wacky but it worked  
for me.


And I used a large timeout (1.0e9), not a negative one.

  -- 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/archive%40mail-archive.com

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


Re: Client/Server Design

2010-05-05 Thread Greg Guerin

Phillip Mills wrote:

I've read the notorious Technical Note TN2152, iPhone OS does not  
currently provide a direct way for third party developers to  
transfer data between the user's computer and their device, but I  
assume common workarounds are in place.  Obviously I could follow  
the note's suggestions about rolling my own from lower level  
functions (or GameKit?), however I thought I should ask whether  
there are strategies and libraries that other people have found  
useful for solving similar problems.



Cocoa AsyncSocket
http://code.google.com/p/cocoaasyncsocket/

BLIP Protocol
http://groups.google.com/group/blip-protocol

  -- 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/archive%40mail-archive.com

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


Re: NSCalendar date calculation anomaly

2010-04-28 Thread Greg Guerin

Scott Ribe wrote:

 NSDate * cd = [[NSCalendar currentCalendar]  
dateByAddingComponents: dc toDate: [NSDate dateWithString:  
@2001-01-01] options: 0];


I think the dateWithString: is wrong.  From the NSDate reference:

You must specify all fields of the format string, including the time  
zone offset, which must have a plus or minus sign prefix.


Refactored code fragments:

NSDate * refDate1 = [NSDate dateWithString: @2001-01-01];
NSDate * refDate2 = [NSDate dateWithString: @2001-01-01 00:00:00  
+];


NSLog( @refDate1: %@, refDate1 );
NSLog( @refDate2: %@, refDate2 );

...
NSDate * cd = [[NSCalendar currentCalendar] dateByAddingComponents: dc
  toDate: refDate1 options: 0];  // should be same as original

...
NSDate * cd = [[NSCalendar currentCalendar] dateByAddingComponents: dc
  toDate: refDate2 options: 0];

  -- 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/archive%40mail-archive.com

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


Re: NSCalendar date calculation anomaly

2010-04-28 Thread Greg Guerin

A couple suggestions:

If you always calculate using noon on any given date, rather than  
midnight, then DST transitions won't affect the year/month/day  
components.


If you don't want to use noon, then NSTimeZone  
daylightSavingTimeOffsetForDate: should be taken into account.


  -- 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/archive%40mail-archive.com

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


Re: menu madness with retain count

2010-04-27 Thread Greg Guerin

Bill Appleton wrote:

3) when i set the menus i have created for NSApp using setMainMenu  
then...
what? who owns them? how do i set more menus for NSApp? how do i  
get NSApp

to release the current set?



You are not responsible for NSApplication's retention or release of  
menus.  It alone is responsible for that.


You set more menus for NSApplication by calling its setMainMenu:  
method with a different set of menus.  That's all you need to know,  
and all you need to do.  What happens in NSApplication as a result of  
calling setMainMenu: is not your responsibility.


To get the current main menu, call NSApplication's mainMenu method.   
You could use this to get the current main menu, which you will not  
own unless you retain.


  -- 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/archive%40mail-archive.com

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


Re: CharacterSet: CharSet(A) - CharSetUnicode = remainder ?

2010-04-24 Thread Greg Guerin

Filip van der Meeren wrote:
 What I was trying to do is the following:

 C/C++ operator| NSCharacterSet operation
  
 
-
 |  (or)  | [aCharSet  
formUnionWithCharacterSet:bCharSet];
  (and)   | [aCharSet  
formIntersectionWithCharacterSet:bCharSet];

 ^ (xor)| ?

There are several equivalents for XOR built from AND, OR, NOT.

http://en.wikipedia.org/wiki/Exclusive_or

If you want one that takes least memory or least time, create tests  
and measure, rather than assume.


  -- 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/archive%40mail-archive.com

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


Re: NSNumberFormatter not working for me ?

2010-04-14 Thread Greg Guerin

Bill Hernandez wrote:

I've worked with lots of number formatters over the years, and that  
is what they do, format numbers into strings, any kind of string...


I looked at the header file for NSNumberFormatter, and there seem  
to be 9,000,000+ methods, it is amazing. Buried in there, there has  
to be a simple way to format a string, that I am overlooking ?


If you look the simple formatter I wrote up last night, it will  
format a string digits any way imaginable.


Your code formats strings (more specifically, characters in  
strings).  It does not format numbers, as such.


By number I mean a binary numeric value (floating-point or  
integer), or possibly NSNumber or NSDecimalNumber.


All your number parameters are actually of the NSString* type, not  
of a numeric type.  The fact that the string contains digits is  
incidental.  In a sense, converting a numeric value to NSString* is  
already a formatting operation, or at least a conversion operation.


Your code would work just as well if you passed it an alphabetic  
string, or one containing punctuation marks.


strippedNumber = @SueMeTomorrow
format = @Social Security : ###-##-###
result = @Social Security : Sue-Me-Tom

I'm not saying the digit-string isn't relevant to what you're doing,  
only that what you seem to think of as a number is, in fact, a string  
that happens to contain a series of digit characters.  I think that  
was a point an earlier reply was trying to make: NSNumberFormatter is  
for numeric values (NSNumber, in particular), not string values that  
happen to contain digits.


  -- 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/archive%40mail-archive.com

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


Re: NSPipe (NSFileHandle) writedata limit?

2010-04-12 Thread Greg Guerin

McLaughlin, Michael P wrote:

Is there a recommended (better) way of sending and receiving a  
known (large)
amount of data to and from a subtask?  Is there any sample code  
anywhere
similar to what I need?  I couldn't find anything close enough to  
work.


Reading your description, my first thought was sockets.  And more  
specifically, CocoaAsyncSocket:


http://code.google.com/p/cocoaasyncsocket/

However, you still haven't completely described how your subtasks  
consume input and produce output, and how the parent collects output  
or other results.  So sockets may not work any better.


I am assuming that subtask output or results are written to the  
subtask's stdout stream, which is a pipe back to the parent process.


If all the subtasks read *all* the input data before producing any  
output data, then I don't know why the parent would be blocking in  
pipe-writing.  The only reasons that come to mind are bugs:  
misinterpretation of protocol bytes, reading the wrong sizes, etc.


If the subtasks read *some* input, then produce *any* output on  
stdout, then that is an opportunity for deadlock, as I previously  
described.  Here's how deadlock happens: after reading some but not  
all input, the subtask writes to its stdout.  This is a pipe back to  
its parent.  The parent is NOT reading its end of the pipe.  When the  
pipe fills up (16 KB), the subtask is then blocked in its writing to  
stdout.  Since it's blocked, it no longer reads its stdin (another  
pipe to parent).  So if parent continues to write bytes to its end of  
the pipe, and does not read from the subtask's output pipe, then the  
parent will eventually block when writing to the pipe that is the  
subtask's stdin.  The parent is now waiting for the child to read its  
input, freeing up space in the pipe, and the child is waiting for the  
parent to read its input, and neither one can proceed until the other  
does.  Classic deadlock.


The fundamental design is send all data before looking for any  
results.  This is inherently synchronous, even though two or more  
processes are involved.  If the subtask is designed to read all data  
before producting any results, then it shouldn't deadlock.  However,  
if the subtask is designed to read some data, produce some results,  
then it is prone to deadlock.


Note that sockets WILL NOT prevent deadlock in this situation.  If  
the requester (the parent) sends enough data to the responder (the  
subtask), but does not read pending responses, then TCP/IP will  
eventually block, just as surely as pipes do.  The size may be larger  
than with pipes, but it can still happen.  Neither pipes nor sockets  
are infinitely buffered streams.  If you treat them as such in your  
software design, then that is a grave error.


I can't tell if this is the cause of the blocking or not, because you  
haven't described how the subtasks produce output.  You also haven't  
described how the parent reads the output from the subtasks.


If the reading is fully asynchronous and infinitely buffered, then it  
shouldn't deadlock.  However, if it's synchronous or has a finite  
buffer length, then it will deadlock under some conditions.  The  
exact conditions depend on the length of the buffers and the amounts  
of data produced for a given input.  Each pipe will hold 16 KB before  
it blocks on write.  Two pipes, so that account for 32 KB.  The other  
32 KB could be in-memory buffering in any of the processes.


If nothing else works, then I think you need to make a well-isolated  
test case that exhibits the problem.  The subtask can be something  
simple, like the 'wc' (word-count) command-line tool.  It reads all  
input before producing any output, so it should never exhibit  
deadlock even if your parent doesn't read any responses until all  
data is sent.


  -- 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/archive%40mail-archive.com

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


Re: NSPipe (NSFileHandle) writedata limit?

2010-04-12 Thread Greg Guerin

McLaughlin, Michael P. wrote:


main -- subtask (main send data)

-(void)sendData:(void*)data numBytes:(NSUInteger)sz taskTag: 
(NSString*)tag

{
   NSData *dataset = [NSData dataWithBytes:data length:sz];
   NSNumber *num = [NSNumber numberWithUnsignedInteger:sz]; //  
NSUInteger
   NSDictionary *dict = [NSDictionary dictionaryWithObjectsAndKeys:  
num,

@size, nil];
   [sendEnd writeData:dataset];// Do NOT close the fileHandle!
   [[NSDistributedNotificationCenter defaultCenter]  
postNotificationName:tag

object:myID userInfo:dict];
}

That is, main
1) sends (via FileHandle and pipe) a known quantity of data to the  
subtask

and
2) tells it what sort of data are coming and how much.



All that stuff I just wrote?  Uh, never mind.

There's your deadlock right there.

You must send the notification with size and such BEFORE writing to  
the pipe.  Otherwise the sender can become blocked, because the  
receiver doesn't know it should be reading anything.


If you'd been sending the size over the pipe, it would have been  
obvious.  You have to tell the receiver how many bytes follow.


  -- 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/archive%40mail-archive.com

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


  1   2   3   4   >