Re: Delayed -dealloc occurs on worker thread if object is working. How?

2010-06-02 Thread BJ Homer
detachNewThreadSelector:target:withObject: retains both the target and the
object.

-BJ

On Wed, Jun 2, 2010 at 11:39 AM, Jerry Krinock je...@ieee.org wrote:

 I allocate an object Foo on the main thread.  Then I spin off a secondary
 thread and give it a long task to do there, but immediately release the
 object, on the main thread.  I expect that the -release invoke -dealloc
 immediately, on the main thread.  To my amazement, the object is not
 deallocced until the task is finished, and to my further amazement, the
 dealloc method runs on the secondary thread.

 Someone please enlighten me.  This is Mac OS 10.6.3, Objective-C garbage
 collection = unsupported.

 Jerry Krinock


 #import Cocoa/Cocoa.h

 @interface Foo : NSObject {
 }
 @end

 @implementation Foo

 - (void)sleep5 {
NSLog(@Sleeping for 5 on secondary thread) ;
sleep(5) ;
 }


 - (void)dealloc {
[super dealloc] ;
NSLog(@Did dealloc a Foo) ;
 }

 @end


 int main(int argc, char *argv[]) {
NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init] ;

Foo* foo = [[Foo alloc] init] ;
[NSThread detachNewThreadSelector:@selector(sleep5)
 toTarget:foo
   withObject:nil] ;
[foo release] ;

sleep(10) ;

NSLog(@Terminating) ;
[pool release] ;
return 0 ;
 }

 RESULT:

 10:23:00.879 LittleTool[83071:1103] Sleeping for 5 on secondary thread
 10:23:05.884 LittleTool[83071:1103] Will dealloc a Foo
 10:23:05.885 LittleTool[83071:1103] Did dealloc a Foo
 10:23:10.879 LittleTool[83071:80f] Terminating

 ___

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

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

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

 This email sent to bjho...@gmail.com

___

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

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

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

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


Notification of unmount events

