Re: Why are these objects still faults?

2011-07-19 Thread vincent habchi
Le 19 juil. 2011 à 07:21, Gideon King  a écrit :

> But I told it to pre-fetch the view relationship. Any ideas why it wouldn't 
> work?

Maybe a silly answer, but isn’it a side effect of lazy loading?

V.

> 

___

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

Please do not post 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: NSArrayController nib binding vs code binding

2011-07-19 Thread Mike Abdullah

On 19 Jul 2011, at 02:41, Trygve Inda wrote:

>> [myArrayController bind:@"content" toObject:myClassObject
>> withKeyPath:@"places" options:NULL];
> 
> Hmm... Seems like it should be bind:@"contentArray"

Please use the NSContentArrayBinding constant as that's what's it exists for, 
despite being fairly hidden away!___

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

Please do not post 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


Optimizing a loop

2011-07-19 Thread Eric E. Dolecki
I have an NSMutableArray that contains a MPMediaItem and song title as it's
key.

 I then take a search string and loop through the entire NSMutableArray
looking for a fuzzy match. It works very well, the problem is that the array
contains 1,777 items (could contain more) and the search takes about 6
seconds on iOS. I am wondering how I could optimize this to get the search
time down. I was thinking of splitting the array into 2 or something, just
not really sure what the best approach might be.

Here is some code I am using (stringValue passed in through the method):

@autoreleasepool {
float currentFoundValue = 1000.0;
MPMediaItem *test;
NSArray *dis;
MPMediaItemCollection *collection;
float match;
*//This takes about 6 seconds each search for song*
for (id key in songsDictionary) {
NSString *thisSong = key;
int suppliedCount = [stringValue length];
int keyCount = [thisSong length];
//Fuzzy matching
if(suppliedCount > keyCount){
match= [StringDistance stringDistance:thisSong
:stringValue];
} else {
match= [StringDistance stringDistance:stringValue
:thisSong];
}
//Get the very best match there is to be found for song.
if(match < currentFoundValue){
currentFoundValue = match;
test = [songsDictionary objectForKey:thisSong];
dis = [NSArray arrayWithObject:test];
collection = [[MPMediaItemCollection alloc]
initWithItems:dis];
}
}

if([collection count] != 0){
[musicPlayer setQueueWithItemCollection:collection];
[musicPlayer play];
//Used to populate a UITableView
songsArray = [[NSMutableArray alloc] init];
@autoreleasepool {
for (MPMediaItem *song in dis) {
NSString *title = [song
valueForProperty:MPMediaItemPropertyTitle];
[songsArray addObject:title];
}
}
[myTable reloadData];
[myTable flashScrollIndicators];
countView.hidden = NO;
countLabel.text = [NSString stringWithFormat:@"%d",
[songsArray count]];
} else {
NSString *msg = [NSString stringWithFormat:@"Search could
not find the song \"%@\". Please try again.", stringValue];
UIAlertView* alert = [[UIAlertView alloc] initWithTitle:@"Song
Not Found"
message:msg

 delegate:self
  cancelButtonTitle:@
"OK"

otherButtonTitles:nil];
[alert show];
}
}

Thanks for any suggestions.

- Eric
___

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

Please do not post 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 are these objects still faults?

2011-07-19 Thread Heath Borders
Is your topic node self-referential? Maybe CoreData doesn't prefetch
circular references.

-Heath Borders
heath.bord...@gmail.com
Twitter: heathborders
http://heath-tech.blogspot.com



On Tue, Jul 19, 2011 at 12:21 AM, Gideon King  wrote:
> Hi, I'm doing a fetch of some objects like this:
>
> entity = [NSEntityDescription entityForName:kNMTopicNodeEntityKey 
> inManagedObjectContext:[self managedObjectContext]];
> request = [[NSFetchRequest alloc] init];
> [request setEntity:entity];
> [request setRelationshipKeyPathsForPrefetching:[NSArray 
> arrayWithObjects:@"topic",@"view", nil]];
>
> results = [[self managedObjectContext] executeFetchRequest:request 
> error:&error];
> if (results) {
>        log4Debug(@"Loaded %d topic nodes", [results count])
> }
> [request release];
>
>
> The log tells me id loaded my 2,000 topics.
>
> Then later, I do the following:
>
> // This is an array of topic nodes - the things that I have just fetched
> NSArray *allTopics = [map.rootTopicNode allDescendantTopicNodesIncludingSelf];
>
> NSSortDescriptor *sd = nil;
> if (floor(NSAppKitVersionNumber) > NSAppKitVersionNumber10_5) {
>        sd = [NSSortDescriptor sortDescriptorWithKey:@"view.zIndex" 
> ascending:YES];
> } else {
>        sd = [[[NSSortDescriptor alloc] initWithKey:@"view.zIndex" 
> ascending:YES] autorelease];
> }
>
> for (NMTopicNodeMO *node in [allTopics sortedArrayUsingDescriptors:[NSArray 
> arrayWithObject:sd]]) {
>        Do stuff
> }
>
>
> But this was running really slowly, so I commented out the above couple of 
> lines, and did the following check:
>
> for (NMTopicNodeMO *ttn in allTopics) {
>        if ([ttn isFault]) {
>                log4Debug(@"Node is a fault");
>        }
>        if ([ttn.view isFault]) {
>                log4Debug(@"View is fault");
>        }
> }
>
> ...and it told me that the view was a fault for every topic node (but none of 
> the topic nodes were faults)!
>
> But I told it to pre-fetch the view relationship. Any ideas why it wouldn't 
> work?
>
>
>
> TIA
>
> 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:
> http://lists.apple.com/mailman/options/cocoa-dev/heath.borders%40gmail.com
>
> This email sent to heath.bord...@gmail.com
>
___

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

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

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

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


Re: Optimizing a loop

2011-07-19 Thread Vincent Habchi
> I have an NSMutableArray that contains a MPMediaItem and song title as it's
> key.
> 
> I then take a search string and loop through the entire NSMutableArray
> looking for a fuzzy match. It works very well, the problem is that the array
> contains 1,777 items (could contain more) and the search takes about 6
> seconds on iOS. I am wondering how I could optimize this to get the search
> time down. I was thinking of splitting the array into 2 or something, just
> not really sure what the best approach might be.

It's not easy, but I would recommend using a hash table instead. You can 
compute a hash code that depends more or less on the spelling of your strings, 
then use that hash key to access a set of candidate for your fuzzy search.

Vincent___

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

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

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

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


Re: Optimizing a loop

2011-07-19 Thread Eric E. Dolecki
Oops - I meant to say it's an NSMutableDictionary!

What might a quick stubbed example of that be? Not sure I am following. How
much speed would it generally gain?



  Google Voice: (508) 656-0622
  Twitter: eric_dolecki  XBoxLive: edolecki  PSN: eric_dolecki
  http://blog.ericd.net



