NSDateFormatter refuses to format dates

2011-09-27 Thread Gerriet M. Denkmann
The following code produces an empty string:

calender = [ [ NSCalendar autoupdatingCurrentCalendar ] retain ];
NSString *dateTemplate = @"eeeddHHmmss";
NSLocale *locale = [calender locale];   //  en_IE
NSString *dateFormat = [ NSDateFormatter dateFormatFromTemplate: 
dateTemplate  options:0  locale: locale ]; //  EEE dd   HH:mm:ss
dateFormatter = [ [ NSDateFormatter alloc ] initWithDateFormat: 
dateFormat allowNaturalLanguage: NO ];
[ dateFormatter setFormatterBehavior: NSDateFormatterBehavior10_4 ];
[ dateFormatter setLocale: locale ];
[ dateFormatter setGeneratesCalendarDates: YES ];
NSTimeZone *localTimeZone = [ calender timeZone ]; 
[ dateFormatter setTimeZone: localTimeZone ];
NSLog(@" now \"%@\"", [dateFormatter stringFromDate: [NSDate date]]);

What am I missing?

Kind regards,

Gerriet.

P.S. 10.7.1

___

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

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

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

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


Re: Questions about -orderFrontTablePanel:

2011-09-27 Thread Ulf Dunkel

Hi Andreas.


"NSTextView has built-in support for text tables, which provides the easiest way to 
add table support to your text view. This table support is in the form of the action 
method orderFrontTablePanel:. This method inserts a table into the text view and opens a 
modeless utility window that floats over the application windows. This table panel 
enables the user to manipulate attributes of a table while the cursor or selection is in 
the table."

So this behavior seems to be intentional. I guess your best bet is to file an 
enhancement request.


Thank you for pointing me to this. So I will file an enhancement request 
for the -orderFrontTablePanel: documentation and one for the function 
itself. I'd like to have it toggle its (predefined) menu string and 
show/hide its panel, like e.g. -orderFrontColorTable: does.


---Ulf Dunkel
___

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

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

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

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


Re: NSDateFormatter refuses to format dates

2011-09-27 Thread Fritz Anderson
On 27 Sep 2011, at 3:41 AM, Gerriet M. Denkmann wrote:

>   [ dateFormatter setGeneratesCalendarDates: YES ];
...
>   NSLog(@" now \"%@\"", [dateFormatter stringFromDate: [NSDate date]]);

