Re: Sending a Selector to another Class.

2009-10-22 Thread Paul M

With all due respect, but by 'directly answering the question' you
are doing the OP and all those reading this list a dis-service.
You are just rewarding his lazyness.

The OP has already been told to bone up on Obj-C basics, and he's
obviously completely ignored this advice, the reason being that
people continue to answer his silly questions.

He will learn how to find his own answers if forced to do so, and
will become a much better coder as a result.

It's much better for him and for all the rest of us, if you would
please refrain from 'directly answering the question in these
circumstances.


paulm



On 22/10/2009, at 7:12 PM, Rob Keniger wrote:



On 22/10/2009, at 3:52 PM, Joshua Garnham wrote:

Ah, I see. so I need to send it to an instance of the class not the  
class it self.

How would I do that?



With respect, please understand that your questions are akin to this:

Q. How do I start the car?
A. You turn the key.
Q. How do I drive?
A. ummm

You need to learn the basics of Objective-C, it is very clear that you  
do not understand even the simplest concepts.


To directly answer your question, you allocate and initialize an  
instance of your class using [[YourClass alloc] init], or using a  
convenience class method or other designated initializer. However,  
this information is unlikely to help you until you invest some time in  
learning Objective-C.


I personally recommend reading this book:

http://www.amazon.com/Programming-Objective-C-2-0-Stephen-Kochan/dp/ 
0321566157


It's all laid down here though:

http://developer.apple.com/mac/library/documentation/Cocoa/Conceptual/ 
ObjectiveC/index.html


--
Rob Keniger



___

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

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

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/list%40no-tek.com

This email sent to l...@no-tek.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


to implement a 1 sec repeating timer in a separate thread

2009-10-22 Thread Nick Rogers

Hi,
I have been trying to implement a 1 second repeating timer, but its  
leading to retaining the target object of a thread from which I'm  
launching this timer thread.

Here's my implementation.

I'm running this method from my thread.
- (void)setUpTimer
{
	timerThread = [[NSThread alloc] initWithTarget:self selector:@selector 
(startTimer) object:nil];

[timerThread start];
}

- (void)startTimer
{
	timer = [NSTimer timerWithTimeInterval:1.0 target:self  
selector:@selector(myTimerFireMethod:) userInfo:nil repeats:YES];

NSRunLoop *theRL = [NSRunLoop currentRunLoop];
[theRL addTimer:timer forMode:NSDefaultRunLoopMode];
	while (keepTimerRunning && [theRL runMode:NSDefaultRunLoopMode  
beforeDate:[NSDate distantFuture]]);

}

- (void)myTimerFireMethod:(NSTimer*)theTimer
{
[self setUpdateStatus:YES];
}

From my thread I'm doing something when updateStatus is YES and then  
I'm setting it to NO, which is again set to YES by this timer, so that  
I get to do something at 1 second interval.
But its leading to referencing the target object of my thread, by 3-4  
non-objects (bytes), which shows different descriptions every time as  
per GC Monitor Instrument (kind of undefined behavior).


Whats wrong with the above scheme, or how can I make it safe?
Googled a lot but couldn't find a simple timer example that would suit  
my need. Can you point me to some example code etc.?


Wishes,
Nick

___

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

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

Help/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: to implement a 1 sec repeating timer in a separate thread

2009-10-22 Thread Dave Keck
I'm having a really hard time making sense of you message...
> I have been trying to implement a 1 second repeating timer, but its
leading
> to retaining the target object

That's expected behavior - NSTimers retain their targets. The target won't
be deallocated until the timer has been invalidated (assuming the timer was
the only thing keeping the target alive.)

> But its leading to referencing the target object of my thread, by 3-4
> non-objects (bytes), which shows different descriptions every time as per
GC
> Monitor Instrument (kind of undefined behavior).

Woah, this sentence has my completely baffled:

 o Prior to this sentence, you were talking about retaining/releasing, not
you're talking about garbage collection. I think I'm still following you
though - regardless, the timer is keeping the target alive.

 o 3-4 bytes of what? Why do these bytes matter?

== Moment of clarity in 3... 2... 1...

Oh. I think you're just trying to have a method called every second. If
that's the case, no need to concern yourself with threads and... well,
whatever it is that's going on in that code snippet. :D

   [NSTimer scheduledTimerWithTimeInterval: 1.0 target: self
selector: @selector(doSomething:) userInfo: nil repeats: YES];

That will call self's -doSomething: method every second. Is that what you're
trying to accomplish?
___

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

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

Help/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: "Sticky" Event tracking

2009-10-22 Thread Joel Norvell
Hi Francisco,

When you click outside of your application, your window's delegate will receive 
a windowDidResignKey message.

I don't know if this is the standard way of handling the type of case you 
described, but I believe it would work.

Sincerely,
Joel



  
___

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

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

Help/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: NSNotificationCentre very slow - normal?

2009-10-22 Thread Graham Cox


On 22/10/2009, at 5:53 PM, Kyle Sluder wrote:

On Oct 21, 2009, at 11:32 PM, Graham Cox   
wrote:


My question is, is this a known slow spot? I've never noticed  
NSNotificationCentre being so slow before, and can't think why it  
would be. And of course, what can I do to help it? I've temporarily  
removed the addObserver call in the code and sure enough it goes a  
lot faster. Trouble is, I do need that notification. Any ideas?


Just dealt with this in a tree controller scenario. In this case, I  
have my tree controller subclass listen for the ItemChanged  
notification unconditionally. It then figures out which node  
represents that item and calls a -noteItemChanged:(NSNotification*) 
aNotification method on it. This is much faster than N different  
observer registrations, because it avoids two bottlenecks: the  
registration side and the dispatch-based-on-notifying-object side.



Thanks Kyle (and Nick too), at least I know I'm looking at a known  
problem.


I'm trying to work out if this solution will fit my model. Right now  
it's hard to see how I can do it, but I'll keep thinking - thanks!


--Graham


___

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

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

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

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


Re: to implement a 1 sec repeating timer in a separate thread

2009-10-22 Thread Nick Rogers

Hi,
Thanks for the reply. My question was very vague, I admit.
But now I have moved to your suggestion.
I'm setting up the timer via  [NSTimer scheduledTimerWithTimeInterval:  
1.0 target: self selector: @selector(doSomething:) userInfo: nil  
repeats: YES];

But the doSomething is not getting called at all.
May be because this thread is busy doing something else, so do I have  
to setup the timer in say main Thread.
Earlier I was doing so, by setting up the timer by calling this  
setting up method as [self performSelectorOnMainThread:],  
and it was working, but even after invalidating the timer, the timer  
was still referencing the object that contained NSTimer *timer.


Any suggestions?
Nick

On 22-Oct-2009, at 2:32 PM, Dave Keck wrote:


I'm having a really hard time making sense of you message...

> I have been trying to implement a 1 second repeating timer, but  
its leading

> to retaining the target object

That's expected behavior - NSTimers retain their targets. The target  
won't be deallocated until the timer has been invalidated (assuming  
the timer was the only thing keeping the target alive.)


> But its leading to referencing the target object of my thread, by  
3-4
> non-objects (bytes), which shows different descriptions every time  
as per GC

> Monitor Instrument (kind of undefined behavior).

Woah, this sentence has my completely baffled:

 o Prior to this sentence, you were talking about retaining/ 
releasing, not you're talking about garbage collection. I think I'm  
still following you though - regardless, the timer is keeping the  
target alive.


 o 3-4 bytes of what? Why do these bytes matter?

== Moment of clarity in 3... 2... 1...

Oh. I think you're just trying to have a method called every second.  
If that's the case, no need to concern yourself with threads and...  
well, whatever it is that's going on in that code snippet. :D


   [NSTimer scheduledTimerWithTimeInterval: 1.0 target: self  
selector: @selector(doSomething:) userInfo: nil repeats: YES];


That will call self's -doSomething: method every second. Is that  
what you're trying to accomplish?


___

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

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

Help/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: Search on Core data Table issue?

2009-10-22 Thread Matthew Lindfield Seager
A "reducing search" is more commonly referred to as filtering. A
google search should help you very quickly as this is very easy with
core data & bindings.

If you're still struggling another keyword that may help is (NS)Predicate.

Matt
___

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

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

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

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


Re: to implement a 1 sec repeating timer in a separate thread

2009-10-22 Thread Dave Keck
Before I try to respond, I'd just like to say you've been mentioning
threads a lot, but you haven't said anything that convinces me that
more than one thread is necessary for what you're trying to do. Unless
you're doing some serious number crunching, video encoding, curing
cancer, etc. it's likely that you won't need any threads other than
the main thread. If, indeed, you simply want a timer to fire
every-so-often, then forget about threads - for this purpose, one
thread is all you'll need.

> But the doSomething is not getting called at all.
> May be because this thread is busy doing something else, so do I have to
> setup the timer in say main Thread.