On Tue, Jul 19, 2011 at 9:22 AM, Vincent Habchi  wrote:

> > I have an NSMutableArray that contains a MPMediaItem and song title as
> it's
> > key.
> >
> > I then take a search string and loop through the entire NSMutableArray
> > looking for a fuzzy match. It works very well, the problem is that the
> array
> > contains 1,777 items (could contain more) and the search takes about 6
> > seconds on iOS. I am wondering how I could optimize this to get the
> search
> > time down. I was thinking of splitting the array into 2 or something,
> just
> > not really sure what the best approach might be.
>
> It's not easy, but I would recommend using a hash table instead. You can
> compute a hash code that depends more or less on the spelling of your
> strings, then use that hash key to access a set of candidate for your fuzzy
> search.
>
> Vincent
___

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

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

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

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


Re: Optimizing a loop

2011-07-19 Thread Vincent Habchi
> Oops - I meant to say it's an NSMutableDictionary!
> 
> What might a quick stubbed example of that be? Not sure I am following. How 
> much speed would it generally gain?

Simple example. Init a NSMutableDictionary. For each string, compute a hash key 
as the sum of all chars composing it (in a short or int), divide it by 8 
(that's quick). This way, all the words that differ by just one char being 
exchanged (metathesis), or look more or less the same, will get an identical 
hash code.

In your mutable dictionary, use the hash key as the key, the object being an 
NSMutableArray where you put all the strings that share the same hash key. Then 
use the contents of this NSMutableArray as proposals for your user. That should 
be really fast. Refine the process if you need more grain. 

Vincent___

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

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

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

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


Re: Optimizing a loop

2011-07-19 Thread Eric E. Dolecki
Someone told me to look into -enumerateKeysAndObjectsWithOptions:usingBlock:
(using NSEnumerationConcurrent) Would that be a better way? If so, I haven't
seen this used before - how could I apply it?

- Eric

>
> Simple example. Init a NSMutableDictionary. For each string, compute a hash
> key as the sum of all chars composing it (in a short or int), divide it by 8
> (that's quick). This way, all the words that differ by just one char being
> exchanged (metathesis), or look more or less the same, will get an identical
> hash code.
>
> In your mutable dictionary, use the hash key as the key, the object being
> an NSMutableArray where you put all the strings that share the same hash
> key. Then use the contents of this NSMutableArray as proposals for your
> user. That should be really fast. Refine the process if you need more grain.
>
> Vincent
___

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

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

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

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


Re: Optimizing a loop

2011-07-19 Thread Vincent Habchi
> Someone told me to look into -enumerateKeysAndObjectsWithOptions:usingBlock: 
> (using NSEnumerationConcurrent) Would that be a better way? If so, I haven't 
> seen this used before - how could I apply it?

You can try to use that, but, basically, it is the same problem: you enumerate 
all entries in your dictionary and compute your string distance for each, which 
is cumbersome. The algorithm I propose you is way faster, because you don't 
have to recompute this distance each time you search. But, once again, the 
crude way to compute a hash code might not suit your needs.

Vincent___

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

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

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

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


Re: Optimizing a loop

2011-07-19 Thread Eric E. Dolecki
Thanks. The distance is computed because the entry string is dynamic and
it's providing a distance between the title of the song and what was entered
as text. So I can't pre-compute that data and stuff into a dictionary. Each
time the method is called, the *stringValue* will be different.

On Tue, Jul 19, 2011 at 9:55 AM, Vincent Habchi  wrote:

> > Someone told me to look into
> -enumerateKeysAndObjectsWithOptions:usingBlock: (using
> NSEnumerationConcurrent) Would that be a better way? If so, I haven't seen
> this used before - how could I apply it?
>
> You can try to use that, but, basically, it is the same problem: you
> enumerate all entries in your dictionary and compute your string distance
> for each, which is cumbersome. The algorithm I propose you is way faster,
> because you don't have to recompute this distance each time you search. But,
> once again, the crude way to compute a hash code might not suit your needs.
>
> Vincent
___

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

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

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

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


Re: Optimizing a loop

2011-07-19 Thread Vincent Habchi
> Thanks. The distance is computed because the entry string is dynamic and it's 
> providing a distance between the title of the song and what was entered as 
> text. So I can't pre-compute that data and stuff into a dictionary. Each time 
> the method is called, the stringValue will be different.

Yep, I understand.

What you do is that for each entry string you compute the hash key (which is 
fast, as it is only a sum of chars), and you select the key which is the 
nearest to your dynamic key. You can do that on the fly.

Somehow, if you want to compare only strings of the same length, you have to 
rely on a two level dictionary, or make your key special (e.g. the upper byte 
contains the string length, the lower bytes are the hash key).

Vincent___

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

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

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

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


Re: Optimizing a loop

2011-07-19 Thread Eric E. Dolecki
I think I see what you're onto here now. So I might only have about 30 or so
keys to search through instead of all 1,777 items, and then just grab an
array (or probably a dictionary) of stuff out of that to search on...
resulting in a lot less searching to hopefully get to a potential match.

a song search for "Cold Wind to Valhalla" ... char count of 21, look in the
dictionary for key of int 21 (or close), and check it (probably another
dictionary) for it's key of the title to get the MPMediaItem.


  Google Voice: (508) 656-0622
  Twitter: eric_dolecki  XBoxLive: edolecki  PSN: eric_dolecki
  http://blog.ericd.net



On Tue, Jul 19, 2011 at 10:36 AM, Vincent Habchi  wrote:

> > Thanks. The distance is computed because the entry string is dynamic and
> it's providing a distance between the title of the song and what was entered
> as text. So I can't pre-compute that data and stuff into a dictionary. Each
> time the method is called, the stringValue will be different.
>
> Yep, I understand.
>
> What you do is that for each entry string you compute the hash key (which
> is fast, as it is only a sum of chars), and you select the key which is the
> nearest to your dynamic key. You can do that on the fly.
>
> Somehow, if you want to compare only strings of the same length, you have
> to rely on a two level dictionary, or make your key special (e.g. the upper
> byte contains the string length, the lower bytes are the hash key).
>
> Vincent
___

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

Please do not post 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 are these objects still faults?

2011-07-19 Thread Gideon King
Interesting idea. The structure is that I have a grandparent with just a single 
attribute, a parent which has parent and children (self referential) 
relationships, and a couple of one way to-one self referential relationships on 
the topic node object itself, so there are a few things going on there

...but the relationship to view is a simple to-one relationship with an 
inverse, so I would have thought it would be easy to fetch. Also I did a check 
on the topic relationship (to-one out and to-many in) which was supposed to be 
pre-fetched too, and they were all faults too.

Regards

Gideon


On 19/07/2011, at 11:05 PM, Heath Borders wrote:

> Is your topic node self-referential? Maybe CoreData doesn't prefetch
> circular references.
> 

___

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

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

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

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


Re: Optimizing a loop

2011-07-19 Thread Jens Alfke

On Jul 19, 2011, at 6:22 AM, Vincent Habchi wrote:

> It's not easy, but I would recommend using a hash table instead. You can 
> compute a hash code that depends more or less on the spelling of your 
> strings, then use that hash key to access a set of candidate for your fuzzy 
> search.

I take it SearchKit isn’t available on iOS? :(

Might also be worth looking into the venerable Soundex algorithm, which 
converts a word to a string that’s sort-of like a phonetic representation of 
it. Misspelled words often have the same Soundex value as the original word. 
It’s widely used for fuzzy string matching.

—Jens___

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

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

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

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


Re: Understanding layer-backed views

2011-07-19 Thread Michael Crawford
Graham; Scott,

I have a follow-up question on this topic, if you don't mind.  Do either of you 
have a recommendation on the idea of adding a layer-hosting view as a subview 
of a layer-backed view?  I'm thinking of adding a virtual keyboard to an 
existing app that is layer-backed.  I would like this VK view to have all the 
benefits that NSView brings including event handling without all of the 
heavy-weight of multiple subviews for the keyboard mechanics.

Can I mix these?

(Please reply to the thread for everyone's benefit.)

-Michael

On Jun 22, 2011, at 3:02 AM, Scott Anguish wrote:

>> Yep, I'm aware of the setWantsLayer/setLayer order making a difference.
>> 
>> In my case I want a layer-hosting view, not a layer-backed view.
>> 
>> However, my question isn't really about that, but about what is done when 
>> you check the box next to the layer in Interface Builder, in the 
>> 'setWantsLayer' panel. Does this provide layer backing or layer hosting? My 
>> thoughts were that is provides layer hosting, but I'm not 100% sure. 
>> Proceeding on the basis that this is the case, it seems to work.
>> 
> 
> layer-backed.
> 
> 
> 
> 
>> 
>>> Again this is not in line with my expectations, which is that the frame of 
>>> a sublayer is expressed in the coordinate system of its superlayer, not the 
>>> underlying window.
>> 
>> I found the cause of this issue, which was that in my layer delegate, I was 
>> not saving, setting and restoring the context passed to 
>> drawLayer:inContext:. I was assuming that the context was set, but having 
>> found a code snippet in the docs that indicated it wasn't, I added these 
>> calls and my graphics are drawing in the right place now.
>> 
> 
> great!___
> 
> Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)
> 
> Please do not post 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/michaelacrawford%40me.com
> 
> This email sent to michaelacrawf...@me.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: Optimizing a loop

2011-07-19 Thread Greg Guerin

Eric E. Dolecki wrote:

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

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



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


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


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


  -- GG

___

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

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

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

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


32 -> 64 bit serializations, NSNumber, int, NSInteger

2011-07-19 Thread Philip Dow
Related to a previous posting of mine regarding floats and CGFloats when 
decoding older 32 bit serializations in a 64 bit runtime, I am now also in the 
process of modernizing some old code that used int values encapsulated by 
NSNumber in keyed archives.

The current serializations were performed in a 32 bit environment. I am now 
running in a 64 bit environment and am reading those archives. The archives 
contain NSNumber objects which stored int values. I would like to update the 
code to use NSInteger instead and the corresponding methods on the NSNumber 
objects.

Will I run into a similar decoding problem where the int values will not be 
correctly read as longs in the new environment, or is NSNumber taking care of 
things under the hood for me?

~Phil

On Jul 13, 2011, at 12:47 PM, Philip Dow wrote:

> Brilliant. Thank you Glenn. I compiled the app for 32 bit and it read the 
> archive fine. I've created my own struct with floats for reading the archive 
> in 64 bit and am coercing the data into doubles after the decoding.
> 
> ~Phil
> 
> On Jul 13, 2011, at 12:30 PM, glenn andreas wrote:
> 
>> Are you decoding it from a 64 bit app?  Because CGRect on 64 bits is made of 
>> doubles, while on 32 bits (where it was probably encoded) it was made of 
>> floats
>> 
>> Also, the exact format for @encode() varies greatly between compiler version 
>> (especially with regards for things like structure names vs ?, etc...).  
>> This, in and of itself, shouldn't make it incompatible, but a structure with 
>> two structures each with two floats doesn't match with the double-based 
>> CGRect.
>> 
>> On Jul 13, 2011, at 12:20 PM, Philip Dow wrote:
>> 
>>> I am trying to decode a 3rd party archive encoded in the old NSArchiver 
>>> (not keyed) format. At a point in the decoding, I expect to find a CGRect, 
>>> but when I call 
>>> 
>>> [coder decodeValueOfObjCType:@encode(CGRect) at:&myRect]
>>> 
>>> an exception is raised with the error:
>>> 
>>> file inconsistency: read '{?={?=ff}{?=ff}}', expecting 
>>> '{CGRect={CGPoint=dd}{CGSize=dd}}'
>>> 
>>> Sure enough, if I open the file in a text editor, I see {?={?=ff}{?=ff}}.
>>> 
>>> According to the docs, the curly braces indicate a structure is encoded, 
>>> which I would expect for CGRect, but the ? indicates an unknown type. I'm 
>>> stumped for a solution and was wondering if anyone might have an insight.
>>> 
>>> ~Phil___
>>> 
>>> Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)
>>> 
>>> Please do not post 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/gandreas%40mac.com
>>> 
>>> This email sent to gandr...@mac.com
>> 
>> 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/dev%40getsprouted.com
> 
> This email sent to d...@getsprouted.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


Modal dialog, run loop and core data

2011-07-19 Thread Vincent
Hi!

I'm facing a little dilemma: in a modal dialog, I'd like to create a new core 
data entity with -[aNSArrayControllerInEntityMode insert:] and initialize some 
attributes of this new entity.

However, the creation and insertion of the new entity is delayed one run loop 
iteration; but, in a modal dialog, the run loop is stopped! So, what I am to 
do? Use -[NSApp beginModalSessionForWindow:] and -[NSApp 
endModalSessionForWindow:] instead of just [NSApp runModalForWindow:]?

Any suggestion?

Thanks,
Vincent___

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

Please do not post 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


Simple iOS app works on device but crashes in simulator, in AppleSpell

2011-07-19 Thread Jens Alfke
I’m working on a fairly simple iOS app with some other folks, and it works fine 
for me on a real iOS device, but whenever I run it in the 4.3 simulator it 
crashes as soon as I type a few characters into a text field. The crash is 
always inside the system method -[AppleSpell init]. The other developers 
haven’t had this problem. Any idea what might be going on? I’m wondering if 
something got corrupted in the simulator’s persistent state; but deleting and 
re-installing the app doesn’t help.

—Jens

(gdb) bt
#0  0x015ce000 in objc_assign_ivar ()
#1  0x039d3c34 in -[AppleSpell init] ()
#2  0x00bee538 in -[UITextChecker _checker] ()
#3  0x00befde9 in -[UITextChecker 
checkSpellingOfString:startingAt:language:wrap:correction:] ()
#4  0x0c01f725 in TIInputManagerZephyr::lookup_spellcheck_candidates ()
#5  0x0c01f609 in TIInputManagerZephyr::lookup_static_dynamic_candidates ()
#6  0x0c01cb2b in TIInputManager::lookup ()
#7  0x0c01ce18 in TIInputManager::autocorrection ()
#8  0x0c03406b in -[TIKeyboardInputManagerZephyr autocorrection] ()
#9  0x009d6be8 in -[UIKeyboardImpl generateCandidatesWithCompletions:] ()
#10 0x009d6c3b in -[UIKeyboardImpl generateCandidates] ()
#11 0x009e3a23 in -[UIKeyboardImpl addInputString:fromVariantKey:] ()
#12 0x009e571b in -[UIKeyboardImpl handleKeyEvent:] ()
#13 0x008a901c in -[UIApplication handleEvent:withNewEvent:] ()
#14 0x008a0abf in -[UIApplication sendEvent:] ()
#15 0x008a5f2e in _UIApplicationHandleEvent ()
...___

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

Please do not post 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: Modal dialog, run loop and core data

2011-07-19 Thread Jens Alfke

On Jul 19, 2011, at 11:31 AM, Vincent wrote:

> I'm facing a little dilemma: in a modal dialog, I'd like to create a new core 
> data entity with -[aNSArrayControllerInEntityMode insert:] and initialize 
> some attributes of this new entity.

I know it’s considered rude to answer a coding question with a UI critique, but 
the best solution would really be to avoid using a modal dialog at all. They’re 
a poor user experience compared to a sheet or some other kind of in-window 
display, and as you’ve seen, they can cause complications with runloops.

> However, the creation and insertion of the new entity is delayed one run loop 
> iteration; but, in a modal dialog, the run loop is stopped! So, what I am to 
> do? Use -[NSApp beginModalSessionForWindow:] and -[NSApp 
> endModalSessionForWindow:] instead of just [NSApp runModalForWindow:]?

The runloop isn’t stopped, it’s just running nested in a different mode 
(NSModalPanelRunloopMode). But most API methods that schedule things only 
schedule them in the default runloop mode, so they won’t get time to run while 
a model panel is up. The workaround is to use variant scheduling methods that 
take an array of runloop modes (usually it’s an extra parameter like 
“inModes:”), and explicitly let them run in the modal mode.

—Jens___

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

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

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

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


Re: Simple iOS app works on device but crashes in simulator, in AppleSpell

2011-07-19 Thread Jens Alfke

On Jul 19, 2011, at 11:46 AM, I wrote:

> I’m working on a fairly simple iOS app with some other folks, and it works 
> fine for me on a real iOS device, but whenever I run it in the 4.3 simulator 
> it crashes as soon as I type a few characters into a text field. The crash is 
> always inside the system method -[AppleSpell init]. The other developers 
> haven’t had this problem. Any idea what might be going on? I’m wondering if 
> something got corrupted in the simulator’s persistent state; but deleting and 
> re-installing the app doesn’t help.

For the record: I got an authoritative answer off-list, and this is a known 
issue with, uh, certain pre-release Apple software I’m using. There is a 
workaround. Email me directly if you’re in the same boat and I’ll give you the 
answer.

—Jens___

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

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

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

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


Re: Modal dialog, run loop and core data

2011-07-19 Thread Vincent
Hi Jens,

> I know it’s considered rude to answer a coding question with a UI critique, 
> but the best solution would really be to avoid using a modal dialog at all. 
> They’re a poor user experience compared to a sheet or some other kind of 
> in-window display, and as you’ve seen, they can cause complications with 
> runloops.

You're right. I will probably change this in the near future, but I really need 
a way to synchronously pick up an entity.

> The runloop isn’t stopped, it’s just running nested in a different mode 
> (NSModalPanelRunloopMode). But most API methods that schedule things only 
> schedule them in the default runloop mode, so they won’t get time to run 
> while a model panel is up. The workaround is to use variant scheduling 
> methods that take an array of runloop modes (usually it’s an extra parameter 
> like “inModes:”), and explicitly let them run in the modal mode.

I'll try to register my window controller as an observer for the selected 
property of the NSArrayController. That should do the trick: I always select a 
newly inserted object.

___

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

Please do not post 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


Printing options

2011-07-19 Thread Amy Gibbs

Hi,

I've read everything that says printing is easy...but I'm struggling  
with it!


I have googled, but nothing quite seems to fit my situation, I just  
want a single page.


In my app I have customer orders, and I just want to print out a copy.  
I can't work out what the best option would be. I can probably create  
an html file (and have css to format it) and save it to disk, but then  
I'd still have to print it, either within my app, or with a browser,  
or I could create a PDF and try and print that? or I could lay it all  
out on a view and print that? Some orders have more than 1 item  
though, and tableviews don't seem to print properly so how should I  
lay out a list of products? It should easily fit on 1 page, just a  
name address and a couple of lines of product details.


It's all in a CoreData app,

I'd appreciate any help, Thanks,

Amy
___

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

Please do not post 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: 32 -> 64 bit serializations, NSNumber, int, NSInteger

2011-07-19 Thread Nick Zitzmann

On Jul 19, 2011, at 12:24 PM, Philip Dow wrote:

> Related to a previous posting of mine regarding floats and CGFloats when 
> decoding older 32 bit serializations in a 64 bit runtime, I am now also in 
> the process of modernizing some old code that used int values encapsulated by 
> NSNumber in keyed archives.
> 
> The current serializations were performed in a 32 bit environment. I am now 
> running in a 64 bit environment and am reading those archives. The archives 
> contain NSNumber objects which stored int values. I would like to update the 
> code to use NSInteger instead and the corresponding methods on the NSNumber 
> objects.
> 
> Will I run into a similar decoding problem where the int values will not be 
> correctly read as longs in the new environment, or is NSNumber taking care of 
> things under the hood for me?

You won't know until you try, but with keyed archives and NSNumber, you should 
not run into any problems across architectures, because NSNumber's accessors 
will do conversions as necessary. The only problem I ever had with unarchiving 
32-bit app archives in a 64-bit app was with longs in non-keyed archives that 
were encoded using @encode(long)*, and that doesn't apply to your scenario.

Nick Zitzmann


* The reason was because the value of @encode(long) changed from "l" in 32-bit 
code to "q" in 64-bit code, which is understandable.

___

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

Please do not post 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: 32 -> 64 bit serializations, NSNumber, int, NSInteger

2011-07-19 Thread Quincey Morris
On Jul 19, 2011, at 12:32, Nick Zitzmann wrote:

> The only problem I ever had with unarchiving 32-bit app archives in a 64-bit 
> app was with longs in non-keyed archives that were encoded using 
> @encode(long)*, and that doesn't apply to your scenario.

The other issue that might rear its head is that the meaning of NSNotFound 
changes between 32- and 64-bit runtimes**, which makes a mess of archives that 
use it. The answer, of course, is to keep NSNotFound out of archives, but (as I 
found to my own cost) if existing code archives NSNotFound, it's really, really 
hard to clean the mess up.



** I mean: if you archive NSNotFound in a 32-bit application, it's no longer 
NSNotFound when you unarchive it in a 64-bit application. And vice versa, 
probably.


___

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

Please do not post 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: 32 -> 64 bit serializations, NSNumber, int, NSInteger

2011-07-19 Thread Philip Dow
Thanks for the tips Quincey and Nick. I'll keep an eye out for the use of 
NSNotFound.

~Phil

On Jul 19, 2011, at 2:46 PM, Quincey Morris wrote:

> On Jul 19, 2011, at 12:32, Nick Zitzmann wrote:
> 
>> The only problem I ever had with unarchiving 32-bit app archives in a 64-bit 
>> app was with longs in non-keyed archives that were encoded using 
>> @encode(long)*, and that doesn't apply to your scenario.
> 
> The other issue that might rear its head is that the meaning of NSNotFound 
> changes between 32- and 64-bit runtimes**, which makes a mess of archives 
> that use it. The answer, of course, is to keep NSNotFound out of archives, 
> but (as I found to my own cost) if existing code archives NSNotFound, it's 
> really, really hard to clean the mess up.
> 
> 
> 
> ** I mean: if you archive NSNotFound in a 32-bit application, it's no longer 
> NSNotFound when you unarchive it in a 64-bit application. And vice versa, 
> probably.
> 
> 

___

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

Please do not post 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: NSArrayController nib binding vs code binding

2011-07-19 Thread Trygve Inda
> 
> On 19 Jul 2011, at 02:41, Trygve Inda wrote:
> 
>>> [myArrayController bind:@"content" toObject:myClassObject
>>> withKeyPath:@"places" options:NULL];
>> 
>> Hmm... Seems like it should be bind:@"contentArray"
> 
> Please use the NSContentArrayBinding constant as that's what's it exists for,
> despite being fairly hidden away!

Thanks for this! Hidden indeed.



___

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

Please do not post 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


Stupid (virtual) keyboard mistake... I think

2011-07-19 Thread William Squires
  What's the proper way to detect if the "Enter" key on the virtual (on-screen) 
keyboard in iOS is touched?
  Is this part of the UITextField delegate protocol? Or is it supposed to be 
the "Editing Did End" event you see when you right-click on the UITextField in 
question (in IB, of course)?
  I've tried both; singly and together, but I still can't figure out how to 
determine when the Enter key is tapped. Probably just a stoopid mistake on my 
part. The keyboard appears (in the simulator) when I click on the field, but I 
can't get it to go away unless I put a UIButton the size of the view under all 
the controls, and tie it's "Touch Up Inside" to an action on my view controller 
that just says

-(IBAction)dismissKeyboard:(id)sender
{
[inputField resignFirstReponder];
}

  Surely there's a better way, right?
  Also, how do I get the "Enter" key to show up in the Numpad-style keyboard, 
like in the phone app (which also has an "add to contacts" button as well)? Is 
this a custom view, or is there a way to make this numpad keyboard do this 
normally? Personally, I'm guessing Apple violated (or severely bent) their own 
HIG guidelines by not reusing the numpad keyboard, or they'd have realized 
they're missing something (namely, the "Enter" key), and would have changed it.

___

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

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

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

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


linking an Apple framework into a static lib project and then linking the static lib into an application project...

2011-07-19 Thread Glen Haderman
I've got a Mac/Cocoa static library project.  It links against 
IOKit.framework.  It builds fine.

I take the .a and header and import them into a Mac/Cocoa project.

I get the following linker errors:

Undefined symbols:
  "_IORegistryEntryCreateCFProperty", referenced from:
  +[MyLibrary getThingamajigFromIORegistry] in libMyLibrary.a(MyLibrary.o)
  "_kIOMasterPortDefault", referenced from:
  _kIOMasterPortDefault$non_lazy_ptr in libMyLibrary.a(MyLibrary.o)
 (maybe you meant: _kIOMasterPortDefault$non_lazy_ptr)
  "_IOObjectRelease", referenced from:
  +[MyLibrary getThingamajigFromIORegistry] in libMyLibrary.a(MyLibrary.o)
  "_IORegistryEntryFromPath", referenced from:
  +[MyLibrary getThingamajigFromIORegistry] in libMyLibrary.a(MyLibrary.o)
ld: symbol(s) not found
collect2: ld returned 1 exit status


Adding IOKit.framework to the **application** project resolves the problem 
(obviously), but how can I set everything up so that references to other Apple 
frameworks which are internal to my static library and linked into the static 
library... are honored by the linker when building application projects which 
link against that static library?

I know the difference between static and dynamic libraries, but aren't the 
internally linked libraries (whether dynamic or static) which a static library 
references within its own code saved in the library archive (the references I 
mean) in a way that ld can understand when that .a library is then linked into 
some other project?
___

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

Please do not post 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: Stupid (virtual) keyboard mistake... I think

2011-07-19 Thread William Squires
Oops, should have stipulated: iOS 4 dev on Xcode 3.2.whatever.

On Jul 19, 2011, at 6:57 PM, William Squires wrote:

>  What's the proper way to detect if the "Enter" key on the virtual 
> (on-screen) keyboard in iOS is touched?
>  Is this part of the UITextField delegate protocol? Or is it supposed to be 
> the "Editing Did End" event you see when you right-click on the UITextField 
> in question (in IB, of course)?
>  I've tried both; singly and together, but I still can't figure out how to 
> determine when the Enter key is tapped. Probably just a stoopid mistake on my 
> part. The keyboard appears (in the simulator) when I click on the field, but 
> I can't get it to go away unless I put a UIButton the size of the view under 
> all the controls, and tie it's "Touch Up Inside" to an action on my view 
> controller that just says
> 
> -(IBAction)dismissKeyboard:(id)sender
> {
> [inputField resignFirstReponder];
> }
> 
>  Surely there's a better way, right?
>  Also, how do I get the "Enter" key to show up in the Numpad-style keyboard, 
> like in the phone app (which also has an "add to contacts" button as well)? 
> Is this a custom view, or is there a way to make this numpad keyboard do this 
> normally? Personally, I'm guessing Apple violated (or severely bent) their 
> own HIG guidelines by not reusing the numpad keyboard, or they'd have 
> realized they're missing something (namely, the "Enter" key), and would have 
> changed it.
> 

___

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

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

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

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


Re: Stupid (virtual) keyboard mistake... I think

2011-07-19 Thread Fritz Anderson
On 19 Jul 2011, at 6:57 PM, William Squires wrote:

>  What's the proper way to detect if the "Enter" key on the virtual 
> (on-screen) keyboard in iOS is touched?
>  Is this part of the UITextField delegate protocol?

Like textFieldShouldReturn:?

Or do you mean something else?

— 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: linking an Apple framework into a static lib project and then linking the static lib into an application project...

2011-07-19 Thread Greg Parker

On Jul 19, 2011, at 5:11 PM, Glen Haderman wrote:

> I've got a Mac/Cocoa static library project.  It links against 
> IOKit.framework.  It builds fine.
> 
> I take the .a and header and import them into a Mac/Cocoa project.
> 
> I get the following linker errors:
> 
> Undefined symbols:
>   "_IORegistryEntryCreateCFProperty", referenced from:
>   +[MyLibrary getThingamajigFromIORegistry] in libMyLibrary.a(MyLibrary.o)
>   "_kIOMasterPortDefault", referenced from:
>   _kIOMasterPortDefault$non_lazy_ptr in libMyLibrary.a(MyLibrary.o)
>  (maybe you meant: _kIOMasterPortDefault$non_lazy_ptr)
>   "_IOObjectRelease", referenced from:
>   +[MyLibrary getThingamajigFromIORegistry] in libMyLibrary.a(MyLibrary.o)
>   "_IORegistryEntryFromPath", referenced from:
>   +[MyLibrary getThingamajigFromIORegistry] in libMyLibrary.a(MyLibrary.o)
> ld: symbol(s) not found
> collect2: ld returned 1 exit status
> 
> 
> Adding IOKit.framework to the **application** project resolves the problem 
> (obviously), but how can I set everything up so that references to other 
> Apple frameworks which are internal to my static library and linked into the 
> static library... are honored by the linker when building application 
> projects which link against that static library?

You can't. 

A static archive is no more than a pile of .o files. They have been compiled 
and assembled, but not linked. The linker doesn't touch them, and they don't 
record any dependencies that should be taken into account when they are finally 
linked.

Your static library project would likely build successfully even if you removed 
all linked libraries from it. 


-- 
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


Opening a file read-only?

2011-07-19 Thread Graham Cox
I'm using +[NSData dataWithContentsOfMappedFile:] to access a file. Is it 
possible to ensure this opens read-only? I see there's a version that takes 
options, but none of these options seem to open it read-only.

--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: Opening a file read-only?

2011-07-19 Thread Greg Parker
On Jul 19, 2011, at 6:29 PM, Graham Cox wrote:
> I'm using +[NSData dataWithContentsOfMappedFile:] to access a file. Is it 
> possible to ensure this opens read-only? I see there's a version that takes 
> options, but none of these options seem to open it read-only.

I believe it already opens the file read-only. What makes you suspect that it 
does not?


-- 
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: Opening a file read-only?

2011-07-19 Thread Graham Cox

On 20/07/2011, at 11:43 AM, Greg Parker wrote:

> On Jul 19, 2011, at 6:29 PM, Graham Cox wrote:
>> I'm using +[NSData dataWithContentsOfMappedFile:] to access a file. Is it 
>> possible to ensure this opens read-only? I see there's a version that takes 
>> options, but none of these options seem to open it read-only.
> 
> I believe it already opens the file read-only. What makes you suspect that it 
> does not?



Because we just got rejected on the App Store for opening a file with 
read/write access in a place that's not allowed. I've checked the code that 
we're not writing or creating files to these locations - we're not - so the 
only other possibility is this.

--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: Understanding layer-backed views

2011-07-19 Thread Scott Anguish

On Jul 19, 2011, at 12:27 PM, Michael Crawford wrote:

> Graham; Scott,
> 
> I have a follow-up question on this topic, if you don't mind.  Do either of 
> you have a recommendation on the idea of adding a layer-hosting view as a 
> subview of a layer-backed view?

Yes. You shouldn’t.

When you turn on layer-backing for a view, you turn it on for the entire 
subview hierarchy. So none of those layers are your’s to mess with. Typically 
the way around this is to restructure the view hierarchy some.


> I'm thinking of adding a virtual keyboard to an existing app that is 
> layer-backed.  I would like this VK view to have all the benefits that NSView 
> brings including event handling without all of the heavy-weight of multiple 
> subviews for the keyboard mechanics.
> 
> Can I mix these?
> 
> (Please reply to the thread for everyone's benefit.)
> 
> -Michael
> 
> On Jun 22, 2011, at 3:02 AM, Scott Anguish wrote:
> 
>>> Yep, I'm aware of the setWantsLayer/setLayer order making a difference.
>>> 
>>> In my case I want a layer-hosting view, not a layer-backed view.
>>> 
>>> However, my question isn't really about that, but about what is done when 
>>> you check the box next to the layer in Interface Builder, in the 
>>> 'setWantsLayer' panel. Does this provide layer backing or layer hosting? My 
>>> thoughts were that is provides layer hosting, but I'm not 100% sure. 
>>> Proceeding on the basis that this is the case, it seems to work.
>>> 
>> 
>> layer-backed.
>> 
>> 
>> 
>> 
>>> 
 Again this is not in line with my expectations, which is that the frame of 
 a sublayer is expressed in the coordinate system of its superlayer, not 
 the underlying window.
>>> 
>>> I found the cause of this issue, which was that in my layer delegate, I was 
>>> not saving, setting and restoring the context passed to 
>>> drawLayer:inContext:. I was assuming that the context was set, but having 
>>> found a code snippet in the docs that indicated it wasn't, I added these 
>>> calls and my graphics are drawing in the right place now.
>>> 
>> 
>> great!___
>> 
>> Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)
>> 
>> Please do not post 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/michaelacrawford%40me.com
>> 
>> This email sent to michaelacrawf...@me.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


NSBeep() blocks for some users

2011-07-19 Thread George Nachman
I've had a few users complain that if my app calls NSBeep() many times in
quick succession the program blocks until each of the beeps has played
sequentially. I can't reproduce this: on my system, NSBeep() returns
immediately and a subsequent call to NSBeep() will cause the sound to stop
and restart. Is there any reason why some machines would behave differently?

Thanks!
___

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

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

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

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


Re : Optimizing a loop

2011-07-19 Thread Mathieu Suen
When computing the string distance depending on the chosen algorithm you can 
exit the function earlier if the distance is becoming too high. 

An other possible way is to do some fuzzy string search:
http://en.wikipedia.org/wiki/Fuzzy_string_searching

HTH

--
mathk


- Message d'origine 
> Thanks. The distance is computed because the entry string is dynamic and
> it's  providing a distance between the title of the song and what was entered
> as  text. So I can't pre-compute that data and stuff into a dictionary. Each
> time  the method is called, the *stringValue* will be different.
> 
> On Tue, Jul  19, 2011 at 9:55 AM, Vincent Habchi  wrote:
> 
> >  > Someone told me to look into
> >  -enumerateKeysAndObjectsWithOptions:usingBlock: (using
> >  NSEnumerationConcurrent) Would that be a better way? If so, I haven't  seen
> > this used before - how could I apply it?
> >
> > You can  try to use that, but, basically, it is the same problem: you
> > enumerate  all entries in your dictionary and compute your string distance
> > for  each, which is cumbersome. The algorithm I propose you is way faster,
> >  because you don't have to recompute this distance each time you search.  
>But,
> > once again, the crude way to compute a hash code might not suit  your needs.
> >
> >  Vincent
> ___
> 
> Cocoa-dev  mailing list (Cocoa-dev@lists.apple.com)
> 
> Please  do not post 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/mathieusuen%40yahoo.fr
> 
> This  email sent to mathieus...@yahoo.fr
>
___

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

Please do not post 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


Double-click a main window's title bar to minimize

2011-07-19 Thread Satoshi Nakagawa
Hi,

Is there a way to read "Double-click a main window's title bar to
minimize" setting in Appearance tab in the system preferences?

I want to read the setting in my code to make a custom window work
with the setting.

Regards,
Satoshi
___

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

Please do not post 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


Customize NSScroller in the NSScrollView

2011-07-19 Thread Dawid Naglik

Hello
Could anyone describe me a way to customize the NSScroller look inside 
NSScrollView?
I know that NSScrollView and NSScroller have to be subclassed but I'm stuck 
with that.
Could anyone tell me how to exchange slider bitmaps and implement the new 
slider into NSScrollView?

Thanks in advance for any help, any hints will be greatly appreciated

___

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

Please do not post 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


NSLayoutManager / Justification incorrect when using drawGlyphsForGlyphRange

2011-07-19 Thread vade

I am drawing an NSAttributedString into a bitmap image and uploading to OpenGL 
as a texture. The strings origin is animated to mimic a scroll view, so speed 
is of the essence. Considering my need for animation I have migrated to 
NSLayoutManager / NSTextContainer and NSTextStorage, as opposed simply drawing 
with NSAttributedString drawWithRect: options, which has been a *huge* 
performance gain, but now I have some layout inconsistencies.

I have noticed that I have lost paragraph justification in the process of my 
migration/optimization with NSLayoutManager. I am drawing using 
drawGlyphsForGlyphRange: atPoint. Is there another mechanism that I need to 
trigger/calculate to ensure justification is correct? I had assumed this was 
part of the layout process that drawGlyphsForGlyphRange states it handles, 
which is apparently incorrect.

My drawing code is as follows, with only the relevant bitmap and string drawing 
code left in:


[NSGraphicsContext saveGraphicsState];

// Must supply flipped context for NSLayoutManagers drawing.
NSGraphicsContext* flipped = [NSGraphicsContext 
graphicsContextWithBitmapImageRep:bitmapImage];
flipped = [NSGraphicsContext 
graphicsContextWithGraphicsPort:[flipped graphicsPort] flipped:YES];

[NSGraphicsContext setCurrentContext:flipped]; 

NSAffineTransform *transform = [NSAffineTransform transform];
[transform translateXBy:0 yBy:h];
[transform scaleXBy:1.0 yBy:-1.0];
[transform concat];

// This is slower. Layout Manager is the way to go.
// This nets us 80% CPU for our test text - however 
justification is correct.
//[self.drawString drawWithRect:rect 
options:NSStringDrawingUsesLineFragmentOrigin];