2010-05-13 Thread BJ Homer
I'm trying to detect disk mount/unmount notifications from a Foundation
tool. Previous questions to this list (e.g.
http://lists.apple.com/archives/cocoa-dev/2007/Jan/msg01170.html) on this
topic have suggested the DiskArbitration framework, which I am using.

The DiskArbitration framework has a number of callbacks. However, none seems
to do what I'm wanting to do.

DiskAppeared callback:
- Called when a volume is attached, even if not mounted. That is, if I have
2 partitions on an external drive but only 1 mounted, I will still hear
about both.

DiskDisappeared callback:
- Called when a volume is physically gone, not just unmounted. If I unmount
one volume on my external drive and leave the other mounted, I won't hear
about the unmount through this callback.

DiskDescriptionChanged callback:
- I can register for changes on the DAVolumePath key, and this works if the
volume is a physical external drive. If it's a network drive, though, then
the description never *changes*; it begins life with the DAVolumePath key
correctly populated. Between DiskAppeared, DiskDisappeared and
DiskDescription I can usually be notified of all disk mount events, but I
get some duplication, and in general it feels very hacked together.

DiskMountApproval callback:
- Notifies me that someone *wants* to mount the volume, but does not
guarantee that the disk was actually mounted.

DiskUnmountApproval callback:
- Notifies me that someone *wants* to unmount the volume, but does not
guarantee that the volume was actually unmounted. In one case I'm working on
right now, I'll have an external drive attached. On reboot, I register for
the mountApproval and unmountApproval callbacks. The volume is mounted and
then I immediately get an unmountApproval callback. If I treat this callback
as a sign that the drive actually *was* unmounted, then I would assume that
the volume is being mounted and immediately unmounted (within milliseconds)
upon startup. That is clearly not the case, since the volume is still
attached when I get up into my login session. This is in a LaunchDaemon, and
the code has been running the whole time without any further
DiskArbitrationCallbacks.


Previous answers (including the one I linked to) have suggested looking at
the code of the disktool utility. It correctly handles situations like this.
It appears, though, that it is using additional information. disktool.c
includes 
DiskArbitrationPrivate.hhttp://www.opensource.apple.com/source/DiskArbitration/DiskArbitration-183/DiskArbitration/DiskArbitrationPrivate.h,
and calls functions defined there including
DiskArbRegisterCallback_UnmountPreNotification
and DiskArbRegisterCallback_UnmountPostNotification. That PostNotification
part looks like what I need in the case of unmounting. Unfortunately, it's
in a private header. I could, of course, copy that header into my project,
but I would have no guarantee that the API would be stable between Leopard
and Snow Leopard, for example. And even though the header is open source and
publicly available, I think it still falls into the category of a private
API, and thus I'd rather avoid that.

The context of all this, since I'm sure someone will ask, is a backup daemon
(a LaunchDaemon) which is keeping track of what files are dirty; when a
volume is mounted, I need to check to see whether any files on that volume
match my rules of what to back up. When a volume is unmounted, I need to
update some internal state to stop tracking those files.

So, my question: is there a better way to be notified of disk mount/unmount
events?

If there's a better list for such questions, please feel free to direct me
there. I searched on lists.apple.com, and everything relating to
DiskArbitration was showing up on Cocoa-dev.

Thanks,

-BJ Homer
___

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

Please do not post admin requests or moderator comments to the list.
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: User-space threads and NSAutoreleasePool

2010-03-18 Thread BJ Homer
On Wed, Mar 17, 2010 at 11:47 PM, Greg Guerin glgue...@amug.org wrote:

 Two main questions come to mind:

 Q1. What are you trying to accomplish?
 Q2. Why do you think this would work?

 More on Q1:  You said you need user-space threads, but you gave no reason
 or rationale.  If it's because you need 500 threads, then why do you need
 500 threads?  Exactly what are you trying to accomplish?


Q1: What am I trying to accomplish?

In this particular case, I'm working on an application that sends very large
HTTP PUT requests over an HTTP connection in a pipelined fashion. For
performance reasons, the server prefers to delay acknowledgement of these
files until it can process them in large groups. (Before it can send an ack,
it must update a database. Doing 400-500 single updates is far slower than
doing one transaction updating 400-500 records.) Hence, we pipeline the HTTP
requests, starting transfer of the second before the first one is finished.
There are a large number of servers that don't handle pipelining, but we'll
only we talking to one particular server, and we know it does.
 NSURLConnection does not (according to various mailing list messages)
implement pipelining, allegedly due to the lack of server support. There's
some suggestion that CFHTTPStream does support pipelining, but there's
little to no documentation about it, and I don't know if it will handle 500
at once.

If you can use user-space threads, this becomes simple; you send the first
file, and then when you're waiting for the ACK, you swap out and let another
file start sending. When the ack is received, the first user-thread is
rescheduled. We've developed an extremely high-performance cross-platform
library that handles all the scheduling directly. Then we've built another
library around that that handles all the particulars of our server protocol.

At the moment, I'm converting our OS X client to use this library. That's my
immediate motivation; if I can use an existing library, I'll save a large
amount of time, get a big performance boost, and have less code to test. To
a large extent, it is already working.


 More on Q2: The ucontext(3) functions appear to me to be more intended for
 signal-handling, specifically for alt-signal-stack handling.  The nature of
 signals is that they eventually return (nested), they don't work in a
 round-robin or any other scheduling.  That's not a question, just prep.  The
 question is this: Are you sure the Objective-C runtime is compatible with
 ucontext user-threads?  There are lots of things you can't do in
 signal-handlers, not even handlers written in plain C (ref: man sigaction,
 the list of safe functions).  If you can't call malloc() in a signal-handler
 (and I'm pretty sure you can't), what do you expect to happen with your
 Objective-C user-threads, since object allocation is tied to malloc()?


Q2: Why do I think this would work? Am I sure the Obj-C runtime is
compatible with ucontext user-threads?

No. There is, in general, relatively little information on use of ucontext
user-threads on OS X. Mostly, it exists in man pages. So far the only issue
I've run into is the autorelease pool issue mentioned previously, which
isn't (I suspect) actually a runtime issue at all. There may be other
issues, but that's part of the reason I'm asking on the list. I can work
around the autorelease pool issue if I have to (by limiting my use of
Objective-C objects and autorelease pools in such a way that I can guarantee
correctness), but if there are other known issues, I'd love to hear about
them.

It's true that ucontext stuff is often used for signal handling, but that's
not the only use case. My code does not relate to signal handling at all. As
mentioned above, all this ucontext stuff happening in a cross-platform
library. It's already running on Linux, where I suspect the
malloc-in-signal-handlers restrictions equally apply. I've also had it
running (to some extent) as well. In neither Linux nor my initial attempts
on OS X have I seen anything to indicate that object allocation was not
working. In fact, I have a fair amout of evidence that it is likely working
just fine. If object allocation was failing or otherwise unstable, my code
would be crashing all over the place, not just having autorelease pool
issues.

-BJ
___

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

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

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

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


User-space threads and NSAutoreleasePool

2010-03-17 Thread BJ Homer
Hi everyone,

Some setup, first. If you just want to jump to the question, jump to the
last paragraph.

OS X includes (as part of its UNIX heritage) functions for implementing
user-space threading.  (See, for example, the man page on
swapcontexthttp://developer.apple.com/Mac/library/documentation/Darwin/Reference/ManPages/man3/swapcontext.3.html.)
 This allows developers to swap out the current stack for another, in effect
allowing two threads of execution on a single thread. Using kernel-level
threads is, naturally, simpler, but due to the cost of kernel-level context
switches, they don't scale well. (You just can't run 500 threads at once
very well.) User-space threads require more programmer attention, certainly,
but also allow certain programming models that can't be done otherwise. For
example, they can be used for coroutines, cooperative threading, or all
sorts of esoteric-yet-sometimes-useful effects.

I say all that in an effort to avoid the frequent you're fighting the
frameworks responses. I'm well familiar with the frameworks, GCD, etc., and
in this particular case, user-space threads is what I need.

The problem is that when you call swapcontext() to switch the user-thread
running on a kernel-thread, the NSAutoreleasePool stack is not swapped out.
It remains rooted in thread-local storage. As a result, serious problems
result. Let me give an example.

- (void)doStuff {
  NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
  // do some stuff that calls swapcontext()
  [pool drain];
}

-doStuff calls swapcontext(), trusting that the other user-thread will
eventually call swapcontext() and restore the flow to this user-thread.

Further, assume that the second user-thread also allocates an autorelease
pool before returning. Despite being on separate user-threads, there is
still only one kernel-thread. Since the autorelease pool stack is in
(kernel-)thread-local storage, the second user-thread's pool goes on top of
the same stack:

Autorelease pool stack: pool_from_uthread1 - pool_from_uthread2

Now, when we swap back to the first user-thread, it will release its
autorelease pool. This, naturally, releases the second pool as well. When we
swap back to the second user-thread, anything that was autoreleased is now
dead and gone.

Okay, so that's the setup. Obviously, the problem is that the two user-space
threads are sharing an autorelease pool stack that is intended to be
thread-local. My question, then, is whether there exists a way to get and
set the autorelease pool stack, so that before calling swapcontext(), I
could put it in a state appropriate for this user-level thread? I assume it
is being stored in thread-local storage, but it's not in the NSThread
threadDictionary, which means it's probably set using pthread_setspecific.
Accessing that value would require the key used to store it, but naturally I
don't have access to that. So is there some existing function call that
allows such access?

Thanks for listening,

-BJ Homer
___

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

Please do not post admin requests or moderator comments to the list.
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: NSPredicate regex

2010-02-18 Thread BJ Homer
I've found Reggy (http://reggyapp.com/) to be *extremely* useful in
debugging regular expressions.

-BJ
___

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

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

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

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


Re: iPhone: validate a NSString for US zipcode

2010-01-07 Thread BJ Homer
Well, depends on what you mean by ordered. NSArray retains insertion order.
NSSet does not. But NSSet may be sorting things on insertion (like you'd get
with a binary tree structure), while NSArray cannot assume any particular
order. So from the NSArray implementor's standpoint, the array is unordered.

-BJ

On Thu, Jan 7, 2010 at 2:52 PM, Dave DeLong davedel...@me.com wrote:

 That's backwards.  NSArray is ordered; NSSet is not.

 Dave

 On Jan 7, 2010, at 2:44 PM, David Duncan wrote:

  Since NSArray is unordered I would not expect its containsObject to do
 better than O(n). If NSSet is an ordered container, it should be able to do
 O(lg n).

 ___

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

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

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

 This email sent to bjho...@gmail.com

___

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

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

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

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


Question about looping constructs

2010-01-05 Thread BJ Homer
 Branching from the Question about garbage collection thread 

On Sun, Jan 3, 2010 at 11:40 AM, Bill Bumgarner b...@mac.com wrote:


 If you are writing your own looping construct, you can call
 objc_clear_stack(...) to clear the stack at appropriate times, typically
 when the stack is as shallow as possible.   Prior to Snow Leopard, writing
 your own looping construct was relatively rare in Cocoa.  With Snow
 Leopard's addition of Grand Central Dispatch, writing your own looping
 construct is actively discouraged (though, certainly, there are still
 reasons to do so).

 b.bum


I assume that when you say looping construct, you're not referring to
things like for, while, do-while, etc. Could you explain what you're talking
about? I'm guessing you mean run loops on detached threads, and if so, are
you referring to using custom input sources for threads?  I've seen a fair
amount of code that detaches a thread to a method with a while(!done) { //
code here } structure. Is there a better way?
___

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

Please do not post admin requests or moderator comments to the list.
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: Stack-based C++ class to wrap NSAutoreleasePool

2009-11-16 Thread BJ Homer
Does the stack-based idiom allow returning an autoreleased object?  I'd
think you'd end up with code like this:

- (id)arrayWithStuff {
  StackAutoreleasePool();
  NSArray *array = [NSArray arrayWithObjects:obj1, obj2, etc, nil];
  return array;
}

which would essentially translate into:

- (id)arrayWithStuff {
  NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
  NSArray *array = [NSArray arrayWithObjects:obj1, obj2, etc, nil];
  [pool release];
  return array;  // array is dead
}

Is there some reason why this would not happen?

-BJ
___

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

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

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

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


Re: [iPhone] OS 3.0 and @synthesize AND @dynamic for the same property

2009-11-13 Thread BJ Homer
On Thu, Nov 12, 2009 at 2:52 AM, Joerg Simon j_si...@mac.com wrote:

 Dear all other Cocoa Developers:

 In an app I am developing I have the following strange thing:

 [code in the .h file]
 @interface XY : CALayer
BOOL _editing;
 ...
 @property (assign, getter = isEditing) BOOL editing;

 [/code]

 [code in the .m file]
 @synthesize editing = _editing;
 @dynamic editing;


The @dynamic is entirely unnecessary; you should use @synthesize or
@dynamic, but not both.

-BJ
___

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

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

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

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


Re: Multiple variable rules in for() statement

2009-11-12 Thread BJ Homer
I believe this is actually independent of being in a for loop.  Your first
line corresponds to code like this:

int i;
i=0, int m=0;

Which is syntactically incorrect.

Your second example corresponds to this:

int i;
int m=0, i;

Which is an attempt to re-declare i.

So you're correct; you can't have both an old variable and a new variable in
the for loop initialization.

-BJ
___

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

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

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

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


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

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

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

-BJ
___

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

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

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

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


Re: Core Data Disable Undo

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

-BJ
___

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

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

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

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


Re: Core-Data : how to merge two contexts ?

2009-11-07 Thread BJ Homer


 I'll probably end up using the merge... method available but that makes
 me feel bad to save a document automatically when the user should be the
 only one responsible for this. For example, the user will not be able to use
 the Revert command from the File menu to restore his document to its
 original state like it is supposed to work (or I'll probably have to
 subclass the standard behavior by saving a copy of the sqlite file in the
 temp area just in case the user needs to revert).

 Eric.___


I'm not a Core Data expert by any stretch of the imagination, but
NSPersistentDocument does support revert and other such features, so it's
clearly possible.  The NSPersistentDocumentation Class
Referencehttp://developer.apple.com/mac/library/documentation/cocoa/Reference/ApplicationKit/Classes/NSPersistentDocument_Class/Reference/Reference.html
indicates
that the save operation simply adds a new persistent store (if it is not
already saved) to the managed object context and then invokes save:. This
suggests a possible solution:

When the user opens your application, use an in-memory persistent store.
 If they're opening an existing document, use the migrate... method on
NSPersistentStoreCoordinator to migrate the on-disk store to an in-memory
one.  Once you've loaded everything into memory, you can invoke save on
multiple MOCs as much as you like without it being written to disk, since
the on-disk store is no longer attached.

When you actually want to save to disk, simply add an on-disk persistent
store to the MOC.  You'd probably just delete the old on-disk one and then
add a new persistent store at the same URL.  I assume you'd have to call
save on your MOC after doing so.  You could then immediately remove the
on-disk store and continue on with in-memory store.  Alternatively, you
could migrate to an on-disk store and then back to an in-memory store, but I
suspect that would be less efficient.

I've tried precisely none of the above personally.  I'm just throwing ideas
out there.  If the above isn't a feasible way to do this in Core Data, I'd
love to know why.

-BJ Homer
___

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

Please do not post admin requests or moderator comments to the list.
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 allocating memory

2009-10-27 Thread BJ Homer


  NSLog(@%d, myString);


Change this line to:

NSLog(@%p, myString);

that will print the value of the pointer, which you'll see changing.

-BJ
___

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

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

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

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


GC and atomic getters/setters

2009-10-17 Thread BJ Homer
In the Garbage Collection Programming Guide: Architecture [1], an example is
given of a set of non-GC getters and setters which use @synchronized(self)
to control the access to the ivar, and in the setter to protect the
releasing of the old object and retaining of the new.  Then, a GC example is
given in which the getters and setters have no synchronization; the getter
simply returns the value, and the setter simply assigns the new value.
I understand why the setter is so much simpler under GC; no retain/release
fiddling is necessary.  However, I'm confused about the lack of
synchronization in the GC examples.  I know there's lots of skepticism as to
whether synchronization at the getter/setter level is even useful (hence the
general recommendation to make properties nonatomic).  But assuming that you
wanted it there in the first place, why does the GC version not need the
synchronization?  Is it simply because the setter is doing less, and thus
the getter wouldn't ever catch the setter halfway through its setting?
 (After releaseing the old value, but before retaining the new, for
example.)

-BJ

[1]
http://developer.apple.com/mac/library/documentation/Cocoa/Conceptual/GarbageCollection/Articles/gcArchitecture.html#//apple_ref/doc/uid/TP40002451
___

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

Please do not post admin requests or moderator comments to the list.
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: NSWorkspaceDidMountNotification not firing on Snow Leopard

2009-10-08 Thread BJ Homer
On Thu, Oct 8, 2009 at 2:39 AM, Dave Keck davek...@gmail.com wrote:

 Not sure why it's not working, but if it turns out to be a bug with
 NSWorkspace, you might try using the Disk Arbitration framework
 instead. See DARegisterDiskAppearedCallback().


Note that there's a difference between disk appeared and disk mounted.
 Specifically, at the time of the DiskAppeared callback, the drive is NOT
mounted.

-BJ
___

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

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

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

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


Re: Constructive Criticism

2009-10-07 Thread BJ Homer
On Wed, Oct 7, 2009 at 10:53 AM, Derek Chesterfield d...@mac.com wrote:



 On 6 Oct 2009, at 22:48, Alastair Houghton alast...@alastairs-place.net
 wrote:

  Oh, and since I'm in the dot-syntax-is-evil camp, s/self.year/[self
 year]/g in Bill's code :-D :-D


 Just an aside, but does either syntax got optimised by the compiler (GCC or
 LLVM). Obviously it can't in all cases, but this seems an obvious case where
 it could be replaced by an
 assignment.___