NSCalendarDate is really most sincerely deprecated, and you're feeding the 
formatter an NSDate, not an NSCalendarDate. What happens if you set this to NO 
(or don't set it at all)?

In general, what happens if you temporarily remove the locale and time zone 
settings?

— 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: controller question

2011-09-27 Thread Keary Suska
On Sep 26, 2011, at 9:22 PM, Quincey Morris wrote:

> On Sep 26, 2011, at 19:03 , Ariel Feinerman wrote:
> 
>> if I use persistence NSMutableArray as content array in NSArrayController so
>> [arrayController setContent: m_array]; will controller copy one or retain?
> 
> The array controller will *observe* the array, not copy it.

I will take your word for how the controller is internally managing its content 
as I haven't inspected it, but although it is true that the controller should 
not copy the object (otherwise the docs should require that the content object 
conform to NSCopying), how the controller content is internally managed is not 
documented and shouldn't be relied on. Setting content is the same as setting 
any object property, and how the object is managed is no business of the setter.

>> So every deletion or addition in the controller will come back to origin.
> 
> Yes.

Again, this isn't guaranteed since it relies to how the controller may be 
managing its content.

>> Or we must synchronize one or get from controller to write to url?
> 
> No, you don't have to either of those things.
> 
> However, if you modify the array directly, you have to do it KVO compliantly, 
> or the array controller won't see the change.

Again, same issue. When not using bindings, you shouldn't rely on the behavior, 
even if it happens to work (for now)...

In sum, if you want synchronization without glue code, use bindings. If you 
don't need to manage the array outside of the controller you can retrieve the 
array contents when you need it as well...

HTH,

Keary Suska
Esoteritech, Inc.
"Demystifying technology for your home or business"

___

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

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

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

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


Re: NSDateFormatter refuses to format dates

2011-09-27 Thread Gerriet M. Denkmann

On 27 Sep 2011, at 21:39, Fritz Anderson wrote:

> On 27 Sep 2011, at 3:41 AM, Gerriet M. Denkmann wrote:
> 
>>  [ dateFormatter setGeneratesCalendarDates: YES ];
> ...
>>  NSLog(@" now \"%@\"", [dateFormatter stringFromDate: [NSDate date]]);
> 
> NSCalendarDate is really most sincerely deprecated, and you're feeding the 
> formatter an NSDate, not an NSCalendarDate. What happens if you set this to 
> NO (or don't set it at all)?

The line "... setGeneratesCalendarDates..." has no effect at all. It was just a 
frantic attempt to get it to work. Has long since been commented out.

> 
> In general, what happens if you temporarily remove the locale and time zone 
> settings?
The time zone settings have been already removed, because setting the locale 
also sets the time zone.

I have just commented out the line "[ dateFormatter setLocale: locale ]" as you 
suggested, but the result is still an empty string.

Kind regards,

Gerriet.

___

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

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

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

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


Re: NSDateFormatter refuses to format dates

2011-09-27 Thread glenn andreas

On Sep 27, 2011, at 9:53 AM, Gerriet M. Denkmann wrote:

>> 
>> In general, what happens if you temporarily remove the locale and time zone 
>> settings?
> The time zone settings have been already removed, because setting the locale 
> also sets the time zone.


NSLocale has no idea about time zones - the two are orthogonal.  NSLocale does 
know what NSCalendar to use (so doing setLocale: should mean that you don't 
need to do setCalendar:), but a given locale can have more than one time zone, 
and a single time zone can potentially cross multiple locales.

Not that that probably has a whole lot to do with NSDateFormatter returning 
empty strings...


Glenn Andreas  gandr...@gandreas.com 
The most merciful thing in the world ... is the inability of the human mind to 
correlate all its contents - HPL

___

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

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

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

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


Re: NSDateFormatter refuses to format dates

2011-09-27 Thread Gerriet M. Denkmann

On 27 Sep 2011, at 22:03, glenn andreas wrote:

> 
> On Sep 27, 2011, at 9:53 AM, Gerriet M. Denkmann wrote:
> 
>>> 
>>> In general, what happens if you temporarily remove the locale and time zone 
>>> settings?
>> The time zone settings have been already removed, because setting the locale 
>> also sets the time zone.
> 
> 
> NSLocale has no idea about time zones - the two are orthogonal.  NSLocale 
> does know what NSCalendar to use (so doing setLocale: should mean that you 
> don't need to do setCalendar:), but a given locale can have more than one 
> time zone, and a single time zone can potentially cross multiple locales.
> 
> Not that that probably has a whole lot to do with NSDateFormatter returning 
> empty strings...

The documentation says about dateStyles: "Do not use these constants if you 
want an exact format".

When I do: [ dateFormatter setDateStyle: NSDateFormatterFullStyle ]
it prints: "Tuesday 27 September 2011"
and when I add: [ dateFormatter setTimeStyle: NSDateFormatterFullStyle ]
it prints: "Tuesday 27 September 2011 23:18:16 Indochina Time"

Note that it was initialized with the dateFormat "EEE dd   HH:mm:ss"

All rather confusing - but at least I get some output.


The reason for using dateFormatter was that I needed:

NSArray *monthSymbols = [ dateFormatter monthSymbols ];
NSArray *shortWeekdaySymbols = [ dateFormatter shortWeekdaySymbols ];

Is there a more direct way to get at these localized strings, without a 
dateFormatter?
Maybe NSUserDefaults?


Kind regards,

Gerriet.

___

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

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

Help/Unsubscribe/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 : Undo Delete : Cannot fulfill a fault

2011-09-27 Thread Jerry Krinock

On 2011 Sep 26, at 11:57, Dave Fernandes wrote:

> Does the deleted object have relationships?

Yes.  The object is of entity Foo which are classic tree nodes.  There is a 
root Foo; Foo objects have to-one parents and to-many children, etc.

> What is the state of those objects?

It's always the same "exceptional" object which whose deletion is unable to be 
undone because Core Data could not fulfill a fault.  Its parent is an object 
that was not deleted and therefore does not need to be restored.  It has one 
child which has already been successfully restored at the time the exception 
occurs.

I now have an AppleScript which reproduces the problem.  The Core Data 
exception does not happen on every run, but on more than half.

___

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

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

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

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


Re: Why does Xcode define IBOutlet with @synthesize?

2011-09-27 Thread Matt Neuburg
On Fri, 23 Sep 2011 22:08:43 -0700, Jerry Krinock  said:

>Yes.  After studying this some more I see that, in older code, I did not 
>declare outlets as properties.  Instead, I put the IBOutlet directive on the 
>ivar,
>
>@interface MyWinCon : NSWindowController 
>{
>IBOutlet FooView *m_fooView ;
>}

I would just add (perhaps unnecessarily) that on iOS, where KVC is used, one 
should not be tempted to use a pure ivar instead of property + synthesized 
accessor, because when KVC sets an ivar directly it retains it and your whole 
memory management scheme can be thrown off. (This is just one of many reasons 
why direct KVC access to ivars is scary.) The property, with its declared 
memory management policy, and the synthesized accessor that implements that 
policy, acts as a memory management gateway to ward off KVC's curious and 
probably unwanted memory management behavior.

I don't remember whether there are similar memory management considerations on 
OS X, but presumably not. m.

--
matt neuburg, phd = m...@tidbits.com, 
A fool + a tool + an autorelease pool = cool!
Programming iOS 4!
http://www.apeth.net/matt/default.html#iosbook___

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

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

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

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


Re: Why does Xcode define IBOutlet with @synthesize?

2011-09-27 Thread David Duncan
On Sep 27, 2011, at 10:06 AM, Matt Neuburg wrote:

> On Fri, 23 Sep 2011 22:08:43 -0700, Jerry Krinock  said:
> 
>> Yes.  After studying this some more I see that, in older code, I did not 
>> declare outlets as properties.  Instead, I put the IBOutlet directive on the 
>> ivar,
>> 
>> @interface MyWinCon : NSWindowController 
>> {
>>   IBOutlet FooView *m_fooView ;
>> }
> 
> I would just add (perhaps unnecessarily) that on iOS, where KVC is used, one 
> should not be tempted to use a pure ivar instead of property + synthesized 
> accessor, because when KVC sets an ivar directly it retains it and your whole 
> memory management scheme can be thrown off. (This is just one of many reasons 
> why direct KVC access to ivars is scary.) The property, with its declared 
> memory management policy, and the synthesized accessor that implements that 
> policy, acts as a memory management gateway to ward off KVC's curious and 
> probably unwanted memory management behavior.
> 
> I don't remember whether there are similar memory management considerations 
> on OS X, but presumably not. m.


Anytime KVC must directly access an instance variable it does this (it maybe 
considered curious by some, but it is also the tactic that yields the least 
surprise – imagine if KVC set a value and it became invalid because there were 
no longer any owning references).

The reason why nib loading doesn't do this on Mac OS X is that nib loading 
there doesn't use KVC, but rather then Obj-C runtime directly.
--
David Duncan

___

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

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

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

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


Re: controller question

2011-09-27 Thread Quincey Morris
On Sep 27, 2011, at 07:40 , Keary Suska wrote:

> On Sep 26, 2011, at 9:22 PM, Quincey Morris wrote:
> 
>> On Sep 26, 2011, at 19:03 , Ariel Feinerman wrote:
>> 
>>> if I use persistence NSMutableArray as content array in NSArrayController so
>>> [arrayController setContent: m_array]; will controller copy one or retain?
>> 
>> The array controller will *observe* the array, not copy it.
> 
> I will take your word for how the controller is internally managing its 
> content as I haven't inspected it, but although it is true that the 
> controller should not copy the object (otherwise the docs should require that 
> the content object conform to NSCopying), how the controller content is 
> internally managed is not documented and shouldn't be relied on. Setting 
> content is the same as setting any object property, and how the object is 
> managed is no business of the setter.

Actually, I was using "observe" a bit loosely, because I didn't want to use 
"retain" in response to the question, because *that* would certainly be an 
implementation detail. I should have said that the array controller just keeps 
a reference to the array.

However, since part of an array controller's API contract is to track 
KVO-compliant changes to the content array, I'm pretty sure it *does* observe 
the object, and KVO-observe it too.

>>> So every deletion or addition in the controller will come back to origin.
>> 
>> Yes.
> 
> Again, this isn't guaranteed since it relies to how the controller may be 
> managing its content.

Every deletion ([NSArrayController removeObject…]) or addition 
([NSArrayController insertObject…] or [NSArrayController insertObject…]) *will* 
cause a corresponding deletion or addition in the content array, again by API 
contract. That's what I understood "come back to origin" to mean.

>>> Or we must synchronize one or get from controller to write to url?
>> 
>> No, you don't have to either of those things.
>> 
>> However, if you modify the array directly, you have to do it KVO 
>> compliantly, or the array controller won't see the change.
> 
> Again, same issue. When not using bindings, you shouldn't rely on the 
> behavior, even if it happens to work (for now)…

There are two facts that are well known, are unquestioningly used by many, many 
applications and are either explicitly or implicitly part of the array 
controller API contract.

1. Changing the data model array KVO compliantly *will* be reflected in the 
array controller (in 'selection', 'selectedObjects', 'arrangedObjects', etc).

2. Changing the content via the array controller *will* change the data model 
array KVO compliantly (so that other observers of the data model array will be 
notified).

Therefore, if you're about to write the data model array to some file at some 
URL, it isn't necessary to "get" anything from the array controller or to 
perform some synchronization operation first.

> In sum, if you want synchronization without glue code, use bindings. If you 
> don't need to manage the array outside of the controller you can retrieve the 
> array contents when you need it as well...

The point is that an array controller is a controller, not a collection. 
Conceptually it does *not* contain the objects in the content array; instead it 
*manages* the content array. Note that an array controller does not itself have 
an array property for the content. Its "content" property is an object 
property, not an array property. It certainly has some array properties of its 
own ('selectedObjects', 'arrangedObjects'), but these are derived properties 
that don't necessarily contain all of the content objects.


___

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

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

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

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


Re: controller question

2011-09-27 Thread Ariel Feinerman
Thank you for your letters. So it is good news. Do -insertObject: atIndex:,
-removeObject: or removeObjects: use KVO? I guess they do.

2011/9/27 Quincey Morris 

> On Sep 27, 2011, at 07:40 , Keary Suska wrote:
>
> On Sep 26, 2011, at 9:22 PM, Quincey Morris wrote:
>
> On Sep 26, 2011, at 19:03 , Ariel Feinerman wrote:
>
>
> if I use persistence NSMutableArray as content array in NSArrayController
> so
>
> [arrayController setContent: m_array]; will controller copy one or retain?
>
>
> The array controller will *observe* the array, not copy it.
>
>
> I will take your word for how the controller is internally managing its
> content as I haven't inspected it, but although it is true that the
> controller should not copy the object (otherwise the docs should require
> that the content object conform to NSCopying), how the controller content is
> internally managed is not documented and shouldn't be relied on. Setting
> content is the same as setting any object property, and how the object is
> managed is no business of the setter.
>
>
> Actually, I was using "observe" a bit loosely, because I didn't want to use
> "retain" in response to the question, because *that* would certainly be an
> implementation detail. I should have said that the array controller just
> keeps a reference to the array.
>
> However, since part of an array controller's API contract is to track
> KVO-compliant changes to the content array, I'm pretty sure it *does*
> observe the object, and KVO-observe it too.
>
> So every deletion or addition in the controller will come back to origin.
>
>
> Yes.
>
>
> Again, this isn't guaranteed since it relies to how the controller may be
> managing its content.
>
>
> Every deletion ([NSArrayController removeObject…]) or addition
> ([NSArrayController insertObject…] or [NSArrayController insertObject…])
> *will* cause a corresponding deletion or addition in the content array,
> again by API contract. That's what I understood "come back to origin" to
> mean.
>
> Or we must synchronize one or get from controller to write to url?
>
>
> No, you don't have to either of those things.
>
>
> However, if you modify the array directly, you have to do it KVO
> compliantly, or the array controller won't see the change.
>
>
> Again, same issue. When not using bindings, you shouldn't rely on the
> behavior, even if it happens to work (for now)…
>
>
> There are two facts that are well known, are unquestioningly used by many,
> many applications and are either explicitly or implicitly part of the array
> controller API contract.
>
> 1. Changing the data model array KVO compliantly *will* be reflected in the
> array controller (in 'selection', 'selectedObjects', 'arrangedObjects',
> etc).
>
> 2. Changing the content via the array controller *will* change the data
> model array KVO compliantly (so that other observers of the data model array
> will be notified).
>
> Therefore, if you're about to write the data model array to some file at
> some URL, it isn't necessary to "get" anything from the array controller or
> to perform some synchronization operation first.
>
> In sum, if you want synchronization without glue code, use bindings. If you
> don't need to manage the array outside of the controller you can retrieve
> the array contents when you need it as well...
>
>
> The point is that an array controller is a controller, not a collection.
> Conceptually it does *not* contain the objects in the content array; instead
> it *manages* the content array. Note that an array controller does not
> itself have an array property for the content. Its "content" property is an
> object property, not an array property. It certainly has some array
> properties of its own ('selectedObjects', 'arrangedObjects'), but these are
> derived properties that don't necessarily contain all of the content
> objects.
>
>
>


-- 
best regards
Ariel
___

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

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

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

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


Re: controller question

2011-09-27 Thread Kyle Sluder
Whoops, apparently only sent this to Quincey. So unfortunately, no
good news for you, Ariel. You need to either bind the controller's
contentArray binding, or manually set its contentObject property. The
insertion and removal methods on NSArray cannot possibly be
KVO-compliant because NSArray in its entirety is not KVO-compliant.

--Kyle Sluder


-- Forwarded message --
From: Kyle Sluder 
Date: Tue, Sep 27, 2011 at 10:47 AM
Subject: Re: controller question
To: Quincey Morris 


On Tue, Sep 27, 2011 at 10:29 AM, Quincey Morris
 wrote:
> However, since part of an array controller's API contract is to track 
> KVO-compliant changes to the content array, I'm pretty sure it *does* observe 
> the object, and KVO-observe it too.

You cannot KVO-observe an NSArray. -[NSArray
addObserver:forKeyPath:options:context:] is implemented to throw an
exception.

--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: controller question

2011-09-27 Thread Quincey Morris
On Sep 27, 2011, at 12:18 , Ariel Feinerman wrote:

> So it is good news. Do -insertObject: atIndex:, -removeObject: or 
> removeObjects: use KVO? I guess they do.

If you use these methods, you don't have to write any manual synchronization 
code. Your original array will contain the modified contents.

However, in your case ('setContent: m_array'), KVO isn't involved. Kyle sent me 
the following message off-list. I don't think he'll mind if I post it here, 
since the information reflects badly on me, not on him.

On Sep 27, 2011, at 10:47 , Kyle Sluder wrote:

> You cannot KVO-observe an NSArray. -[NSArray
> addObserver:forKeyPath:options:context:] is implemented to throw an
> exception.

Well, I thought I'd run out of stupid things to say about NSArrayController, 
but apparently I can still confuse myself.

As Kyle suggests, when you 'setContent:' on an array controller, it cannot 
observe the array because KVO doesn't allow it, and, there just isn't a way to 
update the array itself KVO compliantly. Under those circumstances, using the 
NSArrayController methods ('addObject…', 'removeObject…', 'insertObject…') will 
update the array properly, but updating the array directly won't cause the 
array controller to notice.

Oddly, when I wrote some code to check out a couple of details, I found that:

-- when the array controller is *bound* to its content array, its 'remove:' 
method works fine

-- when the array controller's "content" property is merely set to the content 
array, 'remove:' does nothing

In the second case, I had a document object with an IBOutlet to the array 
controller, and I set it up with [arrayController setContent: theArray]. When 
my deletion button action method looked like this:

- (IBAction) deleteIt: (id) sender {
[arrayController remove: sender];
}

nothing got deleted. (And, yes, I let the app go back to the main event loop 
before checking.)

When my deletion action method looked like this:

- (IBAction) deleteIt: (id) sender {
[arrayController removeObjects: [arrayController 
selectedObjects]];
}

the deletion worked fine. That's in spite of the fact that 'remove:' is 
documented to do what the second version does, though deferred to the next 
iteration of the run loop.

Maybe I made a stupid mistake, but it's a bit puzzling.


___

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

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

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

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


Re: Why does Xcode define IBOutlet with @synthesize?

2011-09-27 Thread Greg Parker
On Sep 27, 2011, at 10:06 AM, Matt Neuburg wrote:
> On Fri, 23 Sep 2011 22:08:43 -0700, Jerry Krinock  said:
>> Yes.  After studying this some more I see that, in older code, I did not 
>> declare outlets as properties.  Instead, I put the IBOutlet directive on the 
>> ivar,
>> 
>> @interface MyWinCon : NSWindowController 
>> {
>>   IBOutlet FooView *m_fooView ;
>> }
> 
> I would just add (perhaps unnecessarily) that on iOS, where KVC is used, one 
> should not be tempted to use a pure ivar instead of property + synthesized 
> accessor, because when KVC sets an ivar directly it retains it and your whole 
> memory management scheme can be thrown off. (This is just one of many reasons 
> why direct KVC access to ivars is scary.) The property, with its declared 
> memory management policy, and the synthesized accessor that implements that 
> policy, acts as a memory management gateway to ward off KVC's curious and 
> probably unwanted memory management behavior.

If you use ARC, that conflict goes away. KVC does the right thing with ARC weak 
or strong or unsafe-unretained ivars. KVC looks for ARC's ivar metadata and 
performs the same memory management as ARC would have.


-- 
Greg Parker gpar...@apple.com Runtime Wrangler


___

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

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

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

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


debugging crashes in dyld?

2011-09-27 Thread Martin Wierschin
Hello everyone,

I have a user reporting a crash whenever they try to first save a file. It is 
reproducible for the user (though not be me) and I'm wondering how to best 
debug this problem remotely. I've included the crash stack below (all other 
threads are waiting/trapped).

I'm no expert on dyld, but I suspect the crash is triggered when loading up 
some bundle code required by OSX's save panel (or perhaps some kind of 
installed system enhancer). I've discovered the environment variable 
DYLD_PRINT_LIBRARIES_POST_LAUNCH, which I'm hoping will help identify the 
relevant library. However, my fear is that this debugging aid logs each 
library's path only after each load completes successfully (ie: conceptually 
after the crash). If so, that obviously won't help me.