You should be able to answer whether "this thread is busy doing
something else": Do you have a while() loop that never exits? How
about a sleep(666)? Why do you think the thread is "busy doing
something else" - is your app beachballing? Are you sure that the
timer is being created at all? (Put a breakpoint or an NSLog(@"timer
created"); before the line that creates the timer.)

Further, use the debugger! Pause your app after it's started up, and
see what it's doing. If it's in a CFRunLoop-derived function (ie,
mach_msg_trap()) then your run loop should be happily doing its thing.

> Earlier I was doing so, by setting up the timer by calling this setting up
> method as [self performSelectorOnMainThread:], and it was
> working, but even after invalidating the timer, the timer was still
> referencing the object that contained NSTimer *timer.

That doesn't make sense - performSelectorOnMainThread:... doesn't
return a timer, so how could you invalidate it? Furthermore, I don't
understand "the timer was still referencing the object that contained
NSTimer *timer", nor do I see how that might relate to the timer
successfully invoking your method. :-/

So let's back up. From a user's perspective, what are you trying to
do? Also, it would probably do you some good to read these:

  
http://developer.apple.com/mac/library/documentation/Cocoa/Conceptual/Timers/Timers.html
  
http://developer.apple.com/mac/library/documentation/Cocoa/Conceptual/Multithreading/Introduction/Introduction.html
___

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

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

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

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


Re: Sending a Selector to another Class.

2009-10-22 Thread Jim Kang
Jens, thanks for clearing up the thing about the selector defining a message
(method plus parameters) rather than a method and thus not being tied to a
class.

On Thu, Oct 22, 2009 at 1:21 AM, Jens Alfke  wrote:

>
> On Oct 21, 2009, at 9:43 AM, Jim Kang wrote:
>
> That selector is a unique index that points to a method of a specific
> class.
>
>
> No, that's not true of Objective-C (although it is of C++ method-pointers.)
> A selector is, basically, just a unique string: it defines a *message*,
> not a method, to use the old Smalltalk OOP terminology.
>

However, a selector is not a string. I was just listening to this podcast
with Mike Ash, and he discusses this around the 9:23 mark or so:

http://podcast.mobileorchard.com/episode-23-mike-ash-on-the-objective-c-runtime-objects-and-the-runtime-message-sending-and-no-such-method/

He explains that comparing strings is too slow for the runtime to use for
finding messages and so it uses integers to represent the messages and calls
them selectors.


> Any class that implements a method with that name uses the same selector
> for it, regardless of inheritance.
>
> To be specific, if I create two unrelated classes A and B, each of which
> implements a -foo method, the selector @selector(foo) is used for both.
>

This is really good to know.
___

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

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

Help/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 run a panel that customizes a new NSDocument

2009-10-22 Thread Ben Haller

On 22-Oct-09, at 2:24 AM, Quincey Morris wrote:

1. Yes, there's a defect in the NSDocumentController design which  
makes it awkward to pass an initial state to a new document without  
having to re-implement everything that NSDocumentController does.  
Awkward but not impossible or even difficult. So let's just get over  
it and move on.


  Now that I've heard someone knowledgeable say that, I am happy to  
move on.  I figured I was just using the framework incorrectly, since  
usually "fighting with the framework" indicates that (which indicates  
how good Apple's designs usually are!)


2. My second suggestion *in no way* depends on knowing what any  
method of NSDocumentController actually does, except that I  
consulted the documentation for 'newDocument:' to guide me in  
choosing which method to override. If that bugs you, override  
'newDocument:' too, to make it do what the documentation says it  
currently does, and you're future-proofed until and unless  
'openUntitledDocumentAndDisplay:error:' is deprecated.


  Given that they deprecated a wave of these methods in 10.4  
(including the predecessor to openUntitledDocumentAndDisplay:error:),  
that does worry me a bit.  The architecture seems like a work in  
progress, which makes me feel I ought to tread especially carefully.


My first suggestion depends on knowing that the type passed to the  
new document instance will be provided by 'defaultType'. It's  
conceivable but extremely unlikely that this is ever going to  
change, but if that bothers you, use the second suggestion.


  Both your fixes still strike me as hacks, and having just spent  
some weekends updating old apps that were bitten by changes that I  
thought at the time were "conceivable but extremely unlikely," I am  
now more wary of such evaluations than I used to be.  But your  
suggestions do seem fairly safe.


Your existing code is, in a sense, more dependent on the current  
implementation details of NSDocumentController, because you're  
trying to do what the documentation says that NSDocumentController  
does.


  Yes, this is exactly what bothers me about it, and is why I've been  
looking for a better solution.


3. The only ways my second suggestion (and, for all practical  
purposes, my first suggestion) could fail are (a) if documents were  
being created on multiple threads, which can't happen because  
NSDocumentController isn't thread safe, or (b) if  
'openUntitledDocumentAndDisplay:error:' could possibly get called  
recursively, which it doesn't. If you're worried about that, then go  
ahead and use your current implementation, which is perfectly viable  
even if it makes you uncomfortable.


  Well, I was worried about a scenario, for example, where multiple  
documents were getting created at once, and that was done in an  
interleaved fashion such that your suggested code would end up setting  
the type into the special ivar/global multiple times, then getting the  
last set type out of the ivar/global multiple times, thus making many  
documents of the last type set, rather than one document each of each  
one type set.  But the more I ponder it the less likely that seems to  
actually happen, so I won't worry about it.


Huh? You *are* getting advice from somebody who knows how this  
architecture is intended to be used, both from having implemented "a  
document like this", and from having carefully absorbed *extensive*  
discussions on this list of how the NSError** output parameter is  
intended to be used.


  Please don't be so easily offended.  Your original reply did not  
indicate you had ever implemented such a scheme; it sounded like a  
tossed-off guess.  Your wording "I don't understand why you think you  
can't..." made it sound like you felt there was no particular problem  
with the design of the framework, which made me suspicious of your  
answer; you seemed to just be saying "Why is there a problem, it's  
easy to hack your way around it," which is an attitude that is not  
terribly helpful when trying to understand the design of a framework  
and how best to use it.  Your acknowledgement in this reply that there  
is indeed a defect in the architecture is much more useful.
  Your answer to the NSError question ("you're not returning an error  
object when you return nil at the end of the method") was unhelpful  
since adding a return of an NSError just changed the behavior of the  
code to a different, equally incorrect behavior; it took a more useful  
tip from a different poster to point me to the fact that a  
*particular* NSError needed to be returned, which was not mentioned in  
any of the documentation that I was looking at.  I state these things  
not to be critical (not trying to start a flamewar here!), but to  
explain to you why I asked the list for advice from "somebody who  
knows how this architecture was intended to be used" and someone who  
"has actually implemented a document like this".  So.  Thanks for your  
r

Re: Opening a NSSavePanel as a Sheet, and blocking like in [panel runModal]

2009-10-22 Thread Motti Shneor

Thanks again.

Regarding the Carbon Window problem, the FrontWindow() call was just  
an illustration. The WindowRef I'm supplying is of a visible (usually  
active and front) Document window. The problems are not even  
consistent, and will randomly occur. The desired behavior, though,  
will very rarely occur. (I'd say one in a hundred times).


In short --- Are there any specific implications to opening a cocoa  
sheet over a carbon (document) window? Is there any specific setup I  
need to know about? What are the limitations of Cocoa NSWindow  
wrappers around Carbon windows?


The problem is, my Plugin is written using cocoa, but runs within a  
Carbon application. I need to attach my NSOpen/NSSave panels onto a  
given application window, which is, of course, a Carbon window. I get  
this bogus behavior and even worse, both running with my Host  
application, and with simplistic test programs like the one below.


Any hints?

Last (and most important) - Supposedly I use your nice category
like this:

WindowRef frontWin = ::FrontWindow();  // get Carbon application
front window. Actually, any carbon window.
NSWindow *cocoaFromCarbonWin = [[NSWindow alloc]
initWithWindowRef:frontWin];
NSSavePanel *navPanel = [NSSavePanel savePanel];
[navPanel runModalForDirectory:nil file:nil types:nil
relativeToWindow: cocoaFromCarbonWin];

Then I'm seeing a host of strange and bogus behaviors.

1. The most severe is that the sheet opens BEHIND the application
window, BUT is still the key window. So, the application is dead
--- I can't click on the sheet (it's not front, and not active,
does not respond to clicks). However, the main application window
is blocked for events too! (I have blocked it via
runModalForWindow!). so, I'm dead. User must force-quit the
application.

2. The sheet opens in the wrong place -- just somewhere on the
screen - not always the same place, but "favorably" when a centered
dialog would appear. If then I try to drag the parent carbon window
by its title, the sheet would "jump into place" and be dragged
right. Events seem to be OK.

3. The sheet is invisible --- Although I get no errors from the
application. However, the debugger console would (sometimes!)
contain lines like this:

[Session started at 2009-10-21 11:01:52 +0200.]
GNU gdb 6.3.50-20050815 (Apple version gdb-1346) (Fri Sep 18
20:40:51 UTC 2009)
Wed Oct 21 12:11:53 Moti-Schneors-Mac-Pro.local NavTester[4398]
: kCGErrorIllegalArgument: _CGSFindSharedWindow: WID 1835
Wed Oct 21 12:11:53 Moti-Schneors-Mac-Pro.local NavTester[4398]
: kCGErrorFailure: Set a breakpoint @ CGErrorBreakpoint() to
catch errors as they are logged.
Wed Oct 21 12:11:53 Moti-Schneors-Mac-Pro.local NavTester[4398]
: kCGErrorIllegalArgument: CGSOrderWindowListWithGroups:
invalid window ID (1835)
Wed Oct 21 12:11:53 Moti-Schneors-Mac-Pro.local NavTester[4398]
: kCGErrorIllegalArgument: CGSOrderWindowList: NULL list
pointer or empty list
Wed Oct 21 12:11:53 Moti-Schneors-Mac-Pro.local NavTester[4398]
: kCGErrorIllegalArgument: _CGSFindSharedWindow: WID 1836
Wed Oct 21 12:11:53 Moti-Schneors-Mac-Pro.local NavTester[4398]
: kCGErrorIllegalArgument: CGSOrderWindowListWithGroups:
invalid window ID (1836)
Wed Oct 21 12:11:53 Moti-Schneors-Mac-Pro.local NavTester[4398]
: kCGErrorIllegalArgument: CGSOrderWindowList: NULL list
pointer or empty list

Any ideas? something I forgot to do? What in general is the state
of opening cocoa-sheets over Carbon-windows? When do I need to
release this NSWindow? I don't wish to close the Carbon window, as
it is coming from my host application!


You may not want to call FrontWindow() since its docs say, "Most
applications should use call ActiveNonFloatingWindow or
FrontNonFloatingWindow instead of FrontWindow because
ActiveNonFloatingWindow and FrontNonFloatingWindow return the active
and frontmost document window, respectively, skipping over other
types of windows that may be in front of the active document, such as
the menubar window, floating windows, help tags and toolbars."



Motti Shneor
Software Engineer

Waves Audio Ltd
Tel: +972 3 608 4155
www.waves.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


NSTextField not getting mouseDown

2009-10-22 Thread Sander Stoks

Hello all,

Executive summary: I have an NSTextField in an NSPanel which, under  
certain circumstances, doesn't receive mouseDowns anymore.   
Specifically, this happens after I end editing with Enter (instead of  
Tab)


Background: I am using NSPanel to make a "tool window" for my app.   
This window contains a few buttons, sliders, and an NSTextField.  I  
wanted this window to avoid becoming key, so that the user can select  
a new tool on this window without her main window losing focus and her  
having to select it again.  I managed to get the right behavior by  
overriding canBecomeKeyWindow and returning NO.  All buttons and  
sliders were fully operable this way.


Until I added an NSTextField, which obviously needs its containing  
window to be the key window to work.  I couldn't get this combination  
of requirements implemented successfully, so I solved it partially by  
making my own textfield and panel subclasses; when the textfield gets  
a mouseDown, I send a "focusRequested" message to its panel, which  
then sets a boolean ivar, like so:


- (BOOL)canBecomeKeyWindow {
return m_focusRequested;
}

- (void)requestFocus {
m_focusRequested = YES;
}

- (void)resignFocus {
m_focusRequested = NO;
}

In the textfield, when it gets a textDidEndEditing message, I send  
"resignFocus" to the panel.  This works.


But: if I cause editing to end by pressing the Enter key (instead of  
Tab), and then give another window the focus, clicking on the  
textfield doesn't cause a mouseDown to be receive anymore.  The  
contents of the textfield stay selected (the focus ring is, of course,  
gone).  Therefore, my panel keeps returning NO from canBecomeKeyWindow  
because it never got a focusRequested message.


Apologies for the long post, but I wanted to make sure I'm approaching  
this the right way.


I also overrode acceptsFirstMouse in my textfield, returning YES, but  
that doesn't make a difference.


Thanks for any insights,
regards,
Sander

___

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

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

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

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


NSScroller graphical lag/glitches

2009-10-22 Thread PCWiz

Hi,

I have the following NSScroller subclass that creates a scroll bar  
with a rounded white knob and no arrows/slot (background):


@implementation IGScrollerVertical

- (void)drawKnob
{
NSRect knobRect = [self rectForPart:NSScrollerKnob];
	NSRect newRect = NSMakeRect(knobRect.origin.x,  
knobRect.origin.y, knobRect.size.width - 4, knobRect.size.height);
	NSBezierPath *path = [NSBezierPath  
bezierPathWithRoundedRect:newRect xRadius:7 yRadius:7];

[[NSColor whiteColor] set];
[path fill];
}

- (void)drawArrow:(NSScrollerArrow)arrow highlightPart:(int)flag
{
// We don't want arrows
}

- (void)drawKnobSlotInRect:(NSRect)rect highlight:(BOOL)highlight
{
// Don't want a knob background
}
@end

This all works fine, except there is a noticable lag when I use the  
scroller. See this video:


http://twitvid.com/70E7C

I'm confused as to what I'm doing wrong, any suggestions?
___

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

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

Help/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 design related question

2009-10-22 Thread Stamenkovic Florijan

Hi Marc,

On Oct 20, 2009, at 16:11, Marc Rink wrote:


Heyas,

I am quite new to Objective-C (and to some extend to OO concepts as  
well), so please be gentle with me :)


I have a core data based document application that purpose is to  
access a mysql database (i am using the MCP Kit).
The documents in my context are Views that contain different aspects  
of the database (small portions consisting of some tables related to  
each other).

One document contains the connection parameters for the database.

I am switching the views according to Aaron Hillegass' example using  
a view controller (the downloadable examples are http://www.bignerdranch.com/solutions/Cocoa-3rd.tgz) 
.


I want to achive the following:
Upon application start the first view "ConfigViewController" is  
shown. It contains all connection related parameters (such as host,  
port, user, password and database) and a "Connect" button.
Upon clicking the "Connect" button, the connection to the database  
is established. The result is a connection object, that i wanted to  
pass around the different Views.


First approach was to pass the resulting connection to the  
superclass of the view's (all my view's are derived from a custom  
superclass which extends NSViewController). For reasons i dont know,  
i didnt get this to work. The resulting object was invalid (nil) in  
the other view's.


Second approch (and better one imho) is to add a core data entity  
"DBConfiguration" holding all connection parameters (persistent, so  
you dont have to enter the stuff every time) and a transient  
property for the connection object (of type undefined).
I added a Object Controller to my documents xib file, set the mode  
to "Entity" and the entity name to "DBConfiguration".
My Problem now is: The view containing the textfields and the  
"connect" button are in a different xib file (ConfigView.xib, whose  
Files Owner is of Type "ConfigViewController". I dont know how to  
bind the ConfigView's text fields to the Object Controller in  
MyDocument.xib.


OK, this was a lot of info. What is your actual problem? Can't you  
simply make another object controller for DBConfig in ConfigView.xib?


Also note that CoreData is probably not the right solution for storing  
your connection info. From what you say the user defaults system seems  
much more appropriate.


I am still new to the different frameworks and unsure about whether  
my design is acceptable or if i am on a completely wrong way.


When taking on so much at once (as you claim to be inexperienced), it  
is almost guaranteed you are not doing things the right way. Still,  
your app seems quite complex and it does not make sense trying to  
explain it all when looking for a solution for a reasonably small  
problem. I am sure you'd get more answers if you put the question to  
the point.


Also, if you are really new to all of this stuff, this sounds like a  
big first step. Too big. Start with small, isolated functionalities  
and practice.


F
___

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

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

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

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


Re: Opening a NSSavePanel as a Sheet, and blocking like in [panel runModal]

2009-10-22 Thread glenn andreas


On Oct 22, 2009, at 8:44 AM, Motti Shneor wrote:


Thanks again.

Regarding the Carbon Window problem, the FrontWindow() call was just  
an illustration. The WindowRef I'm supplying is of a visible  
(usually active and front) Document window. The problems are not  
even consistent, and will randomly occur. The desired behavior,  
though, will very rarely occur. (I'd say one in a hundred times).


In short --- Are there any specific implications to opening a cocoa  
sheet over a carbon (document) window? Is there any specific setup I  
need to know about? What are the limitations of Cocoa NSWindow  
wrappers around Carbon windows?


The problem is, my Plugin is written using cocoa, but runs within a  
Carbon application. I need to attach my NSOpen/NSSave panels onto a  
given application window, which is, of course, a Carbon window. I  
get this bogus behavior and even worse, both running with my Host  
application, and with simplistic test programs like the one below.




There's one fundamental problem - sheets are designed to be document  
modal, not application modal, which requires support from the  
underlying application in order to work correctly.


So a sheet is not support to block the app like runModal does, but to  
work in conjunction with document architecture.


You're basically fighting the frameworks, and the frameworks always  
win...


Glenn Andreas  gandr...@gandreas.com
  wicked fun!
Mad, Bad, and Dangerous to Know

___

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

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

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

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


stringWithContentsOfURL with resulting error 256

2009-10-22 Thread James Lin

Hi,

I am trying to access a PHP script (which adds an entry to MySQL  
database) on my server with the following call:


NSString *result = [NSString stringWithContentsOfURL:theURL  
encoding:NSUTF8StringEncoding error:&error];


However, the result comes back with an NSError as the following:

Error Domain=NSCocoaErrorDomain Code=256 UserInfo=0x15d7b0 "Operation  
could not be completed. (Cocoa error 256.)

which is a NSFileReadUnknownError = 256.

BUT! The same URL string works perfectly in a Safari window and the  
PHP script executes fine when accessed from Safari...


Can anyone please point me to how to troubleshoot this one?

Thank you in advance...

James
___

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

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

Help/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: NSTextField not getting mouseDown

2009-10-22 Thread Graham Cox


On 23/10/2009, at 1:08 AM, Sander Stoks wrote:

Background: I am using NSPanel to make a "tool window" for my app.   
This window contains a few buttons, sliders, and an NSTextField.  I  
wanted this window to avoid becoming key, so that the user can  
select a new tool on this window without her main window losing  
focus and her having to select it again.  I managed to get the right  
behavior by overriding canBecomeKeyWindow and returning NO.  All  
buttons and sliders were fully operable this way.


Until I added an NSTextField, which obviously needs its containing  
window to be the key window to work.  I couldn't get this  
combination of requirements implemented successfully, so I solved it  
partially by making my own textfield and panel subclasses; when the  
textfield gets a mouseDown, I send a "focusRequested" message to its  
panel, which then sets a boolean ivar, like so:



What you want is to remove all this stuff and look at [NSPanel  
setBecomesKeyOnlyIfNeeded:] which deals with whatever is necessary for  
you. Standard text fields and so on should then work properly.


--Graham


___

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

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

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

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


Re: Displaying a view modally

2009-10-22 Thread glenn andreas


On Oct 21, 2009, at 7:54 PM, Saurabh Sharan wrote:


Check out SFHudView by Buzz Andersen (
http://github.com/ldandersen/scifihifi-iphone/blob/master/UI/SFHFHUDView.h 
)

Saurabh



That code runs contrary to the documentation ("iPhone Application  
Programming Guide", "Windows and Views"):


Although iPhone OS supports layering windows on top of each other,  
your application should never create more than one window. The  
system itself uses additional windows to display the system status  
bar, important alerts, and other types of messages on top of your  
application’s windows. If you want to display alerts on top of your  
content, use the alert views provided by UIKit rather than creating  
additional windows.






Ignoring this will result in inconsistent behavior between different  
OS releases.


You're better off making a simple blocking view that "consumes" all  
the touch events (i.e., implements everything, but does nothing), give  
it a translucent gray background and make it the size of the window,  
and add it as a subview of the window, on top of everything else.


Then add your modal content view on top of that blocking view.



Glenn Andreas  gandr...@gandreas.com
  wicked fun!
quadrium2 | build, mutate, evolve, animate  | images, textures,  
fractals, art



___

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

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

Help/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: Opening a NSSavePanel as a Sheet, and blocking like in [panel runModal]

2009-10-22 Thread Motti Shneor
Hi Glenn, Thanks for your note --- However, I experience these  
problems also when I'm completely document modal.


As a decent programmer, I immediately assumed the problem was in my  
code, and wrote a quick test that did NOT block. I used the non- 
blocking  recommended beginSheetForDirectory:  with the didEnd  
selector, as defined in the API's,  both on NSOpenPanel and  
NSSavePanel.  Same problems occur when attaching to a Carbon window.


By the way --- using [NSApp runModalForWindow:win] is not considered  
"messing with the frameworks" and even is demonstrated in Apple Sample  
code, and in the documentation, within the very scope of NSSavePanel  
sheets. This is all legal technically. I understand that you don't  
like sheets to block events on the whole application, but when I don't  
write the application --- I'm sometimes forced to do so. Also, that's  
what the host application requires from me.


I'm quite sure it has nothing to do with the modality issue. More like  
an internal inconsistency between the Carbon and Cocoa window systems,  
when I try to "bind" them together.


Moreover --- I went on, and re-wrote the whole thing (my navigation  
objects) using Navigation Services - Carbon API's. Even there I  
experience the same problem. You'd ask how's that? Don't we have  
Carbon-To-Carbon relationship? well NO.
As of MacOS 10.5, Navigation Services are based on Cocoa -- even when  
using Carbon API's. which means, my Carbon Nav Services calls are  
internally creating Cocoa panels and sheets, which interact with the  
application windows. Again, I see mal-functioning sheets (opening  
Behind their parent windows, hanging my host program, "eating up" user  
events, etc.


Any hint will be greatly appreciated.


On 22/10/2009, at 16:10, glenn andreas wrote:



On Oct 22, 2009, at 8:44 AM, Motti Shneor wrote:


Thanks again.

Regarding the Carbon Window problem, the FrontWindow() call was just
an illustration. The WindowRef I'm supplying is of a visible
(usually active and front) Document window. The problems are not
even consistent, and will randomly occur. The desired behavior,
though, will very rarely occur. (I'd say one in a hundred times).

In short --- Are there any specific implications to opening a cocoa
sheet over a carbon (document) window? Is there any specific setup I
need to know about? What are the limitations of Cocoa NSWindow
wrappers around Carbon windows?

The problem is, my Plugin is written using cocoa, but runs within a
Carbon application. I need to attach my NSOpen/NSSave panels onto a
given application window, which is, of course, a Carbon window. I
get this bogus behavior and even worse, both running with my Host
application, and with simplistic test programs like the one below.



There's one fundamental problem - sheets are designed to be document
modal, not application modal, which requires support from the
underlying application in order to work correctly.

So a sheet is not support to block the app like runModal does, but to
work in conjunction with document architecture.

You're basically fighting the frameworks, and the frameworks always
win...

Glenn Andreas  gandr...@gandreas.com
  wicked fun!
Mad, Bad, and Dangerous to Know



Motti Shneor
Software Engineer

Waves Audio Ltd
Tel: +972 3 608 4155
www.waves.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: Changing an NSToolbar Identifier

2009-10-22 Thread Matthias Arndt

Am 02.10.2009 um 06:53 schrieb Matthias Arndt:

I introduced a new key in user defaults reflecting the "toolbar  
version". If the toolbar version stored in the user defaults doesn't  
match the toolbar version of the application I simply delete the old  
plist settings and the application will display the default set of  
the new toolbar. The code is placed in  
"applicationDidFinishLaunching" of the application controller:


NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
NSString *toolbarVersion = [defaults stringForKey:@"ToolbarVersion"];
if (![toolbarVersion isEqual:@"2.0"])
{
		[defaults removeObjectForKey:@"NSToolbar Configuration 130D8E5D- 
C86E-47DD-9A4E-B367517DA148"];

[defaults setObject:@"2.0" forKey:@"ToolbarVersion"];
}

For me this approach seems to be rough and it'll break if someone  
switches back to the older version. Unfortunately I had no better  
idea, but I'm open to suggestions ... Too bad the IB doesn't allow  
to set toolbar IDs.


IB 3.2 allows to set a toolbar identifier, so all my code is  
obsolete ... Just checked it and it works :-)


Thanks for the heads-up, Kevin!

Matthias
___

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

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

Help/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: Opening a NSSavePanel as a Sheet, and blocking like in [panel runModal]

2009-10-22 Thread Steve Christensen
I don't know what the difference would be in trying to attach to a  
native NSWindow vs one that wraps a Carbon window. When I've done  
this in the past, I always knew that I was attaching to a native  
NSWindow. Sorry I can't be more helpful.


steve


On Oct 22, 2009, at 6:44 AM, Motti Shneor wrote:


Thanks again.

Regarding the Carbon Window problem, the FrontWindow() call was  
just an illustration. The WindowRef I'm supplying is of a visible  
(usually active and front) Document window. The problems are not  
even consistent, and will randomly occur. The desired behavior,  
though, will very rarely occur. (I'd say one in a hundred times).


In short --- Are there any specific implications to opening a cocoa  
sheet over a carbon (document) window? Is there any specific setup  
I need to know about? What are the limitations of Cocoa NSWindow  
wrappers around Carbon windows?


The problem is, my Plugin is written using cocoa, but runs within a  
Carbon application. I need to attach my NSOpen/NSSave panels onto a  
given application window, which is, of course, a Carbon window. I  
get this bogus behavior and even worse, both running with my Host  
application, and with simplistic test programs like the one below.


Any hints?
Last (and most important) - Supposedly I use your nice category  
like this:


WindowRef frontWin = ::FrontWindow();  // get Carbon application
front window. Actually, any carbon window.
NSWindow *cocoaFromCarbonWin = [[NSWindow alloc]  
initWithWindowRef:frontWin];

NSSavePanel *navPanel = [NSSavePanel savePanel];
[navPanel runModalForDirectory:nil file:nil types:nil  
relativeToWindow: cocoaFromCarbonWin];


Then I'm seeing a host of strange and bogus behaviors.

1. The most severe is that the sheet opens BEHIND the application
window, BUT is still the key window. So, the application is dead
--- I can't click on the sheet (it's not front, and not active,
does not respond to clicks). However, the main application window
is blocked for events too! (I have blocked it via
runModalForWindow!). so, I'm dead. User must force-quit the
application.

2. The sheet opens in the wrong place -- just somewhere on the
screen - not always the same place, but "favorably" when a centered
dialog would appear. If then I try to drag the parent carbon window
by its title, the sheet would "jump into place" and be dragged
right. Events seem to be OK.

3. The sheet is invisible --- Although I get no errors from the
application. However, the debugger console would (sometimes!)
contain lines like this:

[Session started at 2009-10-21 11:01:52 +0200.]
GNU gdb 6.3.50-20050815 (Apple version gdb-1346) (Fri Sep 18   
20:40:51 UTC 2009)
Wed Oct 21 12:11:53 Moti-Schneors-Mac-Pro.local NavTester[4398]   
: kCGErrorIllegalArgument: _CGSFindSharedWindow: WID 1835
Wed Oct 21 12:11:53 Moti-Schneors-Mac-Pro.local NavTester[4398]   
: kCGErrorFailure: Set a breakpoint @ CGErrorBreakpoint()  
to catch errors as they are logged.
Wed Oct 21 12:11:53 Moti-Schneors-Mac-Pro.local NavTester[4398]   
: kCGErrorIllegalArgument: CGSOrderWindowListWithGroups:  
invalid window ID (1835)
Wed Oct 21 12:11:53 Moti-Schneors-Mac-Pro.local NavTester[4398]   
: kCGErrorIllegalArgument: CGSOrderWindowList: NULL list  
pointer or empty list
Wed Oct 21 12:11:53 Moti-Schneors-Mac-Pro.local NavTester[4398]   
: kCGErrorIllegalArgument: _CGSFindSharedWindow: WID 1836
Wed Oct 21 12:11:53 Moti-Schneors-Mac-Pro.local NavTester[4398]   
: kCGErrorIllegalArgument: CGSOrderWindowListWithGroups:  
invalid window ID (1836)
Wed Oct 21 12:11:53 Moti-Schneors-Mac-Pro.local NavTester[4398]   
: kCGErrorIllegalArgument: CGSOrderWindowList: NULL list  
pointer or empty list


Any ideas? something I forgot to do? What in general is the state
of opening cocoa-sheets over Carbon-windows? When do I need to
release this NSWindow? I don't wish to close the Carbon window, as
it is coming from my host application!


You may not want to call FrontWindow() since its docs say, "Most
applications should use call ActiveNonFloatingWindow or
FrontNonFloatingWindow instead of FrontWindow because
ActiveNonFloatingWindow and FrontNonFloatingWindow return the active
and frontmost document window, respectively, skipping over other
types of windows that may be in front of the active document, such as
the menubar window, floating windows, help tags and toolbars."


___

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

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

Help/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: stringWithContentsOfURL with resulting error 256

2009-10-22 Thread Jens Alfke


On Oct 22, 2009, at 7:16 AM, James Lin wrote:

NSString *result = [NSString stringWithContentsOfURL:theURL  
encoding:NSUTF8StringEncoding error:&error];

However, the result comes back with an NSError as the following:
Error Domain=NSCocoaErrorDomain Code=256 UserInfo=0x15d7b0  
"Operation could not be completed. (Cocoa error 256.)

which is a NSFileReadUnknownError = 256.
BUT! The same URL string works perfectly in a Safari window and the  
PHP script executes fine when accessed from Safari...


That's a weird error I haven't seen before — looks like a generic  
"duh, something went wrong" fallback.


My first guess is that NSString can't decode the URL response into a  
string due to encoding issues; maybe the content uses an encoding  
that's incompatible with UTF-8? I would start trying lower-level calls  
to find the point where it starts to work.

-[NSString stringWithContentsOfURL:usedEncoding:error:]
-[NSData dataWithContentsOfURL:...]
-[NSURLConnection sendSynchronousRequest:...]

Note that in most cases you don't want to use this type of synchronous  
call on a remote URL because it blocks the thread for an arbitrary  
amount of time. The usual Cocoa style is to use an asynchronous  
request via NSURLRequest.


—Jens___

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

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

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

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


Re: Sending a Selector to another Class.

2009-10-22 Thread Bill Bumgarner

On Oct 22, 2009, at 5:54 AM, Jim Kang wrote:

> However, a selector is not a string. I was just listening to this podcast
> with Mike Ash, and he discusses this around the 9:23 mark or so:
> 
> http://podcast.mobileorchard.com/episode-23-mike-ash-on-the-objective-c-runtime-objects-and-the-runtime-message-sending-and-no-such-method/
> 
> He explains that comparing strings is too slow for the runtime to use for
> finding messages and so it uses integers to represent the messages and calls
> them selectors.

Selectors are strings, but it is an implementation detail.

The runtime uniques the strings such that there is only ever one instance of, 
say, the "drawRect:" selector floating about.  Thus, the runtime can use 
pointer comparison to determine selector equality.

It is an implementation detail though.  One that is exceedingly unlikely to 
ever change but, still, an implementation detail.

Use the Objective-C runtime API if you want to do selector comparison.

sel_isEqual(), IIRC.

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: NSTextField not getting mouseDown

2009-10-22 Thread Jens Alfke


On Oct 22, 2009, at 7:08 AM, Sander Stoks wrote:

But: if I cause editing to end by pressing the Enter key (instead of  
Tab), and then give another window the focus, clicking on the  
textfield doesn't cause a mouseDown to be receive anymore.  The  
contents of the textfield stay selected (the focus ring is, of  
course, gone).


Probably because the textfield is still the window's first responder  
(even though the window isn't key). In that situation there's an  
NSTextView overlaid on the text field, which actually does the  
editing, so clicks go to the text view instead of the field itself.


—Jens

___

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

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

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

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


Re: Sending a Selector to another Class.

2009-10-22 Thread Jens Alfke

On Oct 22, 2009, at 5:54 AM, Jim Kang wrote:

However, a selector is not a string. I was just listening to this  
podcast

with Mike Ash, and he discusses this around the 9:23 mark or so:

http://podcast.mobileorchard.com/episode-23-mike-ash-on-the-objective-c-runtime-objects-and-the-runtime-message-sending-and-no-such-method/

He explains that comparing strings is too slow for the runtime to  
use for
finding messages and so it uses integers to represent the messages  
and calls

them selectors.


This statement is true; however those integers happen to be the memory  
addresses of unique instances of the strings*. This makes it very  
efficient for the runtime to convert a selector to an NSString, and  
vice versa, and also helps with debugging (in gdb you can just type  
"print (char*)sel" to inspect a selector.)


—Jens

* C strings, not NSStrings.___

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

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

Help/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 a Selector to another Class.

2009-10-22 Thread Kyle Sluder

On Oct 22, 2009, at 9:01 AM, Jens Alfke  wrote:

This statement is true; however those integers happen to be the  
memory addresses of unique instances of the strings*. This makes it  
very efficient for the runtime to convert a selector to an NSString,  
and vice versa, and also helps with debugging (in gdb you can just  
type "print (char*)sel" to inspect a selector.)


Don't forget NSStringFromSelector, which I find is usually more  
convenient and doesn't rely on implementation details. Invoke it in  
GDB by casting its return value to id:


po (id)NSStringFromSelector(_cmd)

(Although I have noticed that gdb is much better about inferring when  
it can expect an object return value from a function/method call).


--Kyle Sluder
___

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

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

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

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


Re: Sending a Selector to another Class.

2009-10-22 Thread Jeff Johnson

On Oct 22, 2009, at 10:53 AM, Bill Bumgarner wrote:


Selectors are strings, but it is an implementation detail.

The runtime uniques the strings such that there is only ever one  
instance of, say, the "drawRect:" selector floating about.  Thus,  
the runtime can use pointer comparison to determine selector equality.


It is an implementation detail though.  One that is exceedingly  
unlikely to ever change but, still, an implementation detail.


Use the Objective-C runtime API if you want to do selector comparison.

sel_isEqual(), IIRC.

b.bum


http://twitter.com/gparker/status/2400099786

"Ignore bbum. We hereby promise never to break == for SEL. (But SEL is  
not char*. We will break that.)"


And now that it's on the mailing lists, it can be considered part of  
Apple's official documentation. ;-)


-Jeff

___

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

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

Help/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-dev Digest, Vol 6, Issue 1522

2009-10-22 Thread Greg Guerin

Ashley Perrien wrote:


uint8_t *readBuffer;
NSUInteger bufferLength;
BOOL gotBuffer = [readStream getBuffer: &readBuffer length:  
&bufferLength];


if (gotBuffer) {
int len = [readStream read: readBuffer maxLength: bufferLength];
if (len <= 0)
NSLog(@"nothing read");
else
NSLog(@"Read: %@", [[[NSString alloc] initWithBytes: readBuffer  
length: bufferLength encoding:NSUTF8StringEncoding] autorelease]);

}
else {
NSLog(@"Did not get a buffer");
}
}
// Output: No Bytes , Did not get a buffer



This code is mis-designed.

First, if gotBuffer is YES, then the available data is already  
present in the returned-by-reference readBuffer.  Calling  
read:maxLength: will return the NEXT series of bytes.  It will block  
in doing this, unlike the non-blocking getBuffer:length: call.


Second, if you're expecting a buffer to be available immediately,  
your expectation is misplaced.  It takes time for the first packet to  
arrive and be processed.  If you call read:maxLength:, however, then  
that is a blocking method, and it will suspend the calling thread  
until sufficient data has arrived.


I agree with Jens Alfke: you should read the stream programming  
guide, and look at a working example.




I'm not entirely sure why you mention the null character.



I misread what you were doing with the data.  I thought it was being  
treated as a C string in UTF8 encoding.


  -- 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 a Selector to another Class.

2009-10-22 Thread mmalc Crawford

On Oct 22, 2009, at 9:54 am, Jeff Johnson wrote:

> "Ignore bbum. We hereby promise never to break == for SEL. (But SEL is not 
> char*. We will break that.)"
> And now that it's on the mailing lists, it can be considered part of Apple's 
> official documentation. ;-)
> 
It already is:



mmalc

___

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

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

Help/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: Search on Core data Table issue?

2009-10-22 Thread mmalc Crawford

On Oct 22, 2009, at 4:09 am, Matthew Lindfield Seager wrote:

> A "reducing search" is more commonly referred to as filtering. A
> google search should help you very quickly as this is very easy with
> core data & bindings.
> 
The question is related to iPhone and NSFetchedRestultsController, therefore 
desktop bindings are irrelevant.



On Oct 20, 2009, at 10:56 pm, Damien Cooke wrote:

> One of the big problems as I see it is going to be updating the interface to 
> let it know what to present.  I assume an alternative 
> NSFetchedResultsController needs to be sent to the UITableView.
> 
No, but that points along the right lines...

> So here are my issues:
> 1) I assume I need to create a  NSFetchedResultsController with only the 
> correct items in it then tell the UITableView to use this as the dataSource 
> and reload the table?
> 2) is there a better way than executing a full sorted fetch and removing 
> those objects that do not conform.  ie is there a way of doing a select where 
> type fetch?
> 
The fetched results controller is particularly well-suited to managing 
sectioned data. In a search results table, you don't have sections, and 
moreover your results set is pretty much guaranteed to change on every use, so 
incurring the overhead of storing the results is a waste.
Rather than using a fetched results controller, therefore, simply execute a 
standard fetch for at least the first search character, typically for 
subsequent characters you might do in-memory filtering of the first 
returned-array.

mmalc

___

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

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

Help/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: NSTextField not getting mouseDown

2009-10-22 Thread Sander Stoks


On Oct 22, 2009, at 4:17 PM, Graham Cox wrote:

What you want is to remove all this stuff and look at [NSPanel  
setBecomesKeyOnlyIfNeeded:] which deals with whatever is necessary  
for you. Standard text fields and so on should then work properly.


Duh.  That was indeed what I needed to do.  My stupidity lies in the  
fact that I had already tried this and didn't get it to work (and had  
thus decided to take a different approach), but that was because I had  
already overridden canBecomeKeyWindow to always return NO and had  
forgotten about that.


Thanks,
Sander
___

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

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

Help/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: stringWithContentsOfURL with resulting error 256

2009-10-22 Thread John Horigan
Try using curl (the command-line utility) to see _exactly_ what Cocoa  
gets from the server when it accesses that URL. The server could be  
doing something that confuses Cocoa but which PHP and Safari handle  
properly.


-- john

On Oct 22, 2009, at 8:52 AM, Jens Alfke wrote:



On Oct 22, 2009, at 7:16 AM, James Lin wrote:

NSString *result = [NSString stringWithContentsOfURL:theURL  
encoding:NSUTF8StringEncoding error:&error];

However, the result comes back with an NSError as the following:
Error Domain=NSCocoaErrorDomain Code=256 UserInfo=0x15d7b0  
"Operation could not be completed. (Cocoa error 256.)

which is a NSFileReadUnknownError = 256.
BUT! The same URL string works perfectly in a Safari window and the  
PHP script executes fine when accessed from Safari...


That's a weird error I haven't seen before — looks like a generic  
"duh, something went wrong" fallback.


My first guess is that NSString can't decode the URL response into a  
string due to encoding issues; maybe the content uses an encoding  
that's incompatible with UTF-8? I would start trying lower-level  
calls to find the point where it starts to work.

-[NSString stringWithContentsOfURL:usedEncoding:error:]
-[NSData dataWithContentsOfURL:...]
-[NSURLConnection sendSynchronousRequest:...]

Note that in most cases you don't want to use this type of  
synchronous call on a remote URL because it blocks the thread for an  
arbitrary amount of time. The usual Cocoa style is to use an  
asynchronous request via NSURLRequest.


—Jens___

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

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

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

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


Textured sheet with tabview

2009-10-22 Thread McLaughlin, Michael P.
Don't know if I did something wrong or this is a bug.  [Leopard + Xcode
3.1.3]