// This might be optimizable more? This gets us ~ 40% CPU for 
our test text
//NSRange glyphRange = [self.layoutManager 
glyphRangeForTextContainer:self.textContainer];

// Only give us the glyphs we need for our rect. ~15 - 30% CPU 
for our test text 
NSRange glyphRange = [self.layoutManager 
glyphRangeForBoundingRect:rect inTextContainer:self.textContainer];

// Possibly even better?
//NSRange glyphRange = [self.layoutManager 
glyphRangeForBoundingRectWithoutAdditionalLayout:rect 
inTextContainer:self.textContainer];

[self.layoutManager drawBackgroundForGlyphRange:glyphRange 
atPoint:drawPoint];
[self.layoutManager drawGlyphsForGlyphRange: glyphRange 
atPoint:drawPoint];

[NSGraphicsContext restoreGraphicsState];


Thank you for any information.

___

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

Please do not post 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


NSLayoutManager / Justification incorrect when using drawGlyphsForGlyphRange

2011-07-19 Thread vade

I am drawing an NSAttributedString into a bitmap image and uploading to OpenGL 
as a texture. The strings origin is animated to mimic a scroll view, so speed 
is of the essence. Considering my need for animation I have migrated to 
NSLayoutManager / NSTextContainer and NSTextStorage, as opposed simply drawing 
with NSAttributedString drawWithRect: options, which has been a *huge* 
performance gain, but now I have some layout inconsistencies.