Thanks for any advice,

~Martin


> OS Version:  Mac OS X 10.6.8 (10K540)
...
> Exception Type:  EXC_BAD_ACCESS (SIGBUS)
> Exception Codes: KERN_PROTECTION_FAILURE at 0x000c
> Crashed Thread:  0  Dispatch queue: com.apple.main-thread
> 
> Thread 0 Crashed:  Dispatch queue: com.apple.main-thread
> 0   libobjc.A.dylib   0x942ce85b _cache_flush + 78
> 1   libobjc.A.dylib   0x942d17a5 flush_marked_caches + 242
> 2   libobjc.A.dylib   0x942cb18d _read_images + 2189
> 3   libobjc.A.dylib   0x942e0975 map_images_nolock + 1545
> 4   libobjc.A.dylib   0x942ca189 map_images + 72
> 5   dyld  0x8fe03f2d 
> dyld::notifyBatchPartial(dyld_image_states, bool, char const* 
> (*)(dyld_image_states, unsigned int, dyld_image_info const*)) + 795
> 6   dyld  0x8fe0dec9 
> ImageLoader::link(ImageLoader::LinkContext const&, bool, bool, 
> ImageLoader::RPathChain const&) + 251
> 7   dyld  0x8fe056af dyld::link(ImageLoader*, 
> bool, ImageLoader::RPathChain const&) + 137
> 8   dyld  0x8fe0b240 dlopen + 471
> 9   libSystem.B.dylib 0x936e02a8 dlopen + 66
> 10  com.apple.HIToolbox   0x9489d1c2 InitShortcut + 45
> 11  com.apple.HIToolbox   0x9489d0d1 
> SetupMenuTracking(MenuSelectData&, unsigned char, Point, double, MenuData*, 
> unsigned long, unsigned short, Rect const*, Rect const*, unsigned int, Rect 
> const*, __CFString const*) + 2964
> 12  com.apple.HIToolbox   0x9489c07d MenuSelectCore(MenuData*, 
> Point, double, unsigned long, OpaqueMenuRef**, unsigned short*) + 227
> 13  com.apple.HIToolbox   0x9489b8bb _HandleMenuSelection2 + 465
> 14  com.apple.HIToolbox   0x9489b6d9 _HandleMenuSelection + 53
> 15  com.apple.AppKit  0x9136ff96 _NSHandleCarbonMenuEvent + 
> 285
> 16  com.apple.AppKit  0x91344b46 _DPSNextEvent + 2304
> 17  com.apple.AppKit  0x91343dd6 -[NSApplication 
> nextEventMatchingMask:untilDate:inMode:dequeue:] + 156
> 18  com.apple.AppKit  0x913061f3 -[NSApplication run] + 821
> 19  com.apple.AppKit  0x912fe289 NSApplicationMain + 574
> 20  com.myAppIdentifier   0x330a _start + 216
> 21  com.myAppIdentifier   0x3231 start + 41
___

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

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

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

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


