Re: Thread safety, some basic questions about accessing mutable objects across threads

2013-08-06 Thread David Duncan
On Aug 6, 2013, at 8:39 AM, Nick Rogers  wrote:

> 1. Created a mutable array in main thread, can I read its values in a 
> secondary thread safely, while no other thread is modifying this mutable 
> array?
> 
> 2. I need to add objects to this mutable array from a secondary thread, and 
> no other thread is modifying it. Can I simply add an object like, [array 
> addObject:obj]; or if this is wrong how to achieve the same? The object to 
> add is mostly NSString or NSNumber or a mutable dictionary of NSString and 
> NSNumber.


Honestly I would recommend a thread-confinement strategy. If you have some 
other thread that wants to add an object to the array, it should message the 
thread that owns that array (I'm guessing the main thread here) and tell it to 
add the object.

TN2109 discusses this strategy along with sample code: 

--
David Duncan


___

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

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

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

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

Re: Reloading table view header or footer

2013-08-06 Thread Rick Mann

On Aug 6, 2013, at 14:24 , Alex Zavatone  wrote:

> reloadSections:withRowAnimation
> 
> reloadRowsAtIndexPaths, perhaps?  Or reloadSectionIndexTitles?
> 
> Set an observer to the data record that is being used to populate that cell, 
> then create a little method in your TV class that is triggered when that data 
> value changes.  Then within that method, issue the appropriate reload:
> 
> [self.tableView reloadSections: mySectionIndexPath withRowAnimation: 
> UITableViewRowAnimationNone  ]
> 
> or
> 
> [self.tableView reloadSectionIndexTitles];
> 
> or
> 
> NSArray *mySectionIndex = [NSArray 
> arrayWithObject[thatIndexPathForThisSection]]
> [ self.tableView reloadRowsAtIndexPath: mySectionIndex withRowAnimation: 
> UITableViewRowAnimationNone];
> 
> Not sure if reloading a cell that is a section header will really do a 
> refresh on it, but it looks like reloadSectionIndexTitles sure will.

Unfortunately, of those that cause a section to reload, it makes all the cells 
reload, too, which is something I want to avoid.


-- 
Rick




___

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: Reloading table view header or footer

2013-08-06 Thread Alex Zavatone
Have you tried any of these?

reloadSections:withRowAnimation

reloadRowsAtIndexPaths, perhaps?  Or reloadSectionIndexTitles?

Set an observer to the data record that is being used to populate that cell, 
then create a little method in your TV class that is triggered when that data 
value changes.  Then within that method, issue the appropriate reload:

[self.tableView reloadSections: mySectionIndexPath withRowAnimation: 
UITableViewRowAnimationNone]

or

[self.tableView reloadSectionIndexTitles];

or

NSArray *mySectionIndex = [NSArray arrayWithObject[thatIndexPathForThisSection]]
[ self.tableView reloadRowsAtIndexPath: mySectionIndex withRowAnimation: 
UITableViewRowAnimationNone];

Not sure if reloading a cell that is a section header will really do a refresh 
on it, but it looks like reloadSectionIndexTitles sure will.


GL.

On Aug 6, 2013, at 4:49 PM, Rick Mann wrote:

> I've been struggling with updating the content of a table view footer. I 
> ended up creating a custom view that I hang on to, returning that from the 
> delegate method, and then changing its content.
> 
> But I'm looking at the Personal Hotspot UI in Settings, and I see that the 
> section footer changes nicely when you enable and disable the hot spot. It 
> resizes with animation, and the rest of the table doesn't change.
> 
> How is this properly done?
> 
> -- 
> Rick
> 
> 
> 
> 
> ___
> 
> 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/zav%40mac.com
> 
> This email sent to z...@mac.com


___

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

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

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

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

Reloading table view header or footer

2013-08-06 Thread Rick Mann
I've been struggling with updating the content of a table view footer. I ended 
up creating a custom view that I hang on to, returning that from the delegate 
method, and then changing its content.

But I'm looking at the Personal Hotspot UI in Settings, and I see that the 
section footer changes nicely when you enable and disable the hot spot. It 
resizes with animation, and the rest of the table doesn't change.

How is this properly done?

-- 
Rick




___

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: Thread safety, some basic questions about accessing mutable objects across threads

2013-08-06 Thread Jens Alfke

On Aug 6, 2013, at 8:39 AM, Nick Rogers  wrote:

> 1. Created a mutable array in main thread, can I read its values in a 
> secondary thread safely, while no other thread is modifying this mutable 
> array?

Yes. Most non-thread-safe objects don’t care what threads you call them on, so 
long as they’re only called on one thread at a time. So you can use locks or 
@synchronized blocks to coordinate access.

(The exceptions are higher-level things that use runloops or dispatch queues, 
such as NSURLConnection, NSStream, etc. Those usually need to be called only 
from the same thread/queue they’re scheduled on, because they’re also getting 
callbacks on that same thread/queue.)

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

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

Re: Any way to delay drawing after scrolling?

2013-08-06 Thread Steve Mills
On Aug 6, 2013, at 11:09:51, Kyle Sluder 
 wrote:

> If scrolling your view always requires a redraw, I’d just turn it on in the 
> nib and leave it on.

No, it doesn't always need to do this. This is only needed when scaling our 
view, when the new scroll loc is calculated and set. Regular swipe or scrollbar 
scrolling will still use the optimized copiesOnScroll behavior.

> Also, since we now know how copiesOnScroll affects things: are you sure you 
> were seeing double drawing?

Yes. I know because I overrode display:, set a breakpoint in it, and it was 
called by the call to scrollPoint.

--
Steve Mills
office: 952-818-3871
home: 952-401-6255
cell: 612-803-6157




___

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: Thread safety, some basic questions about accessing mutable objects across threads

2013-08-06 Thread Kyle Sluder
On Aug 6, 2013, at 8:39 AM, Nick Rogers  wrote:

> Hi,
> 
> Please look at the following situations:
> 
> 1. Created a mutable array in main thread, can I read its values in a 
> secondary thread safely, while no other thread is modifying this mutable 
> array?

Yes, but the second half of that sentence is the tricky part. One typically 
uses a lock to ensure that no other threads are modifying the array.

> 
> 2. I need to add objects to this mutable array from a secondary thread, and 
> no other thread is modifying it. Can I simply add an object like, [array 
> addObject:obj]; or if this is wrong how to achieve the same? The object to 
> add is mostly NSString or NSNumber or a mutable dictionary of NSString and 
> NSNumber.

Yes, NSArray can be used from any thread, as long as if one thread is modifying 
the array it is the only thread accessing the array. Again, you need to use a 
synchronization primitive to ensure this is the case.

--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: Any way to delay drawing after scrolling?

2013-08-06 Thread Kyle Sluder
On Aug 6, 2013, at 9:00 AM, Steve Mills  wrote:

> On Aug 5, 2013, at 12:34:11, Kyle Sluder  wrote:
> 
>> Try turning off copies-on-scroll on your scroll view.
> 
> That seems to do the trick. Thanks. I'm grabbing its state, turning it off, 
> scrollPoint, then setting it back.

If scrolling your view always requires a redraw, I’d just turn it on in the nib 
and leave it on.

Also, since we now know how copiesOnScroll affects things: are you sure you 
were seeing double drawing? The way it's supposed to work is that the scrolling 
methods call -scrollRect:by: to blit your contents into the new position, then 
you get -setNeedsDisplay: in the newly-exposed rects.

However you are noticing that you have scrolled, you are presumably calling 
[self setNeedsDisplay], so you should therefore only actually draw once on the 
next turn of the display loop. Turning off copiesOnScroll will avoid the 
unnecessary blit, but if you were actually seeing two -drawRect: calls for 
every scroll then something else is afoot.

--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: Thread safety, some basic questions about accessing mutable objects across threads

2013-08-06 Thread Abdul Sowayan
Nick,

In your secondary you can use dispatch_async or dispatch_sync to schedule a 
block of code to execute on the main thread. Below is a simple example:

dispatch_async(dispatch_get_main_queue(), ^{
  // put your code to modify mutable array here
  });


I hope this helps.

Thanks,
Abdul

On Aug 6, 2013, at 11:39 AM, Nick Rogers 
mailto:roger...@mac.com>> wrote:

Hi,

Please look at the following situations:

1. Created a mutable array in main thread, can I read its values in a secondary 
thread safely, while no other thread is modifying this mutable array?

2. I need to add objects to this mutable array from a secondary thread, and no 
other thread is modifying it. Can I simply add an object like, [array 
addObject:obj]; or if this is wrong how to achieve the same? The object to add 
is mostly NSString or NSNumber or a mutable dictionary of NSString and NSNumber.

Please help.

Best,
Nick


___

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

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

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/asowayan%40vectorworks.net

This email sent to asowa...@vectorworks.net

___

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

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

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

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

Re: Any way to delay drawing after scrolling?

2013-08-06 Thread Steve Mills
On Aug 5, 2013, at 12:34:11, Kyle Sluder  wrote:

> Try turning off copies-on-scroll on your scroll view.

That seems to do the trick. Thanks. I'm grabbing its state, turning it off, 
scrollPoint, then setting it back.

--
Steve Mills
office: 952-818-3871
home: 952-401-6255
cell: 612-803-6157



___

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

Thread safety, some basic questions about accessing mutable objects across threads

2013-08-06 Thread Nick Rogers
Hi,

Please look at the following situations:

1. Created a mutable array in main thread, can I read its values in a secondary 
thread safely, while no other thread is modifying this mutable array?

2. I need to add objects to this mutable array from a secondary thread, and no 
other thread is modifying it. Can I simply add an object like, [array 
addObject:obj]; or if this is wrong how to achieve the same? The object to add 
is mostly NSString or NSNumber or a mutable dictionary of NSString and NSNumber.

Please help.

Best,
Nick


___

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

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

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

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

Re: Computing the height for a UITableViewHeaderFooterView

2013-08-06 Thread Kyle Sluder
On Tue, Aug 6, 2013, at 02:21 AM, Diederik Meijer | Ten Horses wrote:
> The way is handled something similar is by first calculating the label
> size for the dynamic string (which you probably need anyway), then using
> the returned value in the heightForHeaderInSection (or recalculating it
> with a method call), followed by calling reloadData on the tableView.

You're calling -reloadData just to load a header/footer view? That's
overkill.


> -(float)calculateLabelSizeHeightForText:(NSString *)text {
> CGSize constraintSize = ([[UIDevice currentDevice]
> userInterfaceIdiom] == UIUserInterfaceIdiomPad) ? CGSizeMake(748.0f,
> MAXFLOAT) : CGSizeMake(300.0f, MAXFLOAT);

Why are you hardcoding sizes here? This will only work if the table view
you're inserting into has a contentSize.width of your magic values.

Since you know what table view you're being asked for the cell heights
for, why not just use the table view's contentSize.width?

> //You will need to define kDefaultCellFont
> CGSize labelSize = [text sizeWithFont:[UIFont systemFontOfSize:14]
> constrainedToSize:constraintSize
> lineBreakMode:UILineBreakModeWordWrap];
> return labelSize.height+10;

> }

Rather than fudge factors, why not use auto layout? Then you don't have
to duplicate layout information between the nib and your code.

Jon Wight from Twitter has put together an example of how to use auto
layout to compute cell heights: https://github.com/schwa/Smart-Tables

--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: Checking if NSURL exists

2013-08-06 Thread Uli Kusterer
On Aug 5, 2013, at 8:41 PM, Jerry Krinock  wrote:
> As Jens explained, your does not have a clean answer.
> 
> Doing a HEAD request is "optimal" (huge reduction in network traffic) if you 
> can accept  NO answers from a tiny percentage of sites which will won't 
> return data to a HEAD request, even though they will return data to a GET.

Apart from servers not supporting HEAD requests, also keep in mind that some 
servers don't correctly do 404 pages and instead redirect any unknown page to 
the home page (or worse, just display the home page). So your code might not 
even be able to check whether a URL exists, but only if there is a server at 
that URL. For most uses that isn't a problem, but for some it is. The web is a 
crazy place.

Cheers,
-- Uli Kusterer
"The Witnesses of TeachText are everywhere..."
http://www.zathras.de


___

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: Computing the height for a UITableViewHeaderFooterView

2013-08-06 Thread Diederik Meijer | Ten Horses
The way is handled something similar is by first calculating the label size for 
the dynamic string (which you probably need anyway), then using the returned 
value in the heightForHeaderInSection (or recalculating it with a method call), 
followed by calling reloadData on the tableView. The code below, by the way, is 
portrait only, which is fine in my case, but unlikely to work in yours, so 
you'd have to change that.


somewhere in your data model code:
float labelSizeHeight = [self calculateLabelSizeHeightForText:@"blablabla"];



-(float)calculateLabelSizeHeightForText:(NSString *)text {
CGSize constraintSize = ([[UIDevice currentDevice] userInterfaceIdiom] == 
UIUserInterfaceIdiomPad) ? CGSizeMake(748.0f, MAXFLOAT) : CGSizeMake(300.0f, 
MAXFLOAT);
//You will need to define kDefaultCellFont
CGSize labelSize = [text sizeWithFont:[UIFont systemFontOfSize:14]
constrainedToSize:constraintSize
lineBreakMode:UILineBreakModeWordWrap];
return labelSize.height+10;
}


- (CGFloat)tableView:(UITableView *)tableView 
heightForHeaderInSection:(NSInteger)section {
return labelSizeHeight;
}




Op Aug 6, 2013, om 9:23 AM heeft Rick Mann  het volgende 
geschreven:

> Unfortunately, that won't compute the height of the 
> UITableViewHeaderFooterView, which has two different labels with different 
> text characteristics, and who know what positioning within.
> 
> On Aug 5, 2013, at 18:57 , synelang  wrote:
> 
>> Try this : (never tested)
>> 
>>  • void)tableView:(UITableView *)tableView willDisplayHeaderView:(UIView 
>> *)view forSection:(NSInteger)section_
>> {
>>  CGSize size = [dataString sizeWithFont:font constrainedToSize:size 
>> lineBreakMode:UILineBreakModeWordWrap];  
>>  CGFrame frame = view.frame;
>>  frame.size.height = size.height;
>>  •   [view setFrame:frame]; 
>>  • }
>> 
>> 
>> 
>> Original Message 
>> Sender: Rick Mann
>> Recipient: Cocoa Dev List
>> Date: 星期二, 8月 6, 2013 09:25
>> Subject: Computing the height for a UITableViewHeaderFooterView
>> 
>> Is there any way around manually providing the height for a table header 
>> view? If I simply provide a title string for the header, UITableView is able 
>> to compute the height itself. But if I use a UITableViewHeaderFooterView and 
>> set the textLabel and detailTextLabel, I also have to set the height (as far 
>> as I can tell).
>> 
>> But the text I'm rendering is dynamic, and could change the number of lines 
>> used. Not sure how best to handle this.
>> 
>> -- 
>> Rick
>> 
>> 
>> 
>> 
>> ___
>> 
>> 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/synelang%40gmail.com
>> 
>> 
>> This email sent to 
>> synel...@gmail.com
> 
> 
> -- 
> Rick
> 
> 
> 
> 
> ___
> 
> 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/diederik%40tenhorses.com
> 
> This email sent to diede...@tenhorses.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: Computing the height for a UITableViewHeaderFooterView