I thought I would make a (modal) sheet textured because it provided a nice
contrast with its non-textured parent window.  The sheet contains one
tabview and an OK button.  Each of four tabs contains a radio group (matrix)
as its only subview.  The sheet and views have their default attributes in
IB (apart from names and tags).

I found that, when I switch between tabs, the labels of the previous radio
buttons do not go away completely.  They leave a "ghost" behind that I can
easily see.

When I changed to a non-textured sheet, the problem seemed to go away
(unless these "ghosts" have too little contrast to be visible against a
lighter background).

Has anyone else observed this?

-- 
Mike McLaughlin

___

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

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

Help/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 design related question

2009-10-22 Thread Marc Rink

Hey Florijan!

Thanks for your guidance: TBQH, i already came along your described  
way: started out with the obvious "Hello World" stuff, playing around  
with IB and different techniques to deal with object's etc. Eg i  
already had a working version of a window with a popup box feeded from  
a MySQL table content (i will need this later on), i strayed accross  
Core Graphics to load a PNG, cut it into tiles and draw the tiles in a  
scroll view, etc.


I know that core data might be overkill for just storing the  
configuration info, but i need core data along the way (only with  
transient properties) so i figured it may be ok to handle everything  
in there.


Your hint with just creating a object controller in ConfigView did the  
trick! :) Sometimes you can't see the forest because of lots of trees  
standing in your view...