Re: Equivalent of UITextField's textField:shouldChangeCharactersInRange:replacementString for NSTextField

2011-09-27 Thread Eric Wing
On 9/21/11, Jens Alfke  wrote:
>
> On Sep 21, 2011, at 7:42 PM, Eric Wing wrote:
>
>> I have been using the delegate callback
>> textField:shouldChangeCharactersInRange:replacementString for
>> UITextField.
>> I am trying to port code over to Mac using NSTextField. Is there
>> something that provides similar functionality?
>
> Yes, but it’s a bit more complicated due to some rough edges in the AppKit
> API that got cleaned up in iOS. The delegate method you’re looking for is in
> NSTextView, which is the actual view used to manage editing in a focused
> NSTextField. Basically, you should read about “field editors” in the AppKit
> docs. You’ll want to give your text field a custom field editor and set
> yourself as its delegate.
>
> —Jens

Thanks for the info. That turned out to be a really long side quest.
Had to get into NSCell's and went into areas of NSSecureTextField that
I shouldn't have.

Anyway, I have my field editor mostly working, but I have one follow
up issue. I originally was using:
- (void) controlTextDidBeginEditing:(NSNotification*)notification
to get an event callback when the field begins editing.

It seems that once I added my custom field editor, I no longer get
this callback. Strangely, I still get the callback for:
- (void) controlTextDidEndEditing:(NSNotification*)notification

Is there something I can do to get that first callback back working
again, or is there a substitute? (Currently my workaround is to keep a
bool on my shouldChangeCharactersInRange: to know if I just started
editing, but I would like to know if there is something more elegant.)

Thanks,
Eric
-- 
Beginning iPhone Games Development
http://playcontrol.net/iphonegamebook/
___

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

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

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

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


Re: NSDateFormatter refuses to format dates

2011-09-27 Thread Vincent Spader

On Sep 27, 2011, at 1:41 AM, Gerriet M. Denkmann wrote:

> The following code produces an empty string:
> 
>   calender = [ [ NSCalendar autoupdatingCurrentCalendar ] retain ];
>   NSString *dateTemplate = @"eeeddHHmmss";
>   NSLocale *locale = [calender locale];   //  en_IE
>   NSString *dateFormat = [ NSDateFormatter dateFormatFromTemplate: 
> dateTemplate  options:0  locale: locale ]; //  EEE dd   
> HH:mm:ss
>   dateFormatter = [ [ NSDateFormatter alloc ] initWithDateFormat: 
> dateFormat allowNaturalLanguage: NO ];
>   [ dateFormatter setFormatterBehavior: NSDateFormatterBehavior10_4 ];
>   [ dateFormatter setLocale: locale ];
>   [ dateFormatter setGeneratesCalendarDates: YES ];
>   NSTimeZone *localTimeZone = [ calender timeZone ]; 
>   [ dateFormatter setTimeZone: localTimeZone ];
>   NSLog(@" now \"%@\"", [dateFormatter stringFromDate: [NSDate date]]);
> 
> What am I missing?
Creating an NSDateFormatter via -initWithDateFormat:allowNaturalLanguage: will 
create a 10.0 style date formatter. 10.0 and 10.4+ date formatters have 
completely different format strings, so when you call -setFormatterBehavior:, 
the format string may not stick around. Here's what you want:
dateFormatter = [ [ NSDateFormatter alloc ] init];
[dateFormatter setDateFormat:dateFormat];