I have noticed that I have lost paragraph justification in the process of my 
migration/optimization with NSLayoutManager. I am drawing using 
drawGlyphsForGlyphRange: atPoint. Is there another mechanism that I need to 
trigger/calculate to ensure justification is correct? I had assumed this was 
part of the layout process that drawGlyphsForGlyphRange states it handles, 
which is apparently incorrect.

My drawing code is as follows, with only the relevant bitmap and string drawing 
code left in:


[NSGraphicsContext saveGraphicsState];

// Must supply flipped context for NSLayoutManagers drawing.
NSGraphicsContext* flipped = [NSGraphicsContext 
graphicsContextWithBitmapImageRep:bitmapImage];
flipped = [NSGraphicsContext 
graphicsContextWithGraphicsPort:[flipped graphicsPort] flipped:YES];

[NSGraphicsContext setCurrentContext:flipped]; 

NSAffineTransform *transform = [NSAffineTransform transform];
[transform translateXBy:0 yBy:h];
[transform scaleXBy:1.0 yBy:-1.0];
[transform concat];

// This is slower. Layout Manager is the way to go.
// This nets us 80% CPU for our test text - however 
justification is correct.
//[self.drawString drawWithRect:rect 
options:NSStringDrawingUsesLineFragmentOrigin];

// This might be optimizable more? This gets us ~ 40% CPU for 
our test text
//NSRange glyphRange = [self.layoutManager 
glyphRangeForTextContainer:self.textContainer];