This means i need the ObjectController in every view i want to have  
access to the connection parameters.


However, i am now troubling around: I set the value Binding of the  
Textfield to the object Controllers.selection. in IB, however
i wont see the defaultvalue i have set in the model designer in Xcode.  
I already fiddled around with "Enabled" and "editable" bindings, but i  
didnt get it to work...?


Anyone able to point me in the right direction?

thanks
Marc


Am 22.10.2009 um 16:10 schrieb Stamenkovic Florijan:


Hi Marc,

On Oct 20, 2009, at 16:11, Marc Rink wrote:


Heyas,

I am quite new to Objective-C (and to some extend to OO concepts as  
well), so please be gentle with me :)


I have a core data based document application that purpose is to  
access a mysql database (i am using the MCP Kit).
The documents in my context are Views that contain different  
aspects of the database (small portions consisting of some tables  
related to each other).

One document contains the connection parameters for the database.

I am switching the views according to Aaron Hillegass' example  
using a view controller (the downloadable examples are http://www.bignerdranch.com/solutions/Cocoa-3rd.tgz) 
.


I want to achive the following:
Upon application start the first view "ConfigViewController" is  
shown. It contains all connection related parameters (such as host,  
port, user, password and database) and a "Connect" button.
Upon clicking the "Connect" button, the connection to the database  
is established. The result is a connection object, that i wanted to  
pass around the different Views.


First approach was to pass the resulting connection to the  
superclass of the view's (all my view's are derived from a custom  
superclass which extends NSViewController). For reasons i dont  
know, i didnt get this to work. The resulting object was invalid  
(nil) in the other view's.