and the setFormatterBehavior: call is no longer necessary. You can find more 
info in the "Formatting Behaviors and OS Versions" section of the 
NSDateFormatter reference.

--Vince

> 
> Kind regards,
> 
> Gerriet.
> 
> P.S. 10.7.1
> 
> ___
> 
> Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)
> 
> Please do not post admin requests or moderator comments to the list.
> Contact the moderators at cocoa-dev-admins(at)lists.apple.com
> 
> Help/Unsubscribe/Update your Subscription:
> http://lists.apple.com/mailman/options/cocoa-dev/spader%40apple.com
> 
> This email sent to spa...@apple.com

___

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

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

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

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


Re: debugging crashes in dyld?

2011-09-27 Thread Greg Parker
On Sep 27, 2011, at 2:06 PM, Martin Wierschin wrote:
> I have a user reporting a crash whenever they try to first save a file. It is 
> reproducible for the user (though not be me) and I'm wondering how to best 
> debug this problem remotely. I've included the crash stack below (all other 
> threads are waiting/trapped).
> 
> I'm no expert on dyld, but I suspect the crash is triggered when loading up 
> some bundle code required by OSX's save panel (or perhaps some kind of 
> installed system enhancer). I've discovered the environment variable 
> DYLD_PRINT_LIBRARIES_POST_LAUNCH, which I'm hoping will help identify the 
> relevant library. However, my fear is that this debugging aid logs each 
> library's path only after each load completes successfully (ie: conceptually 
> after the crash). If so, that obviously won't help me.
> 
>> OS Version:  Mac OS X 10.6.8 (10K540)
> ...
>> Exception Type:  EXC_BAD_ACCESS (SIGBUS)
>> Exception Codes: KERN_PROTECTION_FAILURE at 0x000c
>> Crashed Thread:  0  Dispatch queue: com.apple.main-thread
>> 
>> Thread 0 Crashed:  Dispatch queue: com.apple.main-thread
>> 0   libobjc.A.dylib  0x942ce85b _cache_flush + 78
>> 1   libobjc.A.dylib  0x942d17a5 flush_marked_caches + 242
>> 2   libobjc.A.dylib  0x942cb18d _read_images + 2189
>> 3   libobjc.A.dylib  0x942e0975 map_images_nolock + 1545
>> 4   libobjc.A.dylib  0x942ca189 map_images + 72
>> 5   dyld 0x8fe03f2d 
>> dyld::notifyBatchPartial(dyld_image_states, bool, char const* 
>> (*)(dyld_image_states, unsigned int, dyld_image_info const*)) + 795
>> 6   dyld 0x8fe0dec9 
>> ImageLoader::link(ImageLoader::LinkContext const&, bool, bool, 
>> ImageLoader::RPathChain const&) + 251
>> 7   dyld 0x8fe056af dyld::link(ImageLoader*, 
>> bool, ImageLoader::RPathChain const&) + 137
>> 8   dyld 0x8fe0b240 dlopen + 471
>> 9   libSystem.B.dylib0x936e02a8 dlopen + 66
>> 10  com.apple.HIToolbox  0x9489d1c2 InitShortcut + 45
>> 11  com.apple.HIToolbox  0x9489d0d1 
>> SetupMenuTracking(MenuSelectData&, unsigned char, Point, double, MenuData*, 
>> unsigned long, unsigned short, Rect const*, Rect const*, unsigned int, Rect 
>> const*, __CFString const*) + 2964
>> 12  com.apple.HIToolbox  0x9489c07d MenuSelectCore(MenuData*, 
>> Point, double, unsigned long, OpaqueMenuRef**, unsigned short*) + 227
>> 13  com.apple.HIToolbox  0x9489b8bb _HandleMenuSelection2 + 465
>> 14  com.apple.HIToolbox  0x9489b6d9 _HandleMenuSelection + 53
>> 15  com.apple.AppKit 0x9136ff96 _NSHandleCarbonMenuEvent + 
>> 285
>> 16  com.apple.AppKit 0x91344b46 _DPSNextEvent + 2304
>> 17  com.apple.AppKit 0x91343dd6 -[NSApplication 
>> nextEventMatchingMask:untilDate:inMode:dequeue:] + 156
>> 18  com.apple.AppKit 0x913061f3 -[NSApplication run] + 821
>> 19  com.apple.AppKit 0x912fe289 NSApplicationMain + 574
>> 20  com.myAppIdentifier  0x330a _start + 216
>> 21  com.myAppIdentifier  0x3231 start + 41

Crashes inside dyld or libobjc during library load often has one of two causes:
1. A library binary on disk or in the dyld shared cache is corrupted.
2. A memory error earlier in the app corrupted a data structure, and that data 
structure went unused until library load time.

This particular crash is manipulating objc's method caches, so #2 is more 
likely. If a memory smasher hits a method cache, but that class's methods 
happen not to be called, then the corruption can go unnoticed for a long time.

If the user is sufficiently sophisticated, you might be able to get them to run 
your app with Guard Malloc enabled via DYLD_INSERT_LIBRARIES. That is probably 
your best chance of catching a memory smasher.


-- 
Greg Parker gpar...@apple.com Runtime Wrangler


___

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

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

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

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


Re: Equivalent of UITextField's textField:shouldChangeCharactersInRange:replacementString for NSTextField

2011-09-27 Thread Aki Inoue
Eric,

We really recommend looking at the approach I described earlier using 
NSFormatter subclass for input validation.
- (BOOL)isPartialStringValid:(NSString **)partialStringPtr 
proposedSelectedRange:(NSRangePointer)proposedSelRangePtr 
originalString:(NSString *)origString 
originalSelectedRange:(NSRange)origSelRange errorDescription:(NSString **)error;

-textView:shouldChangeTextInRange:replacementString: is used by other AppKit 
services including undo/redo, input services, & formatter validation, etc.
It's possible for you to interfere with these system services if your override 
method was not implemented with aware of them.  The interface is designed to 
allow overriding these system services, too.

By using NSFormatter, your method can focus to the validation logic itself 
since it's invoked after other services.

That said, if you still really need to go that route, you don't need have 
custom field editor.

All NSControl subclass hosting a field editor is a text view delegate.
You can simply override the delegate method with your custom NSTextField 
subclass.

For example,

- (BOOL)textView:(NSTextView *)aTextView 
shouldChangeTextInRange:(NSRange)aRange replacementString:(NSString *)aString {
if ([super textView:aTextView shouldChangeTextInRange:aRange 
replacementString:aString]) {
id delegate = [self delegate];
if ([delegate 
respondsToSelector:@selector(textView:shouldChangeTextInRange:replacementString:)])
 return [delegate textView:aTextView shouldChangeTextInRange:aRange 
replacementString:aString];
return YES;
}

return NO;
}

should give you essentially what you want.

Aki

On 2011/09/27, at 14:08, Eric Wing wrote:

> On 9/21/11, Jens Alfke  wrote:
>> 
>> On Sep 21, 2011, at 7:42 PM, Eric Wing wrote:
>> 
>>> I have been using the delegate callback
>>> textField:shouldChangeCharactersInRange:replacementString for
>>> UITextField.
>>> I am trying to port code over to Mac using NSTextField. Is there
>>> something that provides similar functionality?
>> 
>> Yes, but it’s a bit more complicated due to some rough edges in the AppKit
>> API that got cleaned up in iOS. The delegate method you’re looking for is in
>> NSTextView, which is the actual view used to manage editing in a focused
>> NSTextField. Basically, you should read about “field editors” in the AppKit
>> docs. You’ll want to give your text field a custom field editor and set
>> yourself as its delegate.
>> 
>> —Jens
> 
> Thanks for the info. That turned out to be a really long side quest.
> Had to get into NSCell's and went into areas of NSSecureTextField that
> I shouldn't have.
> 
> Anyway, I have my field editor mostly working, but I have one follow
> up issue. I originally was using:
> - (void) controlTextDidBeginEditing:(NSNotification*)notification
> to get an event callback when the field begins editing.
> 
> It seems that once I added my custom field editor, I no longer get
> this callback. Strangely, I still get the callback for:
> - (void) controlTextDidEndEditing:(NSNotification*)notification
> 
> Is there something I can do to get that first callback back working
> again, or is there a substitute? (Currently my workaround is to keep a
> bool on my shouldChangeCharactersInRange: to know if I just started
> editing, but I would like to know if there is something more elegant.)
> 
> Thanks,
> Eric
> -- 
> Beginning iPhone Games Development
> http://playcontrol.net/iphonegamebook/
> ___
> 
> Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)
> 
> Please do not post admin requests or moderator comments to the list.
> Contact the moderators at cocoa-dev-admins(at)lists.apple.com
> 
> Help/Unsubscribe/Update your Subscription:
> http://lists.apple.com/mailman/options/cocoa-dev/aki%40apple.com
> 
> This email sent to a...@apple.com

___

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

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

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

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


Re: Numeric Entry and Formatting With NSNumberFormatter Won't Append Zeros

2011-09-27 Thread Philip McIntosh
> Subject: Re: Numeric Entry and Formatting With NSNumberFormatter Won't
>   Append  Zeros
> To: Philip McIntosh 
> Cc: cocoa-dev@lists.apple.com
> Message-ID: <62796e49-61ed-4b4a-8315-bdeaabeb4...@manoverboard.org>
> Content-Type: text/plain; charset=windows-1252
> 
> On 23 Sep 2011, at 6:48 PM, Philip McIntosh wrote:
> 
>> I have a calculation project using buttons to input numbers into a UILabel. 
>> I want it to format the numbers as they are entered to display grouping 
>> separators. It has been a struggle but so far the best I have ben able to 
>> achieve is this (I got the basic idea from a post at stackoverflow.com):
> 
> A threshold question: Do I understand correctly that the only record you have 
> of the value of your accumulator is the text contents of a label? Why? When 
> you call
> 
>>  NSDecimalNumber *number = [NSDecimalNumber 
>> decimalNumberWithString:currentText];
> 
> you have no control at all over how the label's text is converted to a 
> decimal. It may or may not be lossy.

I don't follow. How could it be "lossy?" It's a string in the display 
(display.text), that is saved into a another string variable (currentText) so 
later added separators are stripped out and that string is then used to create 
the updated and formatted number.