If you replace self.something = @value with something = @value,
Key-Value Observing won't work.  So no.

-BJ
___

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

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

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

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


Re: Correct way to tell if a path is to a .bundle?

2009-09-25 Thread BJ Homer
 Rick,

 You could also use:
 NSBundle pluginBundle = [NSBundle bundleWithPath: fullPath];

 This will return an NSBundle object as your require or nil if fullPath does
 not identify an accessible bundle directory. So...
 if ( pluginBundle == nil ) ... then it is not a valid bundle.

 This isn't actually true.  For example, you can create a bundle with the
path to a flat executable, and if that executable happens to have an
Info.plist embedded inside it, you can access the values in the plist as if
it were a full bundle.  Likewise, if you point it at a random folder, you
may still get a valid object back.  I've got some rubycocoa scripts that
take advantage of that very fact.

Sorry.

-BJ
___

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

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

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

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


Re: Stability on Snow Leopard

2009-09-23 Thread BJ Homer
On Wed, Sep 23, 2009 at 6:24 AM, Kirk Kerekes kirkkere...@gmail.com wrote:

 ... If you don't happen to be using any of these, (or any macros that hide
 relevant code, because the analyzer appears to operate only on unexpanded
 code) you should be golden.


The analyzer definitely expands macros.  I've got some legacy code at work
that's got a frequently-used macro that can basically return from the method
at any point, and it's producing ALL sorts of memory leak warnings.
___

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