Second approch (and better one imho) is to add a core data entity  
"DBConfiguration" holding all connection parameters (persistent, so  
you dont have to enter the stuff every time) and a transient  
property for the connection object (of type undefined).
I added a Object Controller to my documents xib file, set the mode  
to "Entity" and the entity name to "DBConfiguration".
My Problem now is: The view containing the textfields and the  
"connect" button are in a different xib file (ConfigView.xib, whose  
Files Owner is of Type "ConfigViewController". I dont know how to  
bind the ConfigView's text fields to the Object Controller in  
MyDocument.xib.


OK, this was a lot of info. What is your actual problem? Can't you  
simply make another object controller for DBConfig in ConfigView.xib?


Also note that CoreData is probably not the right solution for  
storing your connection info. From what you say the user defaults  
system seems much more appropriate.


I am still new to the different frameworks and unsure about whether  
my design is acceptable or if i am on a completely wrong way.


When taking on so much at once (as you claim to be inexperienced),  
it is almost guaranteed you are not doing things the right way.  
Still, your app seems quite complex and it does not make sense  
trying to explain it all when looking for a solution for a  
reasonably small problem. I am sure you'd get more answers if you  
put the question to the point.


Also, if you are really new to all of this stuff, this sounds like a  
big first step. Too big. Start with small, isolated functionalities  
and practice.


F


___

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

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

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

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


Re: Core data design related question

2009-10-22 Thread Stamenkovic Florijan


On Oct 22, 2009, at 15:46, Marc Rink wrote:

This means i need the ObjectController in every view i want to have  
access to the connection parameters.


Yep, that seems right.

However, i am now troubling around: I set the value Binding of the  
Textfield to the object Controllers.selection. in IB, however
i wont see the defaultvalue i have set in the model designer in  
Xcode. I already fiddled around with "Enabled" and "editable"  
bindings, but i didnt get it to work...?


Anyone able to point me in the right direction?


I am not sure exactly what should be happening as I never used an  
NSObjectController with CoreData fetching (normally use array and tree  
controllers). What gets fetched? One record? All records? No idea...  
However, this should all be fairly simple to track down...


1. Make sure your default value is actually getting set on new objects.
2. Check what the fetched content of the object controller is at the  
point in which you expect your connection info in it.

3. Check what the object controller's selection is at the same time.
...

This is one of those situations which should just work, unless you  
omit one of the myriad small steps necessary to get there. As such  
it's hard for anyone but you to find it. So check your assumptions one  
by one and experiment...


F
___

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

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

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

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


re: Search on Core data Table issue?

2009-10-22 Thread Ben Trumbull

Not sure if this is the right place (I am sure someone will let me
know if it is not)  I have a iPhone application that has a UITable
view that is backed by core data.  I want to perform a reducing search
so that only the items starting with the characters entered into the
search bar are shown.  This is normally done with delegate - (void)
searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)
searchText no problem.  I am a little confused as I am new to Core
Data how to do this.  One of the big problems as I see it is going to
be updating the interface to let it know what to present.  I assume an
alternative NSFetchedResultsController needs to be sent to the
UITableView.