// Only give us the glyphs we need for our rect. ~15 - 30% CPU 
for our test text 
NSRange glyphRange = [self.layoutManager 
glyphRangeForBoundingRect:rect inTextContainer:self.textContainer];

// Possibly even better?
//NSRange glyphRange = [self.layoutManager 
glyphRangeForBoundingRectWithoutAdditionalLayout:rect 
inTextContainer:self.textContainer];

[self.layoutManager drawBackgroundForGlyphRange:glyphRange 
atPoint:drawPoint];
[self.layoutManager drawGlyphsForGlyphRange: glyphRange 
atPoint:drawPoint];

[NSGraphicsContext restoreGraphicsState];


Thank you for any information.

___

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

Please do not post 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: Understanding layer-backed views

2011-07-19 Thread Michael Crawford
Well, I suppose I could make sure the window's contentView is not layer backed 
and then put all of the content that used to be in that view into a new 
layer-backed view and then add the new layer-backed view as a subview of the 
contentView. 

Next, I create my layer-hosting view and add it to the contentView as a 
subview, making it a peer of the layer-backed view. 

Is that what you mean by restructuring the view hierarchy?

-Michael

On Jul 19, 2011, at 23:44, Scott Anguish  wrote:

> 
> On Jul 19, 2011, at 12:27 PM, Michael Crawford wrote:
> 
>> Graham; Scott,
>> 
>> I have a follow-up question on this topic, if you don't mind.  Do either of 
>> you have a recommendation on the idea of adding a layer-hosting view as a 
>> subview of a layer-backed view?
> 
> Yes. You shouldn’t.
> 
> When you turn on layer-backing for a view, you turn it on for the entire 
> subview hierarchy. So none of those layers are your’s to mess with. Typically 
> the way around this is to restructure the view hierarchy some.
> 
> 
>> I'm thinking of adding a virtual keyboard to an existing app that is 
>> layer-backed.  I would like this VK view to have all the benefits that 
>> NSView brings including event handling without all of the heavy-weight of 
>> multiple subviews for the keyboard mechanics.
>> 
>> Can I mix these?
>> 
>> (Please reply to the thread for everyone's benefit.)
>> 
>> -Michael
>> 
>> On Jun 22, 2011, at 3:02 AM, Scott Anguish wrote:
>> 
 Yep, I'm aware of the setWantsLayer/setLayer order making a difference.
 
 In my case I want a layer-hosting view, not a layer-backed view.
 
 However, my question isn't really about that, but about what is done when 
 you check the box next to the layer in Interface Builder, in the 
 'setWantsLayer' panel. Does this provide layer backing or layer hosting? 
 My thoughts were that is provides layer hosting, but I'm not 100% sure. 
 Proceeding on the basis that this is the case, it seems to work.
 
>>> 
>>> layer-backed.
>>> 
>>> 
>>> 
>>> 
 
> Again this is not in line with my expectations, which is that the frame 
> of a sublayer is expressed in the coordinate system of its superlayer, 
> not the underlying window.
 
 I found the cause of this issue, which was that in my layer delegate, I 
 was not saving, setting and restoring the context passed to 
 drawLayer:inContext:. I was assuming that the context was set, but having 
 found a code snippet in the docs that indicated it wasn't, I added these 
 calls and my graphics are drawing in the right place now.
 
>>> 
>>> great!___
>>> 
>>> Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)
>>> 
>>> Please do not post 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/michaelacrawford%40me.com
>>> 
>>> This email sent to michaelacrawf...@me.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: Understanding layer-backed views