Please do not post admin requests or moderator comments to the list.
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: Creator Codes in Snow Leopard

2009-09-23 Thread BJ Homer
On Wed, Sep 23, 2009 at 10:32 AM, Todd Heberlein todd_heberl...@mac.comwrote:

 Some may find the following Apple Insider article on the the topic useful:

 Inside Snow Leopard's UTI: Apple fixes the Creator Code

 http://www.appleinsider.com/articles/09/09/22/inside_snow_leopards_uti_apple_fixes_the_creator_code.html


Some may also find it misleading, since it implies that the UTI can be set
on a per-file basis, independent of type code and extension.  This is false.

As a result, most of their conclusions are incorrect as well.  If you can't
set the UTI differently on two files with the same type code and extension,
it can't serve as a creator code.

Incidentally, this is not a complaint against UTIs; they are very useful.
 They're just not meant to solve the creator code problem.

-BJ Homer
___

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

Please do not post admin requests or moderator comments to the list.
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: an app that never quits

2009-09-21 Thread BJ Homer
On Sat, Sep 19, 2009 at 1:07 AM, Erick Calder e...@arix.com wrote:

 I want to write a daemon for the iPhone.  my goal is to record the
 orientation of the phone across time for later analysis.  I am unsure how
 this could be done since it seems only one application gets to run at a time
 i.e. when the user takes a call my program quits.

 can this be done?


Not without jailbreaking; you simply can't write background apps on the
iPhone.  I'm not sure if you could do it on a jailbroken phone, since I've
never played with one.

-BJ
___

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

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

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

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


Re: #pragma to suppress a warning message

2009-09-16 Thread BJ Homer
If you're just wanting to use the method and avoid the warning, add a
category to NSLocale declaring the preferred languages.  Just add the
interface; no implementation is necessary.
You may want to do further investigation; however.  It's possible that the
preferredLanguages method appeared mid-way through the 10.4 lifecycle, so it
may work for some Tiger users and not others.

-BJ

On Wed, Sep 16, 2009 at 7:09 PM, Jay Boyer j...@automaticduck.com wrote:

 I have three related questions.  I’d like to suppress a particular warning
 message in the source file.  In gnu it could be done as follows:

 #pragma Warnings(Off)
   NSArray *languages = [NSLocale preferredLanguages];
 #pragma Warnings(On)

 Is there a way to do this in xcode with #pragma?

 Also, can anyone point me to a list of the #pragma’s for xcode?

 Finally, I am doing this because the preferredLanguages method is specified
 to be an OS 10.5+ method and the project I am working on is being built on
 the 10.4 SDK.  Nonetheless, on the 10.4 machine where I tested this, the
 method works.  Does anybody know what the story is with this method and
 10.4?  Is this method actually supported by 10.4 or is it something that
 happens to be supported if certain other software has been installed on a
 10.4 platform?

 Thanks,

 Jay___

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

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

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

 This email sent to bjho...@gmail.com

___

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

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

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

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


Re: Retaining a NSURL and retaining its -path

2009-09-12 Thread BJ Homer
On Sat, Sep 12, 2009 at 10:43 AM, John Love jote...@charter.net wrote:

 In my controller, one of my instance variables is a NSURL and I retain it
 because I pass it to a 2nd controller.  In my second controller, I extract
 [myURL path] and look at it in a secondary thread loop and everything works
 fine.  I began to think if I could eliminate that call to [myURL path] every
 time through that loop I would save some time.

 My first attempt was to pass that NSURL in the same manner and then place
 the extracted [myURL path] into an instance variable of the 2nd controller.
  Okay so far .. and then I assumed that if myURL was retained in the 1st
 controller, then naturally its NSString -path was also retained .. but it
 crashed with release message sent to a already released object (or
 something like that).  Only when I extracted the -path *and* retained it
 before I stored it as an instance variable of the 2nd controller did it
 work.

 Basic question: if a parent object is retained, why isn't each sibling
 component object of that parent retained??

 It's very possible that the NSURL doesn't actually keep an instance