You're basically on the right track.


So here are my issues:
1) I assume I need to create a  NSFetchedResultsController with only
the correct items in it then tell the UITableView to use this as the
dataSource and reload the table?


Yes.  Most of the Apple apps use an overlay, so it's also a different  
UITableView entirely.  See search in the Contacts app, for example.



2) is there a better way than executing a full sorted fetch and
removing those objects that do not conform.  ie is there a way of
doing a select where type fetch?


I'm not sure exactly what you mean by "select where type" fetch.  What  
type ?


The typical pattern is if the user typing has gone from a 0 length  
string to a 1 character string, you'll need to do a fetch.  (that  
includes the user deleting a character and starting over).  If the  
string already has 1 or more characters, you can choose between a new  
fetch, or simply an in memory filter of the previous results.  The  
results should always be sorted, so you can binary search the range to  
filter, instead of filtering all the strings.


The balance of when to fetch and when to filter is complicated, and  
depends on your data set, as well as your UI.  If you have an  
extremely large data set, you should use a fetch limit, so that the  
user cannot get back all the results until they've entered a  
sufficiently discriminating search string.  If the number of results  
you get back is equal to the fetch limit, you can consider executing a  
count request or just saying "and more...".


If the number of results is small, then it's much faster to filter the  
old results in memory.  Fetching will save you a lot of memory, but it  
is I/O so it has a high fixed cost (like ~2ms on a desktop).  You'll  
want to balance the two.  You might start out with a threshold of 100  
and tune from there.



Thanks in advance and sorry if this is a dumb question.


It's not.

- Ben

___

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

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

Help/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: NSScroller graphical lag/glitches

2009-10-22 Thread Dave Keck
I'd imagine those artifacts are due to you not drawing the scroller's
background. In -drawArrow:... and -drawKnobSlowInRect:..., you should:

  NSRectFillUsingOperation(rect, NSCompositeClear);
___

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

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

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

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


UITableView scrolling & keyboard

2009-10-22 Thread Bob Barnes

Hi all,

Apple's UICatalog sample iPhone app has a view demonstrating  
various styles of UITextFields and when one of the text fields is  
selected the table view scrolls the view if necessary to keep the  
chosen UITextField visible above the keyboard. I'd like to have the  
same capability in my table view, but the only way I can get the table  
to scroll the selected text field into view above the keyboard is to  
touch the table view outside one of the text fields first. The  
UICatalog code itself is pretty trivial so I'm thinking it must be  
something that's being set in IB.


  I thought perhaps it was the "Show Selection on Touch" setting in  
IB, but unchecking it in IB doesn't change the behavior so I'm at a  
loss. What am I missing?


Bob
___

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

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

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

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


NSTextView is selectable even when selection is disabled

2009-10-22 Thread PCWiz
I have an NSTextView in a NSView (the prototype view of an  
NSCollectionViewItem), and the text view is bound to an  
NSAttributedString In interface builder both selectable and editable  
are disabled, however I can still select and edit the contents of the  
text view. What am I doing wrong?


Thanks
___

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

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

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

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


Help debugging "Dangling reference to an invalid object." Core Data error

2009-10-22 Thread Sean McBride
Hi all,

Core Data is giving me a validation error when I try to save a document
after making a simple change.

I have an entity 'Scene' with a to-many relationship to an entity
'Target'.  The inverse relationship is also to-many.  Both relationships
are optional and the delete rule for both sides is nullify.

To repro, I delete all Scenes then try to save.  It gives:

"Dangling reference to an invalid object." = ;
 NSAffectedObjectsErrorKey = (
   (entity: Scene; id: 0x2004f32a0  ; ...

This error gives only 4 hits with Google. :(

The problem is that some Targets still have relationships to some
Scenes!  How can that happen?  It seems like the delete rule is not
doing its job.

I've confirmed that each Scene receives prepareForDeletion.  None of the
Scenes are finalized, they are all strongly referenced by the moc's
_deletedObjects ivar.

Any advice on how to debug this?

(I can repro this with 2 customer-provided documents, but I've not been
able to create a document with this problem myself.  Happens on 10.5.8
and 10.6.1; my app is garbage collected.)

Thanks,

--

Sean McBride, B. Eng s...@rogue-research.com
Rogue Researchwww.rogue-research.com
Mac Software Developer  Montréal, Québec, Canada


___

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

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

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

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


Professional Error Handling

2009-10-22 Thread Squ Aire

As my code base grows I'm starting to think there something wrong  with my 
error handling code. The following is my current error handling method:


MODEL OBJECTS:

I do methods in my MODEL objects, that could result in an error, like any 
normal person would, namely to have the famous "NSError **anError" parameter. 
Two kinds of methods fall under this:

1) The error is a result of an error thrown by the Cocoa methods themselves. 
This is a simple case and is handled simply by doing "anError = 
theErrorFromTheCocoaObject" and returning either nil or NO from one's method. 
I'm confident I'm doing nothing wrong here.

2) The error is originated in my own code. This case I'm unsure of. The way I 
do it currently is something like this:
NSString *desc = @"Unable to set up image view.";
NSString *info = @"Image does not exist at the specified path.";
NSDictionary *d = [NSDictionary dictionaryWithObjectsAndKeys:
                   desc,NSLocalizedDescriptionKey, 
                  info,NSLocalizedFailureReasonErrorKey,nil];
*anError = [NSError errorWithDomain:@"com.mycompany.GreatApp.ErrorDomain" 
code:43 userInfo:d];

And then of course return NO or nil from the method. Is this how the 
professionals would do it? The first, and only obvious, problem I can see with 
this is that I'm putting a magic number 43 in there. I determine this magic 
number by doing a manual project find for "GreatApp.ErrorDomain" and adding one 
to the greatest error number that already exists. The second problem is of the 
error domain string. To me it currently feels like good enough to just have one 
error domain for the whole app since the app is not huge. The only question is 
where on earth I would put a constant for that string. I have no idea, since 
this string can occur in various model objects, so I just manually copy-paste 
this string every time it's needed.



CONTROLLER OBJECTS:

3) This is where I actually act on the errors that occur when model objects are 
called. In this case I simply do an [NSApp presentError:anError]; and then 
occasionally an [NSApp terminate:self]; in cases when the error occurs, for 
example, while the app is launching. Moreover, I tend to throw in NSLog(@"some 
description of where and why the error occurred.\n" @"Error: %...@\n" 
@"UserInfo: %@", error, [error userInfo]); Do you think this is unnecessary? My 
thinking was that maybe it's a good idea since I could ask the user to send me 
his or her logs in case he or she reported a problem to me one day. I might be 
wrong though.


So, I believe that 1) and 3) are all-in-all fairly good, except I'm unsure 
about the NSLogs in 3). I also sense some use for reusable helpers methods I 
could call in 1) and 3) to avoid repetition. Would you do that? Finally, I 
sense some serious flaws in 2). I need some advice about it. All other advice, 
and even descriptions of how pro coders do this kind of stuff, would be very 
appreciated.
  
_
Windows Live: Friends get your Flickr, Yelp, and Digg updates when they e-mail 
you.
http://www.microsoft.com/middleeast/windows/windowslive/see-it-in-action/social-network-basics.aspx?ocid=PID23461::T:WLMTAGL:ON:WL:en-xm:SI_SB_3:092010___

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

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

Help/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: NSTextView is selectable even when selection is disabled

2009-10-22 Thread Dave Keck
"Conditionally Sets Editable"?
___

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

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

Help/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: Professional Error Handling

2009-10-22 Thread Bryan Henry
Regarding your second case specifically, I usually define an error  
domain and error codes using an extern NSString* const plus an enum on  
a per-class basis.


// This for the header
extern NSString *const ExpressionProcessorErrorDomain;
enum {
  EPUnmatchedParenthesesError   = 21,
  EPRadixPointOnlyError = 22,
  EPSuccessiveOperatorsError= 23,
  EPSuccessiveRadixPointsError  = 24,
  EPSuccessiveNegativeSignsError= 25,
  EPOperatorAtExpressionStartError  = 26,
  EPOperatorAtExpressionEndError= 27,
  EPInvalidExponentialError = 28,
  EPInvalidPowerOfUnitError = 29,
  EPInvalidPlaceholderIndexError= 30,
  EPInvalidPlaceholderObjectError   = 31
};

// And adding, of course, the value of ExpressionProcessorErrorDomain  
in the .m file
NSString *const ExpressionProcessorErrorDomain =  
@"ExpressionProcessorErrorDomain";


I'm not sure whether this is a Cocoa convention or not, or whether a  
convention exists, but this is what I use to ensure that my domains  
are consistent and that error codes are self-documenting (at least in  
the code) as well as ensuring that error code duplication doesn't occur.


- Bryan

On Oct 22, 2009, at 7:40:46 PM, Squ Aire wrote:

2) The error is originated in my own code. This case I'm unsure of.  
The way I do it currently is something like this:

NSString *desc = @"Unable to set up image view.";
NSString *info = @"Image does not exist at the specified path.";
NSDictionary *d = [NSDictionary dictionaryWithObjectsAndKeys:
   desc,NSLocalizedDescriptionKey,
  info,NSLocalizedFailureReasonErrorKey,nil];
*anError = [NSError  
errorWithDomain:@"com.mycompany.GreatApp.ErrorDomain" code:43  
userInfo:d];


And then of course return NO or nil from the method. Is this how the  
professionals would do it? The first, and only obvious, problem I  
can see with this is that I'm putting a magic number 43 in there. I  
determine this magic number by doing a manual project find for  
"GreatApp.ErrorDomain" and adding one to the greatest error number  
that already exists. The second problem is of the error domain  
string. To me it currently feels like good enough to just have one  
error domain for the whole app since the app is not huge. The only  
question is where on earth I would put a constant for that string. I  
have no idea, since this string can occur in various model objects,  
so I just manually copy-paste this string every time it's needed.