> Better that you keep, as a model object, the decimal value, and avoid 
> repeated round trips through the default parser. (You are careful to specify 
> U.S. grouping and decimal separators for _output_, but the convenience parser 
> you're using will use the separators from the current locale.)
> 
> The rule is that you never, ever keep program state in a display object. If 
> you _must_ go through a string (which should still be a model object, and not 
> simply be left lying around in a label), set up an NSNumberFormatter and 
> setGeneratesDecimalNumbers:YES, so you can get some control. You can then 
> keep the formatter in a static variable, and reuse it for repeated 
> conversions in both directions ˜ the round trip will be likelier to preserve 
> your intended value.

It's not left lying around, it exists in currentText.

> 
> I'm also curious to know what you intend by 
> 
>>  currentText = [currentText stringByReplacingOccurrencesOfString:@"." 
>> withString:@"."];
> 

I've done quite a bit of NSLogging in this method to see what is happening. I 
confirm that the char entered is a decimal and is on the end of the input 
string, but no zeros after that are ever detected. 

Anyway, that 'replace @"." with @"." ' is a vestige from a previous failed 
attempt and you are right in assuming it is not required. 

I have indeed set the formatter to generatesDecimalNumbers, allowedFloats, 
tried using floats, ints and doubles to set the NSDecimalNumber, used NSNumber 
instead, and also confirmed that the formatter behaves as desired if I give it 
a canned static string that is not built by appending a string from a button 
input. I have also tried it with and without setting the locale. I really don't 
want to use the locale anyway because I want the user to select the number 
format they are comfortable with without regard to what part of the world the 
device happens to be operating in.

I don't see anything wrong with pulling a string off a display, formatting it 
as a number, converting the number back into a string and redisplaying it. As I 
said the formatter works as expected with any number I give it starting out as 
a defined string (if my string is 1234567.000321 the formatter produces 
1,234,567.000321). It is only when the string is built by appending digits that 
something goes wrong (no zeros accepted after a decimal point).

I have come up with a "work around." I simply do not invoke the NSNotification 
to call the updateDisplay method anymore if a decimal point is detected in the 
display. That way, the formatter properly handles the grouping separators in 
the integer part, and the string continues to be built and displayed as 
expected after the decimal point while preserving any previous formatting in 
the integer part. Any following calculations also come out correct. It works 
good and looks good, but hasn't helped me to understand why it didn't accept 
any zeros after the decimal point.

I appreciate the feedback. It's made me think.

___

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

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

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

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


Re: NSDateFormatter refuses to format dates

2011-09-27 Thread Gerriet M. Denkmann

On 28 Sep 2011, at 04:51, Vincent Spader wrote:

> 
> On Sep 27, 2011, at 1:41 AM, Gerriet M. Denkmann wrote:
> 
>> The following code produces an empty string:
>> 
>>  calender = [ [ NSCalendar autoupdatingCurrentCalendar ] retain ];
>>  NSString *dateTemplate = @"eeeddHHmmss";
>>  NSLocale *locale = [calender locale];   //  en_IE
>>  NSString *dateFormat = [ NSDateFormatter dateFormatFromTemplate: 
>> dateTemplate  options:0  locale: locale ]; //  EEE dd   
>> HH:mm:ss
>>  dateFormatter = [ [ NSDateFormatter alloc ] initWithDateFormat: 
>> dateFormat allowNaturalLanguage: NO ];
>>  [ dateFormatter setFormatterBehavior: NSDateFormatterBehavior10_4 ];
>>  [ dateFormatter setLocale: locale ];
>>  [ dateFormatter setGeneratesCalendarDates: YES ];
>>  NSTimeZone *localTimeZone = [ calender timeZone ]; 
>>  [ dateFormatter setTimeZone: localTimeZone ];
>>  NSLog(@" now \"%@\"", [dateFormatter stringFromDate: [NSDate date]]);
>> 
>> What am I missing?
> Creating an NSDateFormatter via -initWithDateFormat:allowNaturalLanguage: 
> will create a 10.0 style date formatter. 10.0 and 10.4+ date formatters have 
> completely different format strings, so when you call -setFormatterBehavior:, 
> the format string may not stick around. Here's what you want:
>   dateFormatter = [ [ NSDateFormatter alloc ] init];
>   [dateFormatter setDateFormat:dateFormat];
> 
> and the setFormatterBehavior: call is no longer necessary. You can find more 
> info in the "Formatting Behaviors and OS Versions" section of the 
> NSDateFormatter reference.

You are right. Now everything behaves as expected.
Thank you very much.

Kind regards,

Gerriet.

P.S. 
Is there a direct way to get the localized monthSymbols and shortWeekdaySymbols 
without using NSDateFormatter?

___

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

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

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

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


Re: controller question

2011-09-27 Thread Ariel Feinerman
So in the case of insertion to m_array, we just have to reset content
property:

// somewhere in the code
[self willChangeValueForKey: @"content"];
[m_array insertObject: url atIndex: 0];
[self didChangeValueForKey: @"content"];

// in the -observeValue...

[controller setContent: m_array];

well?


2011/9/27 Quincey Morris 

> On Sep 27, 2011, at 12:18 , Ariel Feinerman wrote:
>
> So it is good news. Do -insertObject: atIndex:, -removeObject: or
> removeObjects: use KVO? I guess they do.
>
>
> If you use these methods, you don't have to write any manual
> synchronization code. Your original array will contain the modified
> contents.
>
> However, in your case ('setContent: m_array'), KVO isn't involved. Kyle
> sent me the following message off-list. I don't think he'll mind if I post
> it here, since the information reflects badly on me, not on him.
>
> On Sep 27, 2011, at 10:47 , Kyle Sluder wrote:
>
> You cannot KVO-observe an NSArray. -[NSArray
> addObserver:forKeyPath:options:context:] is implemented to throw an
> exception.
>
>
> Well, I thought I'd run out of stupid things to say about
> NSArrayController, but apparently I can still confuse myself.
>
> As Kyle suggests, when you 'setContent:' on an array controller, it cannot
> observe the array because KVO doesn't allow it, and, there just isn't a way
> to update the array itself KVO compliantly. Under those circumstances, using
> the NSArrayController methods ('addObject…', 'removeObject…',
> 'insertObject…') will update the array properly, but updating the array
> directly won't cause the array controller to notice.
>
> Oddly, when I wrote some code to check out a couple of details, I found
> that:
>
> -- when the array controller is *bound* to its content array, its 'remove:'
> method works fine
>
> sorry for the question, hm I slightly don't understand in cocoa bindings so
how to bound the controller to its content array?


> -- when the array controller's "content" property is merely set to the
> content array, 'remove:' does nothing
>
> In the second case, I had a document object with an IBOutlet to the array
> controller, and I set it up with [arrayController setContent: theArray].
> When my deletion button action method looked like this:
>
> - (IBAction) deleteIt: (id) sender {
> [arrayController remove: sender];
> }
>
> nothing got deleted. (And, yes, I let the app go back to the main event
> loop before checking.)
>
> When my deletion action method looked like this:
>
> - (IBAction) deleteIt: (id) sender {
> [arrayController removeObjects: [arrayController selectedObjects]];
> }
>
> the deletion worked fine. That's in spite of the fact that 'remove:' is
> documented to do what the second version does, though deferred to the next
> iteration of the run loop.
>
> Maybe I made a stupid mistake, but it's a bit puzzling.
>
>
>


-- 
best regards
Ariel
___

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

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

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

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


Trouble creating dictionary

2011-09-27 Thread Dale Satterfield
I have the following code which creates two arrays of 97 elements each, then 
creates an NSDictionary.
However, the dictionary only has 30 elements in it, and reports no errors 
during creation. None of the keys should be a duplicate .

  tzKeys = [NSArray 
arrayWithObjects:TZ_Eniwetok,TZ_Kwajalein,TZ_Midway,TZ_Samoa,TZ_Hawaii,TZ_Alaska,TZ_Tijuana,TZ_LosAngeles,TZ_Pacific,TZ_Mountain,TZ_Phoenix,

TZ_Central,TZ_Eastern,TZ_Bogota,TZ_Lima,TZ_Quito,TZ_Atlantic,TZ_Caracas,TZ_LaPaz,TZ_Santiago,TZ_Newfoundland,TZ_Brasilia,TZ_Buenos_Aires,TZ_MidAtlantic,TZ_Azores,TZ_CapeVerde,TZ_GMT,TZ_Mexico_City,TZ_CentralAmerica,TZ_London,TZ_Edinburgh,TZ_Dublin,TZ_Lisbon,TZ_Monrovia,TZ_Berlin,TZ_Rome,TZ_Amsterdam,TZ_Stockholm,TZ_Paris,TZ_Brussels,TZ_Prague,TZ_Belgrade,TZ_Bratislava,TZ_Budapest,TZ_Ljubljana,TZ_Athens,TZ_Helsinki,TZ_Istanbul,TZ_Minsk,TZ_Riga,TZ_Cairo,TZ_Bucharest,TZ_Harare,TZ_Praetoria,TZ_Jerusalem,TZ_Baghdad,TZ_Kuwait,TZ_Nairobi,TZ_Moscow,TZ_Volgograd,TZ_Tehran,TZ_Tblisi,TZ_Kabul,TZ_Karachi,TZ_Bombay,TZ_Madras,TZ_Calcutta,TZ_New_Delhi,TZ_Chennai,TZ_Almaty,TZ_Dhaka,TZ_Colombo,TZ_Novosibirsk,TZ_Bangkok,TZ_Jakarta,TZ_Irkutsk,TZ_Beijing,TZ_HongKong,TZ_Perth,TZ_Singapore,TZ_Taipei,TZ_Tokyo,TZ_Seoul,TZ_Yakutsk,TZ_Adelaide,TZ_Darwin,TZ_Brisbane,TZ_Melbourne,TZ_Sydney,TZ_Guam,TZ_Magadan,TZ_SolomonIslands,TZ_NewCaledonia,TZ_Fiji,TZ_MarshallIslands,TZ_Auckland,TZ_Wellington,
 nil];
tzValues = [[NSMutableArray alloc] init];
int i;
int offsets[] = 
{-1200,-1200,-1100,-1100,-1000,-900,-800,-800,-800,-700,-700,-600,-500,-500,-500,-500,-400,-400,-400,-400,

-330,-300,-300,-200,-100,-100,0,0,0,0,0,0,0,0,100,100,100,100,100,100,100,100,100,100,100,200,200,200,200,200,200,200,200,200,200,

300,300,300,300,300,330,400,430,500,530,530,530,530,530,600,600,600,600,700,700,800,800,800,800,800,800,900,900,900,

930,930,1000,1000,1000,1000,1100,1100,1100,1200,1200,1200,1200,};

for(i = 0; offsets[i] != ; i++)
{
[tzValues addObject:[NSNumber numberWithInt:offsets[i]]]; 
}
NSLog(@"i = %d elements in tzValues",i);// i ends up at 97
NSLog(@"tzValues says its count is %lu",[tzValues count]);  // Says count 
is 97
NSLog(@"tzKeys says it's count is %lu",[tzKeys count]); // Says count is 97

tzDict = [NSDictionary dictionaryWithObjects:tzKeys forKeys:tzValues];
for(NSString *key in tzDict) NSLog(@"%@  %@",key, [tzDict 
objectForKey:key]);   // Prints 30 keys/objects
for(NSString *key in tzKeys) NSLog(@"%@",key);  // Enumerate items in 
tzKeys// Prints all 97 items
for(NSNumber *aNum in tzValues) NSLog(@" the value in tzValues is 
%@",aNum);// Prints all 97 items
NSLog(@"tzDict says it's count of items is %lu",[tzDict count]);
// Says count is 30

Dale Satterfield
dsatterfi...@mac.com

___

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

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

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

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


Re: Trouble creating dictionary

2011-09-27 Thread Quincey Morris
On Sep 27, 2011, at 18:21 , Dale Satterfield wrote:

>tzDict = [NSDictionary dictionaryWithObjects:tzKeys forKeys:tzValues];

Don't you mean:

tzDict = [NSDictionary dictionaryWithObjects:tzValues forKeys:tzKeys];



___

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

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

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

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


Re: Trouble creating dictionary

2011-09-27 Thread Graham Cox

On 28/09/2011, at 11:21 AM, Dale Satterfield wrote:

>  tzDict = [NSDictionary dictionaryWithObjects:tzKeys forKeys:tzValues];


You've transposed the values and the keys here, and since the values are not 
unique, you end up with only 30 unique "keys" (which are really the values).

--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: controller question

2011-09-27 Thread Quincey Morris
On Sep 27, 2011, at 17:51 , Ariel Feinerman wrote:

> So in the case of insertion to m_array, we just have to reset content 
> property: 
> 
> // somewhere in the code 
> [self willChangeValueForKey: @"content"]; 
> [m_array insertObject: url atIndex: 0];  
> [self didChangeValueForKey: @"content"]; 
> 
> // in the -observeValue... 
> 
> [controller setContent: m_array]; 
> 
> well? 

No, that's not it. I'm sorry I've confused the issue for you by saying 
something wrong earlier.

Let's reset and start again.

1. You have an array (m_array) which you create and maybe populate in advance. 
This is the M in MVC.

2. You have an array controller (controller) which you create or maybe 
instantiate in a nib file. This is the C in MVC.

3. You have a view, for example a table view whose columns are bound to the 
array controller. This is the V in MVC.

With this one-time line of code:

[controller setContent: m_array];

you tell the array controller to *manage* m_array for you. There's no copy 
"inside" the array controller. That answers one of your questions.

If you want to add or remove objects from m_array programmatically, then use 
the various [NSArrayController addObject…], [NSArrayController removeObject…], 
[NSArrayController insertObject…] methods. These method do two things: they 
*both* change the underlying array *and* tell the array controller that the 
underlying array changed. That answers another of your questions.

So long as you use these methods, if you want to know what objects the array 
controller is managing, you can just look at m_array. That answers your last 
question.

In this setup, KVO doesn't enter the picture, and I was wrong to say it did.

That's basically the whole story, but I'll add two footnotes:

-- If you need KVO notifications to be sent because *other* objects in your app 
need to be notified when things change, you should not use an array *object* 
(m_array), but rather an array *property* of some other object (such as a 
"myArray" property of your app delegate). In that case, you would likely bind 
the array controller to this array property, instead of using setContent, and 
everything can then be done KVO-compliantly.

-- If there's no view involved here, there's really no good reason to be using 
an array controller at all. I don't think you mentioned a view, so I'm not sure 
what to assume.

Is that clear? I think I've said it right now.


___

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

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

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

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


Validating form input w/o core data

2011-09-27 Thread William Squires
Hi,
  I have a need for a complex data-entry form (window). Some fields are 
supposed to only accept alpha characters (upper or lower), some are supposed to 
only take integers, others to only take floats (but no negative values 
allowed). Is there a general way of validating the contents of a field before 
it resigns first responder status? Even better, is there a way to encapsulate 
that behavior in an NSTextField subclass so that I can make, say, an 
AlphaOnlyTextField class, drag a (normal) NSTextField onto the window in IB, 
then change it's super to "AlphaOnlyTextField", or some such? This way I can 
save a lot of time, and will have a reusable control (sub)class that I can then 
use in other projects!
  I'm still using Xcode 3.somethingorother, and IB for my MacOS X/iOS work.
  Here's the control flow I hope to tap into:

Control (an NSTextField) has focus (is first responder) - user types something 
into the NSTextField
User tabs (or shift-tabs) to the next control, or clicks the mouse on another 
control
NSTextField that currently has first responder status checks to see if it has a 
delegate, and - if it does - does it respond to validate:? If so, the delegate 
gets sent the validate: message which returns a BOOL. If the control's contents 
(it's stringValue in the case of an NSTextField) has valid input, it'll return 
YES to indicate that the control may lose first responder. If it returns NO, 
then the attempt to lose first responder status is nullified, and the control 
keeps its first responder status.
User finally types in valid input, and the validate: returns YES. The 
NSTextField now loses first responder, and some other control on the view now 
gets first responder status.

Doable? Basically, I'd like to subclass NSTextField and the subclass would 
implement the delegate protocol's validate: message (method); the subclass 
would set itself as it's own delegate in the awakeFromNib: method, then remove 
itself somewhere else (when the control, and it's parent window, dies.) Even 
better, can I trap (and kill) invalid characters as they're entered? (i.e. an 
NSTextField that only allows (A-Z | a-z), and converts the characters to upper- 
or lower-case, say?


___

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

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

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

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


Re: Equivalent of UITextField's textField:shouldChangeCharactersInRange:replacementString for NSTextField

2011-09-27 Thread Eric Wing
> We really recommend looking at the approach I described earlier using
> NSFormatter subclass for input validation.

Unfortunately, I am not actually formatting or validating anything so
this isn't helpful for me. I am working on a middle-layer framework
and what I am interested in is the text change notification with
enough information about how the string just changed.
shouldChangeTextInRange:replacementString: provides me the level of
detail I am interested in.

> All NSControl subclass hosting a field editor is a text view delegate.
> You can simply override the delegate method with your custom NSTextField
> subclass.

> For example,
>
> - (BOOL)textView:(NSTextView *)aTextView
> shouldChangeTextInRange:(NSRange)aRange replacementString:(NSString
> *)aString {
>   if ([super textView:aTextView shouldChangeTextInRange:aRange
> replacementString:aString]) {
>   id delegate = [self delegate];
>   if ([delegate
> respondsToSelector:@selector(textView:shouldChangeTextInRange:replacementString:)])
> return [delegate textView:aTextView shouldChangeTextInRange:aRange
> replacementString:aString];
>   return YES;
>   }
>
>   return NO;
> }
>
> should give you essentially what you want.

Drat, this was the first thing I tried and I never got the callback
which is why I went down the whole field handler path. I just tried it
again, and it just worked.

I'm still a bit confused/overwhelmed by this whole thing, like how the
delegate can call [super textView:aTextView
shouldChangeTextInRange:aRange replacementString:aString]). The
delegate isn't necessarily a subclass of NSTextView, right?

Also, for the record, I figured out why my DidBegin callback didn't
fire. I forgot to call super in my
shouldChangeTextInRange:replacementString: method of my subclass of
NSTextView for the field handler.

But regardless, I'm deleting all my field handler stuff and just going
with the delegate now that it works for me.

Thanks,
Eric
-- 
Beginning iPhone Games Development
http://playcontrol.net/iphonegamebook/
___

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

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

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

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