2013-08-06 Thread Rick Mann
Unfortunately, that won't compute the height of the 
UITableViewHeaderFooterView, which has two different labels with different text 
characteristics, and who know what positioning within.

On Aug 5, 2013, at 18:57 , synelang  wrote:

> Try this : (never tested)
> 
>   • void)tableView:(UITableView *)tableView willDisplayHeaderView:(UIView 
> *)view forSection:(NSInteger)section_
> {
>   CGSize size = [dataString sizeWithFont:font constrainedToSize:size 
> lineBreakMode:UILineBreakModeWordWrap];  
>   CGFrame frame = view.frame;
>   frame.size.height = size.height;
>   •   [view setFrame:frame]; 
>   • }
> 
> 
> 
>  Original Message 
> Sender: Rick Mann
> Recipient: Cocoa Dev List
> Date: 星期二, 8月 6, 2013 09:25
> Subject: Computing the height for a UITableViewHeaderFooterView
> 
> Is there any way around manually providing the height for a table header 
> view? If I simply provide a title string for the header, UITableView is able 
> to compute the height itself. But if I use a UITableViewHeaderFooterView and 
> set the textLabel and detailTextLabel, I also have to set the height (as far 
> as I can tell).
> 
> But the text I'm rendering is dynamic, and could change the number of lines 
> used. Not sure how best to handle this.
> 
> -- 
> Rick
> 
> 
> 
> 
> ___
> 
> 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/synelang%40gmail.com
> 
> 
> This email sent to 
> synel...@gmail.com


-- 
Rick




___

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