___

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

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

Help/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: Professional Error Handling

2009-10-22 Thread Jens Alfke


On Oct 22, 2009, at 4:40 PM, Squ Aire wrote:

And then of course return NO or nil from the method. Is this how the  
professionals would do it?


Basically, although I have a utility function that does most of the  
work, so I don't have to dump ten lines of boilerplate into my code  
every time there's a possible error.


The first, and only obvious, problem I can see with this is that I'm  
putting a magic number 43 in there. I determine this magic number by  
doing a manual project find for "GreatApp.ErrorDomain" and adding  
one to the greatest error number that already exists.


This is what C's 'enum' is for. Create a header file, like "Errors.h"  
and define all your error codes in it:

enum {
kErrFoo = 1,
kErrBar,
kErrZog,
kErrLOL
};
Then just #import this header in any source file where you need to  
create an error, and refer to the error code by its constant.
When you need to define a new error code, just add it to the end of  
the list.


The second problem is of the error domain string. To me it currently  
feels like good enough to just have one error domain for the whole  
app since the app is not huge. The only question is where on earth I  
would put a constant for that string.


It goes in this header too :)

—Jens

___

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

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

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

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


Re: Help debugging "Dangling reference to an invalid object." Core Data error

2009-10-22 Thread Melissa J. Turner

On Oct 22, 2009, at 16:26, Sean McBride wrote:

> Hi all,
> 
> Core Data is giving me a validation error when I try to save a document
> after making a simple change.
> 
> I have an entity 'Scene' with a to-many relationship to an entity
> 'Target'.  The inverse relationship is also to-many.  Both relationships
> are optional and the delete rule for both sides is nullify.
> 
> To repro, I delete all Scenes then try to save.  It gives:
> 
> "Dangling reference to an invalid object." = ;
> NSAffectedObjectsErrorKey = (
>   (entity: Scene; id: 0x2004f32a0  FCE3E0E3-F187-4C44-BFC3-60D7AF3E579F/Scene/p343> ; ...
> 
> This error gives only 4 hits with Google. :(
> 
> The problem is that some Targets still have relationships to some
> Scenes!  How can that happen?  It seems like the delete rule is not
> doing its job.
> 
> I've confirmed that each Scene receives prepareForDeletion.  None of the
> Scenes are finalized, they are all strongly referenced by the moc's
> _deletedObjects ivar.
> 
> Any advice on how to debug this?
> 
> (I can repro this with 2 customer-provided documents, but I've not been
> able to create a document with this problem myself.  Happens on 10.5.8
> and 10.6.1; my app is garbage collected.)
> 


Does the object with the ID 
 exist in the 
affected store? What happens when you call existingObjectWithID:error:? 

Do you know what version of the OS the bad documents were created on? A lot 
changed in the relationship handling area in 10.6 (for the better, really and 
truly ;-), so knowing whether your customers created them on 10.5.x or 10.6.x 
would help narrow down the possibilities.

+Melissa


___

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

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

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

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


[SOLVED] Re: Displaying a view modally

2009-10-22 Thread Mike Manzano
Actually, I solved it myself, but it was similar to the solution you  
pointed me to. Thanks!


The promo code is yours if you want it (it's a US promo code). Just  
email me at m...@instantvoodoomagic.com.


Regards,

Mike


On Oct 21, 2009, at 5:54 PM, Saurabh Sharan wrote:

Check out SFHudView by Buzz Andersen (http://github.com/ldandersen/scifihifi-iphone/blob/master/UI/SFHFHUDView.h 
)


Saurabh

On Tue, Oct 20, 2009 at 5:26 PM, Mike Manzano > wrote:

Hi,

I'd like to display a busy indicator view (HUD) regardless of  
whatever view is currently at the top of the view stack. I'd also  
like this view to display modally so that the user interface beneath  
it is dead to touch events. This is like Tweetie 2's HUD that  
appears when you've successfully posted something to Instapaper,  
with the difference that the UI underneath it wouldn't accept events  
as they do in Tweetie 2. I'd also like to have some control over  
animating the HUD onto and off of the screen.


My current thinking is to find the topmost view controller somehow  
and send it presentModalViewController:animated:. However, I don't  
know how much control over animation I'd get with that method as the  
built-in animation styles sort of assume a full screen view. Also,  
I've never tried to use this method with a view that's smaller than  
the screen size.


Another thought is to just add the view to the root view and bring  
it to the top (this however won't make the view modal as the views  
below will still respond to touch events).


Can anyone tell me if I'm thinking along the right directions? I'd  
like to have some confirmation before I invest a bunch of time only  
to find out it's the wrong method.


Thanks,

Mike Manzano
mike (at) instantvoodoomagic (dot) com
http://instantvoodoomagic.com
@instantvoodoo

Oh BTW, the first reply that gets me closer to a solution gets a  
free promo code for Newsie (http://instantvoodoomagic.com/newsie),  
the Google Reader client for iPhone/iPod touch that I just released ;)



___

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

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

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/saurabh.sharan%40isharan.com

This email sent to saurabh.sha...@isharan.com



Mike Manzano
mike (at) instantvoodoomagic (dot) com
@instantvoodoo
(206) 462-2966



___

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

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

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

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


The "correct" approach? Question about creating an NSMutableDictionary instance.

2009-10-22 Thread Michael de Haan


Let me start by saying I **think** I understand why my first approach  
did not work, but am interested if my working approach is correct in  
concept.


Background.
As a **very long** detour from Hillegass's chapter 18 challenge, I am  
following along with mmalc's excellent series of Binding examples.  
Thus, now creating a table of 4 columns without bindings. (He uses 1  
column, but I added a few).



In order to create the NSMutableDictionary object, which will be added  
to an NSDoc Array ivar, (which will be used by the datasource methods  
of a table) I have created a


Record Object with one ivar (  _record ( An NSMutableDictionary).)

which returns:

First approach: ( did **not** work)

-(id) init
{
  self = snip...usual code
   NSString * _name = @"John Doe";
   NSString *  _city
   snip...other string properties


  _record = [ NSMutableDictionary dictionaryWithObjectsAndKeys:
   _name, MDHNameKey,
   snip...
  nil;
}
  return self;
}


As I learnt, self returns an empty object. ( If I understand it  
correctly, the local variables _name etc are no longer in scope once  
self is returned.)



Second approach.

Record Object with 4 ivars viz
_name
_city etc etc


Self now returns an object whose attributes are now, in the calling  
method ( the "AddRecord")  used to create the NSMutableDictionary  
object and added  "model" array, and the table populates as expected.



May I ask if this is the correct approach? ...or should one still try  
and aim to **return** a dictionary object to the calling method?


Thanks as always, in advance.







___

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

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

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

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


Re: The "correct" approach? Question about creating an NSMutableDictionary instance.

2009-10-22 Thread Graham Cox


On 23/10/2009, at 12:27 PM, Michael de Haan wrote:



Let me start by saying I **think** I understand why my first  
approach did not work, but am interested if my working approach is  
correct in concept.


Background.
As a **very long** detour from Hillegass's chapter 18 challenge, I  
am following along with mmalc's excellent series of Binding  
examples. Thus, now creating a table of 4 columns without bindings.  
(He uses 1 column, but I added a few).



In order to create the NSMutableDictionary object, which will be  
added to an NSDoc Array ivar, (which will be used by the datasource  
methods of a table) I have created a


Record Object with one ivar (  _record ( An NSMutableDictionary).)

which returns:

First approach: ( did **not** work)

-(id) init
{
 self = snip...usual code
  NSString * _name = @"John Doe";
  NSString *  _city
  snip...other string properties



OK, these are NOT "properties". They are simply local variables.  
(Also, don't snip code, it makes it really hard to tell whether what  
you've done is right, as you have to mentally put back what should be  
there - who knows if it matches what you actually have?)



 _record = [ NSMutableDictionary dictionaryWithObjectsAndKeys:
  _name, MDHNameKey,
  snip...
 nil;
   }
 return self;
}


As I learnt, self returns an empty object. ( If I understand it  
correctly, the local variables _name etc are no longer in scope once  
self is returned.)


This should not return an empty object, but it should return one  
having the ivar _record. One question is whether you're using garbage  
collection or not, because if not, then _record is shortly going to  
get autoreleased, leading to a stale reference and almost certain  
disaster (unless you've also snipped out vital memory management calls  
as well as the closing square bracket).


If you are truly getting an empty object, then you'll have to show all  
the code you've snipped to be able to say why.



Second approach.

Record Object with 4 ivars viz
_name
_city etc etc


Self now returns an object whose attributes are now, in the calling  
method ( the "AddRecord")  used to create the NSMutableDictionary  
object and added  "model" array, and the table populates as expected.


OK, read this about twenty times now and still have no clear idea what  
you mean. What mutable dictionary? Having done it this way, you no  
longer need one as far as I can see.


May I ask if this is the correct approach? ...or should one still  
try and aim to **return** a dictionary object to the calling method?


Personally I'd say your second approach is more usual. You *could*  
store your properties in a dictionary - this storage is an  
implementation detail of your record class. However it's usually  
easier just to have a separate ivar for each one, which is how the KVC  
system is typically implemented. If you exposed your 'record' property  
as a property in itself, you could access individual properties using  
a keypath such as yourObject.record.someKey, but typically you'd just  
want yourObject.someKey so that the implementation of the property  
storage is not exposed.


--Graham




___

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

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

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

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


Re: The "correct" approach? Question about creating an NSMutableDictionary instance.

2009-10-22 Thread Michael de Haan
Graham...firstly thank you. I certainly did not try and make it  
harder...I **thought** I was making it easier to present what I  
thought was the crux of the issue.  :-) So much for that thought!




On Oct 22, 2009, at 6:47 PM, Graham Cox wrote:



On 23/10/2009, at 12:27 PM, Michael de Haan wrote:


{
self = snip...usual code
 NSString * _name = @"John Doe";
 NSString *  _city
 snip...other string properties



OK, these are NOT "properties". They are simply local variables.



Point taken. My loose syntax did not correctly convey what I thought  
was happening.






_record = [ NSMutableDictionary dictionaryWithObjectsAndKeys:
 _name, MDHNameKey,
 snip...
nil;
  }
return self;
}


As I learnt, self returns an empty object. ( If I understand it  
correctly, the local variables _name etc are no longer in scope  
once self is returned.)


This should not return an empty object, but it should return one  
having the ivar _record. One question is whether you're using  
garbage collection or not, because if not, then _record is shortly  
going to get autoreleased, leading to a stale reference and almost  
certain disaster (unless you've also snipped out vital memory  
management calls as well as the closing square bracket).



Again, my lack of articulation/understanding. What I **meant** was  
that I could see an object created (in the debugger) in Record's init  
method. If I displayed this object in a log statement, it correctly  
wrote the   **local variables** to the console :-) If I did the same  
in the calling method, the object ( same value in the debugger) now  
did **not** write those local variables to the console. I incorrectly  
labeled this as "empty". To answer about GC, No. You, I think much  
more succinctly identified the issue that I was trying to convey.



If you are truly getting an empty object, then you'll have to show  
all the code you've snipped to be able to say why.



Second approach.

Record Object with 4 ivars viz
_name
_city etc etc


Self now returns an object whose attributes are now, in the calling  
method ( the "AddRecord")  used to create the NSMutableDictionary  
object and added  "model" array, and the table populates as expected.


OK, read this about twenty times now and still have no clear idea  
what you mean. What mutable dictionary? Having done it this way, you  
no longer need one as far as I can see.


In words, ( also tried to do it diagrammatically...see below)
In the dataSource object ( which in this case is a doc subclass) I  
have declared an array as an Ivar ( I called it "_record_list"). To  
this array, I added the object created in the AddRecord method of the  
doc object. That object is the NSMutableDictionary Object, (which uses  
the returned object from the Record Class init method).


So, ( and I hope this comes out)

So  ---> AddRecord (in doc class) ---> init ( Record Class)

|

|

|

   ↓
  
Record_object ( with 4 values ) ---> Returned to AddRecord Method  
---> Used to create NSMutableDictionary Object -> Added to  
Doc Array--> Used by TableView as source of display in  
tableView.





May I ask if this is the correct approach? ...or should one still  
try and aim to **return** a dictionary object to the calling method?


Personally I'd say your second approach is more usual. You *could*  
store your properties in a dictionary - this storage is an  
implementation detail of your record class. However it's usually  
easier just to have a separate ivar for each one, which is how the  
KVC system is typically implemented. If you exposed your 'record'  
property as a property in itself, you could access individual  
properties using a keypath such as yourObject.record.someKey, but  
typically you'd just want yourObject.someKey so that the  
implementation of the property storage is not exposed.





Thanks Grahamyour input is always very valuable in my quest  
through Hillegass.


___

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

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

Help/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 "correct" approach? Question about creating an NSMutableDictionary instance.

2009-10-22 Thread Graham Cox


On 23/10/2009, at 1:15 PM, Michael de Haan wrote:


In words, ( also tried to do it diagrammatically...see below)
In the dataSource object ( which in this case is a doc subclass) I  
have declared an array as an Ivar ( I called it "_record_list"). To  
this array, I added the object created in the AddRecord method of  
the doc object. That object is the NSMutableDictionary Object,  
(which uses the returned object from the Record Class init method).


So, ( and I hope this comes out)

So  ---> AddRecord (in doc class) ---> init ( Record Class)

   |

   |

   |

  ↓
 
Record_object ( with 4 values ) ---> Returned to AddRecord Method  
---> Used to create NSMutableDictionary Object -> Added  
to Doc Array--> Used by TableView as source of display in  
tableView.





I'm still unclear why there is a (mutable) dictionary in here at all.  
There's no need to have one. The simplest design is an array of  
Record_objects, the table can populate itself perfectly well from that  
(provided the Record_object's properties are identified in the table,  
which they surely must be).


--Graham


___

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

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

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

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


Re: The "correct" approach? Question about creating an NSMutableDictionary instance.

2009-10-22 Thread Michael de Haan


On Oct 22, 2009, at 7:33 PM, Graham Cox wrote:


In words, ( also tried to do it diagrammatically...see below)
In the dataSource object ( which in this case is a doc subclass) I  
have declared an array as an Ivar ( I called it "_record_list"). To  
this array, I added the object created in the AddRecord method of  
the doc object. That object is the NSMutableDictionary Object,  
(which uses the returned object from the Record Class init method).


So, ( and I hope this comes out)

So  ---> AddRecord (in doc class) ---> init ( Record Class)

  |

  |

  |

 ↓

Record_object ( with 4 values ) ---> Returned to AddRecord Method  
---> Used to create NSMutableDictionary Object -> Added  
to Doc Array--> Used by TableView as source of display in  
tableView.










I'm still unclear why there is a (mutable) dictionary in here at  
all. There's no need to have one. The simplest design is an array of  
Record_objects, the table can populate itself perfectly well from  
that (provided the Record_object's properties are identified in the  
table, which they surely must be).



OK...I see what you are saying. I did not know I could do it that way  
ie simply add the object "Record" to the record_list. I had seen an  
example from the documentation which had sued this approach, so simply  
followed that example!  :-)


___

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

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

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

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


NSDate timeIntervalSinceNow problem

2009-10-22 Thread PCWiz
In an NSDictionary I have a key called "time" that contains an NSDate  
object. When I NSLog the NSDictionary the time object appears like this:


"time" = 2009-10-22 20:58:19 +;

So what I did was this:

// "myDict" represents the dictionary that contains the time key

NSDate *time = [myDict objectForKey:@"time"];
NSLog(@"%d", [time timeIntervalSinceNow]);

And the result is this:

2009-10-22 21:01:18.949 TestApplication[8263:a0f] -2097072

Not sure what's wrong here, I've taken a look at some examples and  
they seem to do the same thing.

___

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

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

Help/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: NSDate timeIntervalSinceNow problem

2009-10-22 Thread Stephen J. Butler
On Thu, Oct 22, 2009 at 10:06 PM, PCWiz  wrote:
> NSDate *time = [myDict objectForKey:@"time"];
> NSLog(@"%d", [time timeIntervalSinceNow]);
>
> And the result is this:
>
> 2009-10-22 21:01:18.949 TestApplication[8263:a0f] -2097072
>
> Not sure what's wrong here, I've taken a look at some examples and they seem
> to do the same thing.

The method returns a NSTimeInterval, which is a double, but the %d
format is for integers.
___

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

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

Help/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: NSDate timeIntervalSinceNow problem

2009-10-22 Thread Kyle Sluder

On Oct 22, 2009, at 8:06 PM, PCWiz  wrote:


NSLog(@"%d", [time timeIntervalSinceNow]);


From NSDate.h:

typedef double NSTimeInterval;

You need a %f, not a %d.

--Kyle Sluder
___

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

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

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

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


Re: NSDate timeIntervalSinceNow problem

2009-10-22 Thread Sherm Pendley
On Thu, Oct 22, 2009 at 11:06 PM, PCWiz  wrote:
>
> NSDate *time = [myDict objectForKey:@"time"];
> NSLog(@"%d", [time timeIntervalSinceNow]);
>
> And the result is this:
>
> 2009-10-22 21:01:18.949 TestApplication[8263:a0f] -2097072
>
> Not sure what's wrong here, I've taken a look at some examples and they seem
> to do the same thing.

NSTimeInterval is a floating-point value, not an integer. You should
use %f to print it.

sherm--

-- 
Cocoa programming in Perl: http://camelbones.sourceforge.net
___

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

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

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

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


Re: NSDate timeIntervalSinceNow problem

2009-10-22 Thread Graham Cox


On 23/10/2009, at 2:06 PM, PCWiz wrote:


NSLog(@"%d", [time timeIntervalSinceNow]);

And the result is this:

2009-10-22 21:01:18.949 TestApplication[8263:a0f] -2097072

Not sure what's wrong here, I've taken a look at some examples and  
they seem to do the same thing.



[NSDate timeIntervalSinceNow]. What does it return?

Now what is that type an alias of?

And what format string specifier would you need to log it?

--Graham


___

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

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

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

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


Re: NSDate timeIntervalSinceNow problem

2009-10-22 Thread Graham Cox


On 23/10/2009, at 2:10 PM, Stephen J. Butler wrote:


The method returns a NSTimeInterval, which is a double, but the %d
format is for integers.



Awww, you spoiled the ending ;)