variable for the path, and instead simply generates it on demand.  It would
probably return it to you autoreleased and then forget all about it, so if
you didn't retain it, you'd be in trouble.

In short, if you care about an object obtained through a non-owning method,
retain it.

-BJ
___

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

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

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

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


Re: Cleaning garbage in Core Data

2009-08-16 Thread BJ Homer
On Sun, Aug 16, 2009 at 10:35 AM, Squ Aire squ...@live.com wrote:


 I am not *explicitly* marking anything as garbage. Whenever a user decides
 to remove a ValidKeys managed object, corresponding key-value pairs in all
 the userInfo dictionaries are *conceptually* marked as garbage. This is
 because I do not want to show the beach ball to the user while things are
 getting cleaned up. I want to postpone the cleaning up until later when it
 will not bother the user.


If the goal is to avoid beachballing the user, you may be able to simply put
the cleanup logic into a background thread and fire it off immediately.
 Beachballs only happen when the main thread is blocked.  Now, if this is
data that is displayed and manipulated in the UI, you may need to do some
synchronization to avoid race conditions.  But in general, avoiding
beachballs is a matter of doing things in the background instead of delaying
it until later; if you wait to clean up garbage, you'll just postpone your
beachball until later.  Now, there may still be merit to batching the
deletions; you could make a background thread that runs cleanup every 1.0
seconds on any object in a deletion queue or something.

I'm not a Core Data expert (yet), but you will need to give the background
thread a separate NSManagedObjectContext.  As you mentioned, you'll need to
notify the main thread's MOC of the changes.  Luckily, in 10.5 there's
-[NSManagedObjectContext
mergeChangesFromContextDidSaveNotification:]http://developer.apple.com/documentation/Cocoa/Reference/CoreDataFramework/Classes/NSManagedObjectContext_Class/NSManagedObjectContext.html#//apple_ref/doc/uid/TP30001182-SW9,
which takes care of that.  Register an observer on
the NSManagedObjectContextDidSaveNotification notification with the
background MOC as the object and the main MOC as the target, and whenever
the background thread performs a save, the main thread's MOC will be
updated.

That's how I'd do it, anyway.

-BJ
___

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

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

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

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


Re: Custom NSArrayController - Dynamic Class?

2009-07-19 Thread BJ Homer



On Jul 18, 2009, at 11:52 PM, BJ Homer bjho...@gmail.com wrote:




On Sat, Jul 18, 2009 at 4:23 PM, Quincey Morris quinceymor...@earthlink.net 
 wrote:

On Jul 18, 2009, at 15:07, Kyle Sluder wrote:

I would instead recommend using -setValue:forKey: like this:

[object setValue:[NSNumber numberWithInteger:[[self arrangedObjects]
indexOfObject:object]] forKey:@index]

Yes, it's more sensible.

But now that I think about it, the performSelector approach has  
one *slight* advantage to the developer. If you ever use Xcode's  
refactoring to change the name of the property, it will miss the  
property name in the string. With @selector, the method name still  
doesn't change, but the refactor window does give a warning that  
it's not going to change automatically.