2011-07-19 Thread Scott Anguish
Exactly. That’s an excellent example and should work fine.

Great solution.


On Jul 19, 2011, at 11:59 PM, Michael Crawford wrote:

> Well, I suppose I could make sure the window's contentView is not layer 
> backed and then put all of the content that used to be in that view into a 
> new layer-backed view and then add the new layer-backed view as a subview of 
> the contentView. 
> 
> Next, I create my layer-hosting view and add it to the contentView as a 
> subview, making it a peer of the layer-backed view. 
> 
> Is that what you mean by restructuring the view hierarchy?
> 
> -Michael
> 
> On Jul 19, 2011, at 23:44, Scott Anguish  wrote:
> 
>> 
>> On Jul 19, 2011, at 12:27 PM, Michael Crawford wrote:
>> 
>>> Graham; Scott,
>>> 
>>> I have a follow-up question on this topic, if you don't mind.  Do either of 
>>> you have a recommendation on the idea of adding a layer-hosting view as a 
>>> subview of a layer-backed view?
>> 
>> Yes. You shouldn’t.
>> 
>> When you turn on layer-backing for a view, you turn it on for the entire 
>> subview hierarchy. So none of those layers are your’s to mess with. 
>> Typically the way around this is to restructure the view hierarchy some.
>> 
>> 
>>> I'm thinking of adding a virtual keyboard to an existing app that is 
>>> layer-backed.  I would like this VK view to have all the benefits that 
>>> NSView brings including event handling without all of the heavy-weight of 
>>> multiple subviews for the keyboard mechanics.
>>> 
>>> Can I mix these?
>>> 
>>> (Please reply to the thread for everyone's benefit.)
>>> 
>>> -Michael
>>> 
>>> On Jun 22, 2011, at 3:02 AM, Scott Anguish wrote:
>>> 
> Yep, I'm aware of the setWantsLayer/setLayer order making a difference.
> 
> In my case I want a layer-hosting view, not a layer-backed view.
> 
> However, my question isn't really about that, but about what is done when 
> you check the box next to the layer in Interface Builder, in the 
> 'setWantsLayer' panel. Does this provide layer backing or layer hosting? 
> My thoughts were that is provides layer hosting, but I'm not 100% sure. 
> Proceeding on the basis that this is the case, it seems to work.
> 
 
 layer-backed.
 
 
 
 
> 
>> Again this is not in line with my expectations, which is that the frame 
>> of a sublayer is expressed in the coordinate system of its superlayer, 
>> not the underlying window.
> 
> I found the cause of this issue, which was that in my layer delegate, I 
> was not saving, setting and restoring the context passed to 
> drawLayer:inContext:. I was assuming that the context was set, but having 
> found a code snippet in the docs that indicated it wasn't, I added these 
> calls and my graphics are drawing in the right place now.
> 
 
 great!___
 
 Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)
 
 Please do not post 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/michaelacrawford%40me.com
 
 This email sent to michaelacrawf...@me.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


Modal panel and -initialFirstResponder

2011-07-19 Thread Vincent
Hi again,
I’m puzzled by what I think is a very basic Cocoa feature that still escapes my 
knowledge (and I found nothing really meaningful about it).

More specifically, I have a NSPanel, with some NSTextField inside, and would 
like the editing to begin immediately in the first text field when the panel 
appears. I thus set the initialFirstResponder outlet to the field I’d like the 
edition to start in. But when the panel shows (modally), all the fields are 
inactive: I have to explicitly select one of them by clicking.

I’ve tried to call -setFirstResponder: with my NSTextField as parameter (or 
even -[myTextField performClick:]) inside the -didBecomeKey delegate methods, 
to no avail.

Has someone an idea on how to make the cursor initially appear without having 
to click on a text field?

Thanks!
Vincent___

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

Please do not post 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