Re: How to parse a search string..

2012-02-13 Thread Uli Kusterer
On 12.02.2012, at 23:02, David Delmonte wrote:
> I have a search box, and need to parse out some special characters (' and \).

 Do you? In most cases, ignoring some of the user's input just leads to wrong 
result. Instead, you should determine how to correctly escape the given 
characters so they make it through as text instead of doing something special. 
E.g. for an SQLite query, you usually just have to prefix special characters 
with a backslash (and any backslashes you want to go through verbatim as well, 
so they can be told from "special character"-backslashes).

> The search bar text is sbar.text.. How do I interrupt the string before it is 
> sent and remove (or warn) of these characters... ? Many thanks..
> 
> I've tried this: 
> 
> if ([sbar.text isEqualToString:(@"'")] || [sbar.text 
> isEqualToString:(@"\\")]) {
>   NSLog(@"Found You");
>   sbar.text = nil;
> 
> (This works when the characters are first in the string..)

 Your code above compares the entire string to another entire string. Unless 
the string only consists of a tick mark, or only of one backslash, this won't 
match. You have to use a call that searches the string for a substring, like 
rangeOfString:... 

> and this:
> 
> NSString *protectedString1 = sbar.text;
> NSString *protectedString2 = [protectedString1 
> stringByReplacingOccurrencesOfString:@"'" withString:@" "];
> sbar.text = protectedString2;
> 
> But this loops :)


What do you mean "it loops" ? This should replace any tick marks with spaces in 
your string. What were you expecting it to do ... ?

Cheers,
-- Uli Kusterer
"The Witnesses of TeachText are everywhere..."




___

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

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

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

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


Re: copy & isEqual nightmares

2012-02-13 Thread Uli Kusterer
On 13.02.2012, at 01:25, James Maxwell wrote:
> But what I don't get is how hash plays into all this. I've always read that I 
> have to override hash when I override isEqual, but I don't exactly understand 
> what that means or does. What I've done is to make a hash that is equal when 
> two objects have the same values for propA and propB (ignoring propC). That's 
> how I interpreted the few threads I've read about overriding hash...

 A hash is a gatekeeper, a criterion used to discard some of a large number of 
expensive comparisons. The only condition a hash has to fulfill is that if the 
hashes are different, the objects *must not* be equal. If the hashes are 
identical, the objects may or may not be equal.

 It *has to be* like this. Your data consists of probably 8 or 16 bytes, maybe 
more. A hash consists of about 4 bytes. So by that alone, if you go through all 
the permutations of bits in your 16 bytes (all possible values your object may 
contain), some of these must map to the same 4-byte-hash. You only have 4 
billion different hash values, after all. This is what is called a "hash 
collision": Two different objects that result in the same hash.

 When looking for an object identical to another, the hash is simply used to 
eliminate the majority of objects, who *do* have a different hash. A good 
hashing function gives you different hashes for the most common values, while 
rarer values cause more hash collisions. That way, the majority can be quickly 
discarded, leaving you to *really* compare only a few leftover objects that 
happen to collide.

 It's simply a speed optimization in that case.

> But what I need to do in my code, right now, is to copy an object, then alter 
> some properties of the copy, but not the original -- a typical reason for 
> wanting a copy. But I'm seeing that the copy has the same hash and appears to 
> be the same object, since changing properties of the copy changes the 
> original.

 How are you copying this object? What do the instance variables of this object 
contain? The -copy method is not magic. If you have any instance variables that 
are pointers (like objects), you *have to* override -copyWithZone: to make 
copies of those objects as well, if they are mutable. E.g. NSString is 
immutable, so you usually replace an old NSString value with a new one, so you 
can just -retain it, but if it's an NSMutableString, then you need to copy 
that, or both copies of *your* object, even though different, will reference 
(and thus edit) the same mutable string object.

 Collection classes usually perform a shallow copy. That is, if you copy an 
NSMutableDictionary, it will copy the dictionary (so you can modify the list 
without modifying the original list), but will simply retain the objects in the 
array. This is more efficient and usually what's desired, but if you are 
duplicating your entire dictionary hoping to be able to independently edit all 
of your objects in there, you'll have to do it differently and make a deep copy 
yourself.

> So does the system see the matching hashes as identical objects, not just the 
> collection classes?

 No. Try it: Call NSLog( @"%p", theObject ); to log the actual memory address 
of theObject (or just pause in the debugger and note down both addresses). 
Unless you made a shallow copy of a containing object, you will get different 
addresses logged. The hashes will be identical, of course. That's the whole 
point of hashes. If the memory address is identical, it *must* be the same 
object (and NSDictionary probably checks for that by default and considers the 
objects equal right away). Otherwise, it looks at the hash, and if it's 
different, the objects can't be equal. And only if it's neither of those cases, 
it actually compares ivars using -isEqual:.

> Do I have to manually implement some sort of deepCopy method?

 For containers, yes. For your object, -copyWithZone: should be sufficient. Or 
you can grab one from https://github.com/uliwitness/UliKit/ e.g. 
NSDictionary+DeepCopy.m.

> Or, can I just change hash, so that the copy is a different instance, without 
> losing the functionality I need for collections? I don't understand why I'd 
> need to make a deepCopy, since that's what copy is for...


 The hash should be calculated from your object's values. If your object's 
ivars (those that are relevant to the hash) can be changed after creation, you 
must always recalculate your hash whenever one of them is modified (or mark it 
as invalid, and lazily recalculate it whenever someone next asks for the hash). 
If it really is the same object, you goofed and are somehow not copying your 
object. In that case changing the hash will not do much good, as you'll change 
the hash for both places that reference this single object. If you have two, 
the moment you change a value in it, the hash should change as well. If they 
have identical values, they should have identical hashes.

Cheers,
-- Uli Kusterer
"The Witnesses of T

Re: copy & isEqual nightmares

2012-02-13 Thread Uli Kusterer
On 13.02.2012, at 02:54, James Maxwell wrote:
> NSLog(@"%@", [obj hash])

 I hope this is a typo. %@ expects an object, while -hash returns an integer. 
If you're lucky, this will crash, or just output garbage. Your compiler should 
be warning you about that line.

Cheers,
-- Uli Kusterer
"The Witnesses of TeachText are everywhere..."




___

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

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

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

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


Re: How to parse a search string..

2012-02-13 Thread Uli Kusterer
On 13.02.2012, at 00:22, Graham Cox wrote:
> If you really have to annoy the user by rejecting their input as they go, 
> there are delegate methods on the field editor which would allow you to 
> validate the text as they type - look up "field editor" in the guides.

 Isn't that what NSFormatter is for? Allow only input of numbers into a text 
field, and the likes? That's how NSOpenPanel does, it substitutes any colon 
character you type in (which is, to criminally simplify, the path component 
separator character on HFS) with a minus sign.

Cheers,
-- Uli Kusterer
"The Witnesses of TeachText are everywhere..."
http://www.masters-of-the-void.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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

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


Re: copy & isEqual nightmares

2012-02-13 Thread James Maxwell
oops, yes. typo (0x%X)

J.

On 2012-02-13, at 1:21 AM, Uli Kusterer wrote:

> On 13.02.2012, at 02:54, James Maxwell wrote:
>> NSLog(@"%@", [obj hash])
> 
> I hope this is a typo. %@ expects an object, while -hash returns an integer. 
> If you're lucky, this will crash, or just output garbage. Your compiler 
> should be warning you about that line.
> 
> Cheers,
> -- Uli Kusterer
> "The Witnesses of TeachText are everywhere..."
> 
> 
> 

--
James B. Maxwell
Composer/Researcher/PhD Candidate






___

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

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

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

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


Problem assigning NSView bounds from subview.bounds

2012-02-13 Thread Michael Crawford
I'm trying to have a superview resize itself to match the bounds of a subview 
when the subview is added.  When I do, the superview bounds become NaN.

Why would this:

- (void)didAddSubview:(NSView *)view
{
// resize to match bounds of given subview
NSLog(@"%@ = %@, %@ = %@", self, NSStringFromRect([self bounds]), view, 
NSStringFromRect([view bounds]));
[self setBounds:[view bounds]];
NSLog(@"%@ = %@, %@ = %@", self, NSStringFromRect([self bounds]), view, 
NSStringFromRect([view bounds]));
}

result in this?

2012-02-13 09:48:03.637 LSSettingsBar[3797:707]  = {{0, 
0}, {0, 0}},  = {{0, 0}, {216, 216}}
2012-02-13 09:48:03.637 LSSettingsBar[3797:707]  = {{nan, 
nan}, {nan, nan}},  = {{0, 0}, {216, 216}}

-Michael
___

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

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

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

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


Re: Playing Music in Objective C

2012-02-13 Thread Jim McGowan

On 13 February, 2012 4:38, Jens Alfke  wrote:
> 
> On Feb 12, 2012, at 10:35 AM, Conrad Shultz wrote:
> 
>> The simplest (and therefore least customizable) approach would be to use 
>> NSSound. But I think it will do everything you stipulate. 
> 
> A minor issue with NSSound in games is that, the first time you play a 
> particular sound, it’ll first hang for a fraction of a second while it loads 
> the file. I’ve found this to be annoyingly distracting since it also freezes 
> animations. To work around this, at startup create the NSSound object, set 
> its volume to 0 and play it once. That will pre-load the samples into memory.

Actually I found that there is no need to play the NSSound at 0 volume to load 
the data into RAM, simply instantiating the NSSound ahead of time (with 
+soundNamed:) is enough.  I looked into using NSSound for simple game sounds in 
a blog post a while back: 
http://bleepsandpops.com/post/1431403685/using-nssound-for-simple-game-sounds-in-cocoa

As the OP was creating a simple puzzle game I think NSSound is a reasonable way 
to go for the sound effects.  Might even be reasonable for the music too, if it 
is just a looping MP3.

Jim
___

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

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

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

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

Re: Problem assigning NSView bounds from subview.bounds

2012-02-13 Thread Kyle Sluder
On Feb 13, 2012, at 7:02 AM, Michael Crawford  wrote:

> I'm trying to have a superview resize itself to match the bounds of a subview 
> when the subview is added.  When I do, the superview bounds become NaN.
> 
> Why would this:
> 
> - (void)didAddSubview:(NSView *)view
> {
>// resize to match bounds of given subview
>NSLog(@"%@ = %@, %@ = %@", self, NSStringFromRect([self bounds]), view, 
> NSStringFromRect([view bounds]));
>[self setBounds:[view bounds]];

You want to call -setFrame:.

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

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


Re: Playing Music in Objective C

2012-02-13 Thread Kyle Sluder
On Feb 12, 2012, at 11:02 AM, Charles Srstka  wrote:

> I’d suggest looking at QTMovie — more customizable than NSSound, and just 
> about as simple to use.
> 

If you're targeting Lion, do not use QTMovie. Use AVFoundation instead.

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

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

Re: Playing Music in Objective C

2012-02-13 Thread Kyle Sluder
On Feb 13, 2012, at 7:30 AM, Jim McGowan  wrote:

> As the OP was creating a simple puzzle game I think NSSound is a reasonable 
> way to go for the sound effects.  Might even be reasonable for the music too, 
> if it is just a looping MP3.

AVAudioPlayer is simple enough that I would recommend not using NSSound at all 
in new code. AVFoundation exists on iOS, and is clearly the way of the future 
on both platforms.

https://developer.apple.com/library/mac/#documentation/AVFoundation/Reference/AVAudioPlayerClassReference/Reference/Reference.html#//apple_ref/doc/uid/TP40008067

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

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


Re: Playing Music in Objective C

2012-02-13 Thread John Pannell
Hi all-

Another tidbit on NSSound (or perhaps sound in general)… laptops will sleep the 
sound hardware when possible, and there is a brief delay when waking things 
back up.  I have found that the playing of a silent sound at the launch of my 
app is helpful to wake things up and avoid the delay (sound delay, no app 
freeze or the like) associated with the wake up caused by your first 
app-related sound.

Just FYI!

John


John Pannell
http://www.positivespinmedia.com

On Feb 13, 2012, at 8:30 AM, Jim McGowan wrote:

> 
> On 13 February, 2012 4:38, Jens Alfke  wrote:
>> 
>> On Feb 12, 2012, at 10:35 AM, Conrad Shultz wrote:
>> 
>>> The simplest (and therefore least customizable) approach would be to use 
>>> NSSound. But I think it will do everything you stipulate. 
>> 
>> A minor issue with NSSound in games is that, the first time you play a 
>> particular sound, it’ll first hang for a fraction of a second while it loads 
>> the file. I’ve found this to be annoyingly distracting since it also freezes 
>> animations. To work around this, at startup create the NSSound object, set 
>> its volume to 0 and play it once. That will pre-load the samples into memory.
> 
> Actually I found that there is no need to play the NSSound at 0 volume to 
> load the data into RAM, simply instantiating the NSSound ahead of time (with 
> +soundNamed:) is enough.  I looked into using NSSound for simple game sounds 
> in a blog post a while back: 
> http://bleepsandpops.com/post/1431403685/using-nssound-for-simple-game-sounds-in-cocoa
> 
> As the OP was creating a simple puzzle game I think NSSound is a reasonable 
> way to go for the sound effects.  Might even be reasonable for the music too, 
> if it is just a looping MP3.
> 
> Jim


___

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

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

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

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

Re: NSReadPixel

2012-02-13 Thread koko
Hello Kyle -

What I am trying to accomplish is my own 'eye-droper' color picker (for reasons 
I cannot get into).

Can you point me to the best method as I have done things other than a plain 
read pixel to no avail.

Thanks!

-koko



On Feb 11, 2012, at 10:09 AM, Kyle Sluder wrote:

> On Fri, Feb 10, 2012 at 4:44 PM, koko  wrote:
>> I have two monitors connected.
>> 
>> When I call NSreadPixel with a point that is on the main screen, origin 0,0 
>> it returns the appropriate NSColor;
>> 
>> When I call NSreadPixel with a point that is on the 2nd screen, origin 
>> -1280,0 it returns nil as the NSColor;
>> 
>> So, how do I get the NSColor for a pixel whose x coordinate is <0?
> 
> 1. Are you sure you're actually passing the correct point? NSReadPixel
> operates in the coordinate system of the currently-focused view. You
> might be getting the right color by sheer luck.
> 2. Why are you using NSReadPixel at all? There might be better ways of
> accomplishing your goal.
> 
> --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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

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


Odd display of percent character

2012-02-13 Thread Chris Paveglio
I'm having an issue with the percent character being displayed as random 
numbers in an NSAlertPanel (modal). My app has an ivar, "fullString", including 
the usual property/synthesize getters and setters, there is nothing special 
about it. fullString is bound to an NSTextField where a user might type "10% 
off all shoes", or put some text that contains dollar signs or percent signs. 
Later another method will validate if it's a web address or plain text and 
display an alert if it's not a web address. At this point I use the usual 
-stringWithFormat and put the "fullString" text in with some other descriptive 
text. But if fullString contains a percent character, then the NSAlert displays 
something like "10254458745ff all shoes". Why is the percent character being 
turned into some numbers, and it also seems to lop off the space and letter o 
as well? Using ampersand, dollar sign, and number symbol all display properly.
FWIW, I am using objective-C++, because my QR code library project is C++ and I 
need to compile it all the same (first time I've had to do anything like this). 
Would that be somehow mangling my string in the NSAlert display? If I do NSLog 
on the string displayed in the NSAlert it also logs properly. So why the 
discrepancy in the Alert?

Thanks,
Chris
___

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

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

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

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


Re: NSReadPixel

2012-02-13 Thread Kyle Sluder
On Feb 13, 2012, at 8:48 AM, koko  wrote:

> Hello Kyle -
> 
> What I am trying to accomplish is my own 'eye-droper' color picker (for 
> reasons I cannot get into).
> 
> Can you point me to the best method as I have done things other than a plain 
> read pixel to no avail.

Well, as long as you're not using NSReadPixel to try to take a screenshot. ;-)

This page on CocoaDev suggests using a transparent window: 
http://www.cocoadev.com/index.pl?GettingTheColorUnderTheCursor

But I don't think a screen-sized window is necessary. You might be able to 
create a transparent 1px-by-1px window that follows the cursor hotspot, then 
lock focus on its contentView and call NSReadPixel.

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

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


Re: copy & isEqual nightmares

2012-02-13 Thread Quincey Morris
On Feb 13, 2012, at 01:14 , Uli Kusterer wrote:

> The hash should be calculated from your object's values. If your object's 
> ivars (those that are relevant to the hash) can be changed after creation, 
> you must always recalculate your hash whenever one of them is modified (or 
> mark it as invalid, and lazily recalculate it whenever someone next asks for 
> the hash). If it really is the same object, you goofed and are somehow not 
> copying your object. In that case changing the hash will not do much good, as 
> you'll change the hash for both places that reference this single object. If 
> you have two, the moment you change a value in it, the hash should change as 
> well. If they have identical values, they should have identical hashes.

I'm not sure I absolutely understand what you said, but it doesn't sound right.

It's a mistake to calculate the hash from *mutable* object state, including 
ivars that "can be changed after creation". The NSObject protocol documentation 
on 'hash' is worth recalling:

> hash
> Returns an integer that can be used as a table address in a hash table 
> structure. (required)
> 
> - (NSUInteger)hash
> Return Value
> An integer that can be used as a table address in a hash table structure.
> 
> Discussion
> If two objects are equal (as determined by the isEqual: method), they must 
> have the same hash value. This last point is particularly important if you 
> define hash in a subclass and intend to put instances of that subclass into a 
> collection.
> 
> If a mutable object is added to a collection that uses hash values to 
> determine the object’s position in the collection, the value returned by the 
> hash method of the object must not change while the object is in the 
> collection. Therefore, either the hash method must not rely on any of the 
> object’s internal state information or you must make sure the object’s 
> internal state information does not change while the object is in the 
> collection. Thus, for example, a mutable dictionary can be put in a hash 
> table but you must not change it while it is in there. (Note that it can be 
> difficult to know whether or not a given object is in a collection.)

There are 3 points to take away, beyond the basic requirements:

1. "the value returned by the hash method of the object must not change…". It 
sounded like you were contradicting this, above.

2. "… while the object is in the collection". This seems to promise that the 
only parts of the Cocoa frameworks that actually make use of the hash are the 
collection classes.

3. The hash is primarily intended to support hash table storage mechanisms. Any 
performance benefits in other contexts are secondary (and, given #2, aren't 
even necessarily valid if the object isn't in a collection).

Now, although #2 gives you permission to violate #1 while the object is *not* 
in a collection, its sounds like a terrible idea to do so.

Also, if the "they" in your last sentence refers to an object and its copy, 
then Ken already pointed out earlier in this thread that there's no requirement 
that:

[object isEqual: [object copy]]

although that would typically be expected. So, there's also no requirement that:

[object hash] == [[object copy] hash]


___

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

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

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

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

Re: Playing Music in Objective C

2012-02-13 Thread Charles Srstka
On Feb 13, 2012, at 10:03 AM, Kyle Sluder wrote:

> On Feb 12, 2012, at 11:02 AM, Charles Srstka  wrote:
> 
>> I’d suggest looking at QTMovie — more customizable than NSSound, and just 
>> about as simple to use.
>> 
> 
> If you're targeting Lion, do not use QTMovie. Use AVFoundation instead.
> 
> --Kyle Sluder

IMO, there are still too many users on Snow Leopard to justify targeting Lion 
exclusively just yet. AVFoundation is nice, but for a lot of people I suspect 
it will have to wait a while.

Charles
___

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

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

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

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

Re: NSDateFormatter not working on iOS 5.

2012-02-13 Thread Peter Edberg

On Feb 2, 2012, at 7:56 AM, John Joyce wrote:

> 
> On Feb 2, 2012, at 2:20 AM, Peter Edberg wrote:
> 
>> 
>> On Jan 31, 2012, at 2:35 PM, cocoa-dev-requ...@lists.apple.com wrote:
>>> --
>>> 
>>> Message: 1
>>> Date: Tue, 31 Jan 2012 14:10:13 -0600
>>> From: Heath Borders 
>>> To: cocoa-dev 
>>> 
>>> Peter,
>>> 
>>> If I set the locale to "en_IN" shouldn't that show the short time zone?
>>> 
>>> NSLocale *indianEnglishLocale = [[[NSLocale alloc]
>>> initWithLocaleIdentifier:@"en_IN"] autorelease];
>>> NSTimeZone *timeZone = [NSTimeZone timeZoneWithName:@"Asia/Kolkata"];
>>> NSDateFormatter *dateFormatter = [[[NSDateFormatter alloc] init] 
>>> autorelease];
>>> dateFormatter.locale = indianEnglishLocale;
>>> dateFormatter.dateFormat = @"z";
>>> dateFormatter.timeZone = timeZone;
>>> 
>>> NSLog(@"date string: %@", [dateFormatter stringFromDate:[NSDate date]]);
>>> NSLog(@"time zone abbreviation: %@", [timeZone
>>> abbreviationForDate:[NSDate date]]);
>>> 
>>> output:
>>> 
>>> date string: GMT+05:30
>>> time zone abbreviation: IST
>>> 
>>> -Heath Borders
>> 
>> 
>> Heath,
>> Yes, you are correct, for the example you provided above, [dateFormatter 
>> stringFromDate:[NSDate date]] *should* use the short time zone name "IST". 
>> The fact that it does not is due to a deficiency in the "en_IN" locale data 
>> in the versions of CLDR data used by ICU in the current OSX and iOS releases 
>> (CLDR 1.9.1 and 2.0 respectively). The "en_IN" locale in those CLDR versions 
>> did not override or supplement any of the timezone name data from the base 
>> "en" locale, whose default content is for "en_US".
>> 
>> This is already fixed for the CLDR 21 release coming in a few days. That is 
>> being incorporated into ICU 49 which will be picked up in future OSX and iOS 
>> releases.
>> 
>> - Peter E
>> 

> Is there any recommended workaround approach for this kind of scenario until 
> those updates are incorporated?
> More specifically, how would one best implement a workaround that would be 
> easily overridden by (or not clash terribly) the fix when it is eventually 
> incorporated into a release?
> Any best practices or recommendations in that area?

I will need to think about the best current workaround for this, but right now 
I am (and have been) swamped, sorry.
- Peter E

> 


___

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

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

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

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


Re: Playing Music in Objective C

2012-02-13 Thread Kyle Sluder
On Mon, Feb 13, 2012 at 9:49 AM, Charles Srstka
 wrote:
> On Feb 13, 2012, at 10:03 AM, Kyle Sluder wrote:
>
>> On Feb 12, 2012, at 11:02 AM, Charles Srstka  
>> wrote:
>>
>>> I’d suggest looking at QTMovie — more customizable than NSSound, and just 
>>> about as simple to use.
>>>
>>
>> If you're targeting Lion, do not use QTMovie. Use AVFoundation instead.
>>
>> --Kyle Sluder
>
> IMO, there are still too many users on Snow Leopard to justify targeting Lion 
> exclusively just yet. AVFoundation is nice, but for a lot of people I suspect 
> it will have to wait a while.

Our figures are showing 40%-60% adoption for Lion:  http://update.omnigroup.com/

Whether that's enough to justify making your product Lion-only is a
judgment call only you can make.

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

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

Re: Odd display of percent character

2012-02-13 Thread Kyle Sluder
On Mon, Feb 13, 2012 at 9:04 AM, Chris Paveglio
 wrote:
> I'm having an issue with the percent character being displayed as random 
> numbers in an NSAlertPanel (modal). My app has an ivar, "fullString", 
> including the usual property/synthesize getters and setters, there is nothing 
> special about it. fullString is bound to an NSTextField where a user might 
> type "10% off all shoes", or put some text that contains dollar signs or 
> percent signs. Later another method will validate if it's a web address or 
> plain text and display an alert if it's not a web address. At this point I 
> use the usual -stringWithFormat and put the "fullString" text in with some 
> other descriptive text. But if fullString contains a percent character, then 
> the NSAlert displays something like "10254458745ff all shoes". Why is the 
> percent character being turned into some numbers, and it also seems to lop 
> off the space and letter o as well? Using ampersand, dollar sign, and number 
> symbol all display properly.

NSAlert takes a format string. Therefore you must take care to never
ever pass user input as part of the format string.

NSString *fullString = managedObj.fullString;
NSString *informativeText = [NSString stringWithFormat:@"The
fullString %@ is invalid.", fullString];
NSAlert *alert = [NSAlert alertWithMessageText:…
informativeTextWithFormat:@"%@", informativeText];

Note the use of "%@" as the format argument.

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

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

Re: Odd display of percent character

2012-02-13 Thread Ken Thomases
On Feb 13, 2012, at 11:04 AM, Chris Paveglio wrote:

> I'm having an issue with the percent character being displayed as random 
> numbers in an NSAlertPanel (modal). My app has an ivar, "fullString", 
> including the usual property/synthesize getters and setters, there is nothing 
> special about it. fullString is bound to an NSTextField where a user might 
> type "10% off all shoes", or put some text that contains dollar signs or 
> percent signs. Later another method will validate if it's a web address or 
> plain text and display an alert if it's not a web address. At this point I 
> use the usual -stringWithFormat and put the "fullString" text in with some 
> other descriptive text. But if fullString contains a percent character, then 
> the NSAlert displays something like "10254458745ff all shoes". Why is the 
> percent character being turned into some numbers, and it also seems to lop 
> off the space and letter o as well? Using ampersand, dollar sign, and number 
> symbol all display properly.
> FWIW, I am using objective-C++, because my QR code library project is C++ and 
> I need to compile it all the same (first time I've had to do anything like 
> this). Would that be somehow mangling my string in the NSAlert display? If I 
> do NSLog on the string displayed in the NSAlert it also logs properly. So why 
> the discrepancy in the Alert?

Show your code.  It sounds like you are using fullString as a format string, 
not as an argument being formatted into a format string.  In the format string, 
percent signs introduce format specifiers (e.g. %d, %@, etc.).  That's what's 
causing the percent signs in your string to produce odd results.

Regards,
Ken


___

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

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

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

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


Re: Odd display of percent character

2012-02-13 Thread Keary Suska
On Feb 13, 2012, at 10:04 AM, Chris Paveglio wrote:

> I'm having an issue with the percent character being displayed as random 
> numbers in an NSAlertPanel (modal). My app has an ivar, "fullString", 
> including the usual property/synthesize getters and setters, there is nothing 
> special about it. fullString is bound to an NSTextField where a user might 
> type "10% off all shoes", or put some text that contains dollar signs or 
> percent signs. Later another method will validate if it's a web address or 
> plain text and display an alert if it's not a web address. At this point I 
> use the usual -stringWithFormat and put the "fullString" text in with some 
> other descriptive text. But if fullString contains a percent character, then 
> the NSAlert displays something like "10254458745ff all shoes". Why is the 
> percent character being turned into some numbers, and it also seems to lop 
> off the space and letter o as well? Using ampersand, dollar sign, and number 
> symbol all display properly.
> FWIW, I am using objective-C++, because my QR code library project is C++ and 
> I need to compile it all the same (first time I've had to do anything like 
> this). Would that be somehow mangling my string in the NSAlert display? If I 
> do NSLog on the string displayed in the NSAlert it also logs properly. So why 
> the discrepancy in the Alert?


% is a format specifier, so you must escape them (by doubling them, "%%") if 
you are using it as a format string, even if what follows the % is not a known 
specifier. In your case, "o" means show an unsigned int in octal and the space 
after the % means pad spaces instead of zeros. The number is being derived from 
whichever parameter is being eaten up by the specifier. If it is an object, it 
is converting the pointer address to an int and then showing it in octal. 
Normally you would get a warning about this, unless you don't have decent 
warnings set...

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

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


Re: Odd display of percent character

2012-02-13 Thread Chris Paveglio
I was thinking it had something to do with the % formatter, but wasn't sure how 
to "escape" it, or if there was something different about NSAlert. I totally 
understand now how it works, as the "informativeTextWithFormat" automatically 
reads the % as another format placeholder.
Thanks Kyle, Ken and Keary!


- Original Message -
From: Kyle Sluder 
To: Chris Paveglio 
Cc: Cocoa Dev List 
Sent: Monday, February 13, 2012 1:22 PM
Subject: Re: Odd display of percent character

On Mon, Feb 13, 2012 at 9:04 AM, Chris Paveglio
 wrote:
> I'm having an issue with the percent character being displayed as random 
> numbers in an NSAlertPanel (modal). My app has an ivar, "fullString", 
> including the usual property/synthesize getters and setters, there is nothing 
> special about it. fullString is bound to an NSTextField where a user might 
> type "10% off all shoes", or put some text that contains dollar signs or 
> percent signs. Later another method will validate if it's a web address or 
> plain text and display an alert if it's not a web address. At this point I 
> use the usual -stringWithFormat and put the "fullString" text in with some 
> other descriptive text. But if fullString contains a percent character, then 
> the NSAlert displays something like "10254458745ff all shoes". Why is the 
> percent character being turned into some numbers, and it also seems to lop 
> off the space and letter o as well? Using ampersand, dollar sign, and number 
> symbol all display properly.

NSAlert takes a format string. Therefore you must take care to never
ever pass user input as part of the format string.

NSString *fullString = managedObj.fullString;
NSString *informativeText = [NSString stringWithFormat:@"The
fullString %@ is invalid.", fullString];
NSAlert *alert = [NSAlert alertWithMessageText:…
    informativeTextWithFormat:@"%@", informativeText];

Note the use of "%@" as the format argument.

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

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

Re: Odd display of percent character

2012-02-13 Thread Michael Babin
On Feb 13, 2012, at 11:04 AM, Chris Paveglio wrote:

> I'm having an issue with the percent character being displayed as random 
> numbers in an NSAlertPanel (modal). My app has an ivar, "fullString", 
> including the usual property/synthesize getters and setters, there is nothing 
> special about it. fullString is bound to an NSTextField where a user might 
> type "10% off all shoes", or put some text that contains dollar signs or 
> percent signs. Later another method will validate if it's a web address or 
> plain text and display an alert if it's not a web address. At this point I 
> use the usual -stringWithFormat and put the "fullString" text in with some 
> other descriptive text. But if fullString contains a percent character, then 
> the NSAlert displays something like "10254458745ff all shoes". Why is the 
> percent character being turned into some numbers, and it also seems to lop 
> off the space and letter o as well? Using ampersand, dollar sign, and number 
> symbol all display properly.
> FWIW, I am using objective-C++, because my QR code library project is C++ and 
> I need to compile it all the same (first time I've had to do anything like 
> this). Would that be somehow mangling my string in the NSAlert display? If I 
> do NSLog on the string displayed in the NSAlert it also logs properly. So why 
> the discrepancy in the Alert?

You did not provide a code snippet showing how the string is used, but you 
mentioned using -[NSString stringWithFormat:]. My guess would be that 
fullString is being interpreted somewhere as a format string, where the % is 
interpreted as a format directive/specifier. %o is unsigned 32-bit integer 
(unsigned int), printed in octal, which matches what you're reporting as the 
results. If so, rewrite your code so fullString is not interpreted as a format 
string when composing your message/output.


___

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

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

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

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


Re: NSReadPixel

2012-02-13 Thread Seth Willits
On Feb 13, 2012, at 9:21 AM, Kyle Sluder wrote:

> But I don't think a screen-sized window is necessary. You might be able to 
> create a transparent 1px-by-1px window that follows the cursor hotspot, then 
> lock focus on its contentView and call NSReadPixel.

It'll lag.


--
Seth Willits





___

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

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

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

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


NSEvent locationInWindow undefined for non-mouse events, how to catch?

2012-02-13 Thread Sean McBride
Hi all,

The NSEvent locationInWindow docs say: "For non-mouse events the return value 
of this method is undefined."

I've just been bitten by this.  Seems it would be easy to detect at runtime and 
assert, is there any magic environment variable or defaults value that can help 
me catch such incorrect usage?  I've searched but not found...

Cheers,

-- 

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

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

iCal syncing on multiple computers

2012-02-13 Thread Gideon King
Hi,

I have some data that is synced with iCal by my application. I get the 
calendars, and the user selects which one to sync to, and in my data, I save 
the UID for the calendar we have synced with.

Now the user moves to a different computer and can't sync, since the same 
calendar is not available on that computer. So I ask them to select another 
calendar to sync with.

BUT, in some cases the calendar on computer 1 is synced with iCloud, and is 
synced to a calendar on the other computer. So in actual fact, the exact same 
calendar with a different UID is available on the other computer.

Is there any way of me knowing that both those calendars are synced with each 
other on iCloud, and therefore effectively the same calendar?

Thanks


Gideon







___

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

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

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

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