Perhaps the best option is option (c): create a IndexedObject  
abstract superclass (if there isn't one already) and use  
'object.index = ...' after all.


In order to preserve the contract of NSArrayController (which is  
that you can add any object with addObject:), I'd recommend doing  
something like this:


- (void)addObject:(id)object {
   if ([object respondsToSelector:@selector(setIndex:)] {
  object.index = [NSNumber numberWithInt:[[self arrangedObjects]  
indexOfObject:object]];

   }
   [super addObject:object];
}

Note that I call super's addObject: at the end.  I have no idea what  
the implementation of NSArrayController's addObject: is, but it's  
always better to have things set up before you pass something along  
to super.  Imagine, for example, that NSArrayController writes the  
object immediately to disk when added.  Since you haven't set your  
index yet, it would be incorrect.  (I don't think it actually writes  
anything to disk at that point, but you get the idea.)


-BJ


Actually, use [object setIndex:] instead, and cast it as an  
IndexedObject*. That will get rid of your compiler warnings.


-BJ
___

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

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

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

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


Re: Custom NSArrayController - Dynamic Class?

2009-07-19 Thread BJ Homer

On Jul 19, 2009, at 11:21 AM, Kyle Sluder kyle.slu...@gmail.com wrote:


On Jul 18, 2009, at 11:52 PM, BJ Homer bjho...@gmail.com wrote:

Actually, use [object setIndex:] instead, and cast it as an  
IndexedObject*. That will get rid of your compiler warnings.


-BJ


We're talking about the case in which you don't have a managed  
object subclass, and therefore there is nothing to cast to.


--Kyle Sluder


Oh, right. Cast it to (id) then. Though if it's already passed in as  
an id, that's obviously unnecessary. Point is, calling setIndex:  
instead of object.index= will let it compile w/o warnings, in certain  
situations.


Thanks for the correction.

-BJ
___

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

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

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

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


Re: Where to release in UIView

2009-07-18 Thread BJ Homer
That actually is a valid concern; since you're on the iPhone, memory
constraints are tight, and your view may actually be unloaded at some point.
Instead of doing additional initialization in awakeFromNib, (which has no
counterpart), I'd recommend doing your additional setup in viewDidLoad: on
the associated UIViewController.  Then, in viewDidUnload: you can release
anything you instantiated in viewDidLoad:.  Note that viewDidUnload is only
available in iPhone OS 3.0 and later.

-BJ



On Sat, Jul 18, 2009 at 1:56 PM, DKJ hatzicw...@shaw.ca wrote:

 Thanks to all who replied. I was concerned whether the object might somehow
 get re-instantiated from the nib without dealloc being called first. If I
 understand memory management correctly, that would produce a leak.

 I'm assuming that the object wouldn't be re-instantiated without its
 previous instantiation being released. But I'd sleep better having an expert
 opinion.

 dkj



 On 18-Jul-09, at 7:59 , DKJ wrote:

  I've got a UIView object that uses an NSDictionary. The UIView is
 instantiated from a nib, so I initialise the dictionary in awakeFromNib,
 since the initWithFrame: method is never called. Is it appropriate to
 release this dictionary in the UIView dealloc method?

 dkj
 ___


 ___

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

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

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

 This email sent to bjho...@gmail.com

___

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

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

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

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


Re: Custom NSArrayController - Dynamic Class?

2009-07-18 Thread BJ Homer
On Sat, Jul 18, 2009 at 4:23 PM, Quincey Morris quinceymor...@earthlink.net
 wrote:

 On Jul 18, 2009, at 15:07, Kyle Sluder wrote:

  I would instead recommend using -setValue:forKey: like this:

 [object setValue:[NSNumber numberWithInteger:[[self arrangedObjects]
 indexOfObject:object]] forKey:@index]


 Yes, it's more sensible.

 But now that I think about it, the performSelector approach has one
 *slight* advantage to the developer. If you ever use Xcode's refactoring to
 change the name of the property, it will miss the property name in the
 string. With @selector, the method name still doesn't change, but the
 refactor window does give a warning that it's not going to change
 automatically.

 Perhaps the best option is option (c): create a IndexedObject abstract
 superclass (if there isn't one already) and use 'object.index = ...' after
 all.


In order to preserve the contract of NSArrayController (which is that you
can add *any* object with addObject:), I'd recommend doing something like
this:

- (void)addObject:(id)object {
   if ([object respondsToSelector:@selector(setIndex:)] {
  object.index = [NSNumber numberWithInt:[[self arrangedObjects]
indexOfObject:object]];
   }
   [super addObject:object];
}

Note that I call super's addObject: at the end.  I have no idea what the
implementation of NSArrayController's addObject: is, but it's always better
to have things set up before you pass something along to super.  Imagine,
for example, that NSArrayController writes the object immediately to disk
when added.  Since you haven't set your index yet, it would be incorrect.
 (I don't think it actually writes anything to disk at that point, but you
get the idea.)

-BJ
___

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

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

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

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


Re: Core Data debugging

2009-07-16 Thread BJ Homer


  NSError *err;
 BOOL result = [moc save: err];


Make sure you initialize err:

 NSError *err = nil;


Otherwise, you may be dealing with a bogus error object, since method-scope
variables are not automatically initialized to 0.  (Instance variables are
initialized, btw.)  I don't think that would affect the return value of
save, but it's a good habit either way.

-BJ
___

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

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

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

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


Re: iTunes COM interface for Windows; need the equivalent for iTunes on the Mac

2009-07-16 Thread BJ Homer
Or, if you want something more code-y, try the Scripting Bridge:
http://developer.apple.com/documentation/Cocoa/Conceptual/ScriptingBridgeConcepts/UsingScriptingBridge/UsingScriptingBridge.html#//apple_ref/doc/uid/TP40006104-CH4-DontLinkElementID_11

-BJ

On Thu, Jul 16, 2009 at 3:55 PM, Nick Zitzmann n...@chronosnet.com wrote:


 On Jul 16, 2009, at 3:42 PM, Michael A. Crawford wrote:

  So, is there an SDK for accessing iTunes on the Mac?


 AppleScript?

 Nick Zitzmann
 http://www.chronosnet.com/

 ___

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

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

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

 This email sent to bjho...@gmail.com

___

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

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

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

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


Re: ibtool and genstrings do nothing

2009-07-16 Thread BJ Homer
genstrings does not produce output.  It does, however, produce
Appdel.strings.
-BJ

On Thu, Jul 16, 2009 at 3:51 PM, Development developm...@fornextsoft.comwrote:

 I am trying to use genstrings:
 genstrings AppDelegate.m Appdel.strings
 from the terminal window and I get no errors and no output.

 Likewise when I do
 ibtoo -generate-strings-file MainWindow.nib MainWindow.xib
 I get no error and no output.

 I am in the terminal in the correct directory so I have no idea what I'm
 doing wrong
 ___

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

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

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

 This email sent to bjho...@gmail.com

___

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

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

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

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


Re: {Cocoa semi-related} Unable to de-archive an archive from SQLite.

2009-07-14 Thread BJ Homer
It's not an archive; that's the actual binary executable.  Just rename it to
something more reasonable.
I dealt with this just last week.

-BJ

On Tue, Jul 14, 2009 at 5:06 PM, Frederick C. Lee amourinet...@gmail.comwrote:

 I'm trying to dearcive sqlite3-3.6.16-osx-x86.bin.

 But what I get is: sqlite3-3.6.16-osx-x86.bin.cpgz

 Is there a remedy?


 Ric.
 ___

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

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

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

 This email sent to bjho...@gmail.com

___

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

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

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

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


Re: literal strings - who do they belong to?

2009-07-13 Thread BJ Homer

 But then I saw the case where I have an object which returns, as a method
 result or a property, one of its instance variables. The caller holds on to
 it (without retaining it) then releases (and deallocs) my object.  My object
 releases its instance variables which results in the caller holding a
 reference to a dead value.

 {
  Object *o = [Object new];
  NSString *s = o.somevalue;// gets o's instance variable
 (without retain)
  [o release];  // o's instance variable is released
  NSLog(@Crash: %@,s) // accesses dead string
 }

 So, yes, the retain/autorelease isn't superfluous at all, though the usage
 pattern that would trigger the problem seems relatively unlikely (in my
 example, o seems far more likely to be autorelease'd).  Is there a more
 common case that I'm missing?


If o were in an NSDictionary that was passed to you in a parameter, for
example, and you removed the key from the dictionary, you'd trigger the same
problem.

-BJ
___

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

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

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

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


Re: Why do I receive KVO notification when new value IS the old value?

2009-07-08 Thread BJ Homer
Likewise, what if I had a program that was counting the number of X events
per 10 seconds, and I wanted to add a data point to a list every time it was
updated?  I would definitely want to record the same number twice in a row.
It may not be a common case, but reporting the value enables situations that
filtering it out would not allow.  Besides, it's not a waste of CPU cycles;
if the framework did the equality check for you first, it would be performed
on *every* notification.  This way, you can only perform it on the
notifications where you need it.

-BJ

On Wed, Jul 8, 2009 at 4:17 PM, Greg Guerin glgue...@amug.org wrote:

 Jerry Krinock wrote:

  This happens not only when the new and old values are -isEqual:, but when
 they are identically the same pointer. I can't think of any reason why
 anyone would want notification of a no-op.



 What if the operation isn't a no-op?  What if the operation represented
 some kind of accumulation instead of replacement, or an incremental change
 instead of assignment?

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

 This email sent to bjho...@gmail.com

___

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

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

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

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


Re: AsyncSocket. Troubles with MTMessageBroker didReceiveData

2009-07-07 Thread BJ Homer
Neither AsyncSocket nor MTMessageBroker are part of Cocoa, and thus you're
very unlikely to find help on a Cocoa developer's list.  They're both
third-party classes.  My best recommendation is that you try Google.  The
first result for searching *AsyncSocket MTMessageBroker* is
thishttp://www.macresearch.org/cocoa-scientists-part-xxix-message,
which seems to have an example that may help you.
One other thought: if your delegate methods aren't being called, have you
actually called [socket setDelegate:self]?

-BJ

On Tue, Jul 7, 2009 at 2:24 AM, Carlo Gulliani carlogulli...@yahoo.comwrote:

 Nobody knows?



 ___

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

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

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

 This email sent to bjho...@gmail.com

___

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

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

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

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


Re: MDSchemaCopyAllAttributes() returning nil

2009-06-18 Thread BJ Homer


 In this particular instance, don't forget that Spotlight importers can
 live in ~/Library/Spotlight as well as within app bundles in
 ~/Applications.  Any answer that MDSchemaCopyAllAttributes() would
 give you when running as root might be incorrect for the user who's
 actually the results.

 --Kyle Sluder


Interesting. So what you're saying is that the schema is actually defined on
a per-user basis, depending on what applications and spotlight importers are
installed for that user?  Shouldn't root, though, still be able to list the
schema provided by apps in /Applications and importers in /Library/Spotlight
Importers?

-BJ
___

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

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

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

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


Binding to an NSArrayController subclass

2009-05-15 Thread BJ Homer
I have an NSTableView displaying a collection of rules.  (Let's imagine
they're smart playlists, a la iTunes.)  I set up an NSArrayController to
provide access to these playlists, and at that level, everything works.  The
ArrayController has its contentSet as the set of playlists, and I can
display the name of each playlist by binding the Value of an NSTableColumn
to {bindTo = PlaylistArrayController, controllerKey = 'arrangedObjects',
modelKey = 'name'} in Interface Builder.  (Forgive the odd notation, I'm
just trying to provide enough information.)  With this configuration, the
tableview displays the name of each playlist correctly.

However, I also wanted to display the number of songs matching each
playlist.  This is something the playlist won't know when it's created,
since files matching the rule might be added later.  Hence, I can't bind
directly to a value on the Playlist object.  Instead, I created a subclass
of NSArrayController called PlaylistArrayController, which has a reference
(connected through IBOutlets in interface builder) that can provide it
information about what files match the playlist.  I changed the class of the
array controller in InterfaceBuilder, so that it's actually of class
PlaylistArrayController.  Retrieving the name still works at this point.

I then attempted to add another key to the controller, parallel to
arrangedObjects.  Where arrangedObjects returns an array of Playlists,
arrangedCounts should return an array of NSNumbers. This is the
implementation:

- (id)arrangedCounts {

NSArray *objects = [self arrangedObjects];

NSMutableArray *counts = [NSMutableArray arrayWithCapacity:[objects
count]];



Playlist *rule;

NSEnumerator *ruleEnumerator = [objects objectEnumerator];

while (rule = [ruleEnumerator nextObject]) {

int count = [playlistController countForRule:rule];

[counts addObject:[NSNumber numberWithInt:count]];

}

return counts;

}


However, when I attempt to bind another column to {bindTo =
PlaylistArrayController, controllerKey = 'arrangedCounts', modelKey =
blank}, I get problems.  I have walked through the arrangedCounts method and
verified that it is, in fact, returning an array of NSNumbers just as I
expect.  However, instead of displaying a number with each name, each row in
the table tries to display the entire array of counts.  If I tweak
arrangedCounts to always return the string @hi, then each row will display
hi in that column.

The only difference I can see between the two is that I am not using the
modelKey of the property, since I actually want to display the value of each
object (an NSNumber) itself.  I've even tried adding an NSDictionary to my
counts array with the NSNumber as the value for the key count, and setting
modelKey = 'count' on the bindings, but that still didn't work.  Is there
some deep magic behind [NSArrayController arrangedObjects] that I don't have
access to?  Is there a better way to solve my problem?  I considered using
an NSValueTransformer, but I would have to create a static
playlistController object which would be shared app-wide, and I'd rather not
do that.

Please let me know if I'm missing some important piece of information here.

-BJ Homer
bjho...@gmail.com
___

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

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

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

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


Re: A tree data structure?

2009-05-06 Thread BJ Homer
On Wed, May 6, 2009 at 2:15 AM, Andreas Grosam agro...@onlinehome.dewrote:


 On May 5, 2009, at 6:54 PM, Clark Cox wrote:

  On Tue, May 5, 2009 at 8:28 AM, Andreas Grosam agro...@onlinehome.de
 wrote:


 On May 5, 2009, at 3:21 PM, Ken Thomases wrote:


 Since you mention NSTreeController and CFTree, you may already be aware
 of
 this, but just in case you aren't: have you looked at NSTreeNode?


 I didn't - thanks for this hint :) And it looks perfect if I decide to
 implement my own container, but I'm going to search some more
 opportunities.


 Beyond NSTreeNode, what more do you have to implement? (i.e. there
 needn't be any container for a tree data structure, it can be
 composed completely of its nodes).

 Well, this depends on your requirements and whether it is a search tree or
 a graph.
 In my actual case I wont need much functionality.

 Some possible requirements may be:
 copy, slice, count, rotate, enumerators with the five most common traversal
 methods, partial locks, thread safety,
 time and space complexity constraints, etc.



 Instantiate a root node, and that can be your container, then add
 and remove children as appropriate.

 In may case, this will work since, as mentioned, I just need a graph,
 insert methods and a traversal algorithm.


 Regards
 Andreas


Quinn Taylor, who made the CHDataStructures framework I referenced earlier,
asked me to post the following in response to this latest post.

These links should be helpful...

-
http://dysart.cs.byu.edu/websvn/filedetails.php?path=/CHDataStructures/source/CHAbstractBinarySearchTree.m
-
http://dysart.cs.byu.edu/websvn/filedetails.php?path=/CHDataStructures/source/CHAbstractBinarySearchTree_Internal.h

Searching for - (id) nextObject { at the first link puts you right at the
traversal algorithms he's talking about.

Not sure what he's talking about with slice and rotate, but variants of this
code would make implementing the operations he talks about a lot easier for
an N-ary tree, although not trivial. :-)

Thanks,
  - Quinn
___

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

Please do not post admin requests or moderator comments to the list.
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: A tree data structure?

2009-05-05 Thread BJ Homer
You may be interested the CHDataStructures framework, hosted by the BYU
CocoaHeads group.  It has a number of such structures that should work for
you.
http://cocoaheads.byu.edu/code/CHDataStructures

http://cocoaheads.byu.edu/code/CHDataStructures-BJ Homer

On Tue, May 5, 2009 at 7:10 AM, Andreas Grosam agro...@onlinehome.dewrote:


 NSTreeController and CFTree is not exactly what I'm searching for. I would
 like to have  a *pure*, simple and effective but complete tree data
 structure which comprises a hierarchy of objects:

 root
  |- object1
  |- object2
 |- object4
 |- object5


 The container shall be sequential, that is its elements shall be ordered.


 A possible approach could look like this:

 @interface Tree {
  Node* root;
 }
 -(void) addObject: (NSObject)* data into:(Node*)parent;
 -(TreeEnumerator*) enumeratorOfType:(int) enumeratorType;
 - (int) count;
 ...
 @end


 Class Node contains the data and structural information:

 @interface Node {
NSMutableArray*  data;
Node*parent;
 }
 -(void) addObject:(NSObject*) data;
 -(int) count;
 ...
 @end



 Is there already something available like this?
 Thanks in advance for hints.


 Regards
 Andreas Grosam
 ___

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

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

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

 This email sent to bjho...@gmail.com

___

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

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

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

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


Re: unrecognized selector sent to instance

2009-04-15 Thread BJ Homer
On Wed, Apr 15, 2009 at 9:02 AM, Bill Bumgarner b...@mac.com wrote:

 On Apr 15, 2009, at 7:04 AM, Jason Stephenson wrote:

 So, the error that I get at runtime makes it appear that my
 SIGIOBzip2OutputStream does not respond to the -[initToFileAtPath:append:]
 selector, but it does. In the debugger, it looks as though
 SIGIOBzip2OutputStream's super class is the object that doesn't respond to
 that selector. But, it's superclass is NSOutputStream, and it is documented
 to respond to that selector and I get no warnings about the selector when
 compiling.


 Actually, it doesn't.  A subclass of NSOutputStream responds to that
 method.

 NSStream/NSOutputStream are both abstract classes with very specific
 subclassing notes.

 See the documentation:


 http://developer.apple.com/DOCUMENTATION/Cocoa/Reference/Foundation/Classes/NSOutputStream_Class/Reference/Reference.html


Which says:

 Subclassing Notes

The NSOutputStream is a concrete subclass of NSStream that lets you write
data to a stream. Although NSOutputStream is probably sufficient for most
situations requiring this capability, you can create a subclass of
NSOutputStream if you want more specialized behavior (for example, you want
to record statistics on the data in a stream).


Seems to be concrete to me. Nevertheless, calling it on super does throw an
exception; you might just try calling [super init] and see what happens.

Note that you'll also get exceptions on [super open] and [super close] in
those respective methods, since they're not defined on the superclass.  Look
at the subclassing notes on both NSStream and NSOutputStream, and you'll be
closer.



 http://developer.apple.com/DOCUMENTATION/Cocoa/Reference/Foundation/Classes/NSOutputStream_Class/Reference/Reference.html

 And:


 http://developer.apple.com/DOCUMENTATION/Cocoa/Reference/Foundation/Classes/NSStream_Class/Reference/Reference.html#//apple_ref/occ/cl/NSStream

 There is a very specific set of methods you need to override.   -init isn't
 one of them;  you don't need to call super's implementation, apparently.

 b.bum

___

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

Please do not post admin requests or moderator comments to the list.
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: Dragging around an NSImageView

2009-04-03 Thread BJ Homer
On Fri, Apr 3, 2009 at 9:54 AM, Randall Meadows cocoa-...@not-pc.comwrote:

 On Apr 3, 2009, at 4:14 AM, Aaron Scott wrote:

  I'm trying to figure out how to be able to drag an NSImageView around. The
 NSImageView has been added as a subview to another NSImageView.

 Basically, I'm trying to drag a grey box around over the top of a picture.
 I can programmatically move it around but I can't seem to find the right
 code to allow me to drag it around.


 You don't actually drag a *view*, you drag an image.  Pedantic, perhaps,
 but important.

 When you start a drag, you specify the image that will be dragged.  See
 NSView's -dragImage:at:offset:event:pasteboard:source:slideBack:, as well as
 Dragging Sources in the Drag and Drop Programming Topics for Cocoa
 reference.


That's true if you're trying to do drag-and-drop programming, but I don't
think the OP was trying to do that.  I think he's basically trying to change
the frame of a subview.  If that's the case, I think you'll want to look at
the documentation for -[NSResponder mouseDragged].  (Note that NSImageView
is a type of NSResponder.)

-BJ
___

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

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

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

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


-[UIView actionForLayer:forKey:] returns NSNull

2009-03-03 Thread BJ Homer
I have a UIWebView displaying the contents of a local html file.  When the
user presses a button, I'd like to transition, with a fade, to another
UIWebView (also displaying local content; no need to wait for the network.)
 The UIView transitions will not do a fade, but a CATransition on a CALayer
would do the trick.  Of course, I'd need to apply to the CATransition to a
layer containing both of the webViews, but that's fine; the UIWebViews are
both subviews of another UIView that serves simply to contain both of them.
As I understand, when a subview is added to a view, the layer calls
-[CALayer actionForKey:], which goes through the following search (self
refers to the CALayer on which actionForKey: was called):
  1. [self.delegate actionForLayer:forKey:]
  2. [self.actions valueForKey:]
  3. Recursively search self.style for an actions dictionary, then [actions
valueForKey:]
  4. [self defaultActionForKey:]

If any of these steps returns a non-nil result, that value is used.
Especially relevant in this case is the fact that when an NSNull is
returned, the search stops and nil is returned from [CALayer actionForKey:].

The problem is that, as near as I can tell, UIView's implementation of
actionForLayer:forKey: returns an NSNull.  I would have liked to add a
CATransition to the container view's layer's action dictionary
(view.layer.actions) for the key kCAOnOrderIn.  However, since UIView's
actionForLayer:forKey: returns NSNull, the search always bails out after the
first step.  This seems odd, since it seems that defaultActionForKey: never
actually gets the chance to return a default action unless you're already
changing things.

Am I missing something here, or is a UIView's layer's actions dictionary
only usable if you're subclassing UIView?

-BJ Homer
___

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

Please do not post admin requests or moderator comments to the list.
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