Make 'em work for it!

--Graham


___

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

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

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

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


Re: NSDate timeIntervalSinceNow problem

2009-10-22 Thread PCWiz

Tried using %f to log it instead of %d, but it gives me this:

2009-10-22 22:01:55.459 TestApplication[8629:a0f] -2160.459210

On 2009-10-22, at 9:13 PM, Graham Cox wrote:



On 23/10/2009, at 2:10 PM, Stephen J. Butler wrote:


The method returns a NSTimeInterval, which is a double, but the %d
format is for integers.



Awww, you spoiled the ending ;)

Make 'em work for it!

--Graham




___

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

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

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

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


Re: NSDate timeIntervalSinceNow problem

2009-10-22 Thread Graham Cox


On 23/10/2009, at 3:02 PM, PCWiz wrote:


Tried using %f to log it instead of %d, but it gives me this:

2009-10-22 22:01:55.459 TestApplication[8629:a0f] -2160.459210




What did you expect to see?

This reports that the date you've stored is 2160.45.. seconds earlier  
than now. Not unreasonable, is it?


--Graham


___

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

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

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

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


Re: NSDate timeIntervalSinceNow problem

2009-10-22 Thread PCWiz
Had a little brain freeze for a second :P the negative sign had me a  
bit confused, my eyes generally associate long numbers with a negative  
sign as bad. Thanks for the clarification.


On 2009-10-22, at 10:06 PM, Graham Cox  wrote:



On 23/10/2009, at 3:02 PM, PCWiz wrote:


Tried using %f to log it instead of %d, but it gives me this:

2009-10-22 22:01:55.459 TestApplication[8629:a0f] -2160.459210




What did you expect to see?

This reports that the date you've stored is 2160.45.. seconds  
earlier than now. Not unreasonable, is it?


--Graham



___

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

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

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

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


re: Help debugging "Dangling reference to an invalid object." Core Data error

2009-10-22 Thread Ben Trumbull
> Core Data is giving me a validation error when I try to save a document
> after making a simple change.
> 
> I have an entity 'Scene' with a to-many relationship to an entity
> 'Target'.  The inverse relationship is also to-many.  Both relationships
> are optional and the delete rule for both sides is nullify.
> 
> To repro, I delete all Scenes then try to save.  It gives:
> 
> "Dangling reference to an invalid object." = ;
> NSAffectedObjectsErrorKey = (
>   (entity: Scene; id: 0x2004f32a0  FCE3E0E3-F187-4C44-BFC3-60D7AF3E579F/Scene/p343> ; ...
> 
> This error gives only 4 hits with Google. :(
> 
> The problem is that some Targets still have relationships to some
> Scenes!  How can that happen?  It seems like the delete rule is not
> doing its job.

This error happens when the MOC for a destination object is nil, the object is 
in a relationship but marked deleted, or the object in a relationship has a 
temporary objectID but is not marked inserted.  Using 
refreshObject:mergeChanges:NO on an object with pending changes can do some of 
that, as can assigning a deleted object to new relationships after delete 
propagation has run.

- Ben



___

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

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

Help/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: Textured sheet with tabview

2009-10-22 Thread John Joyce
Don't know if I did something wrong or this is a bug.  [Leopard +  
Xcode

3.1.3]

I thought I would make a (modal) sheet textured because it provided  
a nice

contrast with its non-textured parent window.  The sheet contains one

Please review the HIG (human interface guidelines) in the docs.

This is a terrible design idea or apple would be doing it.
___

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

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

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

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