Re: question about last used date

2016-03-14 Thread Jens Alfke

> On Mar 14, 2016, at 6:11 PM, Rick C.  wrote:
> 
> 2.  NSURLContentAccessDateKey returns the current date like mentioned here - 
> http://stackoverflow.com/questions/13914600/get-the-real-last-opened-date 
> 
> 3.  The same problem with st_atimespec it returns the current date

The thread you linked to doesn’t say the _current_ date, it says "very strange 
dates, usually near 3:00-3:30 AM, today or yesterday”. That’s probably the last 
time the file was scanned by some system daemon like the Spotlight indexer or 
Time Machine, as I said in my previous reply.

> So from what I see there is no real alternative to kMDItemLastUsedDate if 
> that value is missing.  Additional thoughts?


It sounds like what you want is a high level “last time this file was opened in 
a GUI application by a user command” property, which isn’t something the 
filesystem knows anything about. Higher-level frameworks seem to update 
kMDItemLastUsedDate to implement this. If that data is lost, I don’t think you 
have an alternative.

—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: question about last used date

2016-03-14 Thread Rick C.
So I’ve done some work:

1.  Might be possible no kMDItemLastUsedDate on a new Mac after using 
MigrationAssistant or of course if no Spotlight being used
2.  NSURLContentAccessDateKey returns the current date like mentioned here - 
http://stackoverflow.com/questions/13914600/get-the-real-last-opened-date 

3.  The same problem with st_atimespec it returns the current date
4.  NSURLAttributeModificationDateKey seems to be what Path Finder is using to 
get the Attribute tag

So from what I see there is no real alternative to kMDItemLastUsedDate if that 
value is missing.  Additional thoughts?



> On 15 Mar 2016, at 1:04 AM, Fritz Anderson  wrote:
> 
> 
>> On 14 Mar 2016, at 10:39 AM, Jens Alfke  wrote:
>> 
>> Unix filesystems do keep a last-accessed date for files, but it looks like 
>> NSFileManager doesn’t expose an attribute for it. You can call stat() and 
>> get the st_atimespec field of the result.
> 
> NSURL *Resource* methods can get at NSURLContentAccessDateKey:
> 
>> The time at which the resource was most recently accessed, returned as an 
>> NSDate object if the volume supports accessdates, or nil if access dates are 
>> unsupported (read-only).
> 
> The resource stuff is painful, especially in Swift, but indispensable.
> 
>   — 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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

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

Making Managed Object Context available to array controller in Storyboard scene

2016-03-14 Thread Eric Gorr
I have a core data, document based, storyboard OS X application.

There is a test project here:

https://github.com/ericgorr/sb_ac_doc

which is just the default project Xcode creates with a few modifications.

I have a single view controller and the view contains a table view which will 
eventually display the data in the Core Data document. I will also using an 
array controller to manage the rows for the table view.

The three scenes are:

 - Application Scene
 - Window Controller Scene
 - Main View Controller Scene

The *Main View Controller Scene* contains the *TestItem Array Controller*.

The *TestItem View Controller* contains the code:

class ViewController: NSViewController
{
var context: NSManagedObjectContext?

//
// ...
//
}

The *TestItem Array Controller* contains the Parameters Binding:

Managed Object Context
Bind to: Main View Controller
Model Key Path: context

In Document.swift:

override func makeWindowControllers()
{
let moc = self.managedObjectContext!

// Returns the Storyboard that contains your Document window.
let storyboard  = NSStoryboard(name: "Main", bundle: nil)
let windowController= 
storyboard.instantiateControllerWithIdentifier( "Document Window Controller" ) 
as! NSWindowController
let contentController   = windowController.contentViewController as! 
ViewController

NSLog( "%@", self.managedObjectContext! )

contentController.context = self.managedObjectContext!

NSLog( "%@", contentController.context! )

self.addWindowController( windowController )
}

This is my attempt to pass the MOC to the view controller before the array 
controller attempts to access it.

The NSLog's both print out valid values.

However, I am getting the following crash:

2016-03-13 20:13:02.667 sb_ac_doc[73021:16415257] Cannot perform operation 
without a managed object context
2016-03-13 20:13:02.669 sb_ac_doc[73021:16415257] (
0   CoreFoundation  0x7fff956f9ae2 
__exceptionPreprocess + 178
1   libobjc.A.dylib 0x7fff9a09073c 
objc_exception_throw + 48
2   CoreFoundation  0x7fff956f998d 
+[NSException raise:format:] + 205
3   AppKit  0x7fff8c8224e7 
-[_NSManagedProxy _managedObjectContext] + 66
4   AppKit  0x7fff8c822507 
-[_NSManagedProxy _persistentStoreCoordinator] + 22
5   AppKit  0x7fff8c82257a 
-[_NSManagedProxy _entity] + 46
6   AppKit  0x7fff8c822802 
-[_NSManagedProxy fetchRequestWithSortDescriptors:limit:] + 89
7   AppKit  0x7fff8c821fec 
-[NSObjectController(NSManagedController) 
_executeFetch:didCommitSuccessfully:actionSender:] + 75
8   AppKit  0x7fff8c5c18c2 
-[NSController _controllerEditor:didCommit:contextInfo:] + 185
9   CoreFoundation  0x7fff955c417c 
__invoking___ + 140
10  CoreFoundation  0x7fff955c3fce 
-[NSInvocation invoke] + 286
11  CoreFoundation  0x7fff95663be6 
-[NSInvocation invokeWithTarget:] + 54
12  Foundation  0x7fff87cce345 
__NSFireDelayedPerform + 377
13  CoreFoundation  0x7fff9563fbc4 
__CFRUNLOOP_IS_CALLING_OUT_TO_A_TIMER_CALLBACK_FUNCTION__ + 20
14  CoreFoundation  0x7fff9563f853 
__CFRunLoopDoTimer + 1075
15  CoreFoundation  0x7fff956bde6a 
__CFRunLoopDoTimers + 298
16  CoreFoundation  0x7fff955facd1 
__CFRunLoopRun + 1841
17  CoreFoundation  0x7fff955fa338 
CFRunLoopRunSpecific + 296
18  HIToolbox   0x7fff8add1935 
RunCurrentEventLoopInMode + 235
19  HIToolbox   0x7fff8add1677 
ReceiveNextEventCommon + 184
20  HIToolbox   0x7fff8add15af 
_BlockUntilNextEventMatchingListInModeWithFilter + 71
21  AppKit  0x7fff8c25e0ee 
_DPSNextEvent + 1067
22  AppKit  0x7fff8c62a943 
-[NSApplication _nextEventMatchingEventMask:untilDate:inMode:dequeue:] + 454
23  AppKit  0x7fff8c253fc8 
-[NSApplication run] + 682
24  AppKit  0x7fff8c1d6520 
NSApplicationMain + 1176
25  sb_ac_doc   0x00012427 main + 87
26  libdyld.dylib   0x7fff987455ad start + 1
)

What is the correct pattern I should use so the array 

Re: NSBitmapImageRep setSize: doesn't always do the right thing

2016-03-14 Thread Steve Mills

On Mar 14, 2016, at 03:29 PM, Quincey Morris 
 wrote:

It’s not clear what your intention is, in trying to set the size of the image 
rep. It’s a NSBitmageImageRep, right? The pixels are the pixels are the pixels, 
so I don’t think you should be doing anything to the image *rep* size.
 
Normally, if you have a bitmap image (i.e. NSBitmageImageRep) that’s actually 
88px x 107px, but you want to appear as 13pt x 16pt — note points not pixels — 
you would set the NSImage size to CGSize (13, 16)** and let the drawing system 
determine how to scale the pixel data to the perceived image size.

No, this is a proper way to set the resolution. It shouldn't affect the 
pixelWidth/pixelHeight. Documentation is sketchy, but I've seen it somewhere. 
Setting the image size after drawing into it was causing the image rep to lose 
pixels.
 
The other problem here is that you’re drawing the “hi-res” data at about 7x, 
which means that you’re guaranteeing some loss of detail when the image is 
scaled down to its final physical size (2x or 3x, or even 1x on a very old 
Mac). Why not draw it at the correct pixel resolution for the current display, 
so that there’s no actual pixel scaling (interpolation) needed when drawing? 
That should produce better quality than what you’re doing. (Unless you’re 
drawing something to be cached for multiple pixel resolutions, but even then 
there’s no hardware resolution higher than 3x).

This isn't being drawn to the display. The image is being placed into an 
InDesign document for export or print, so we need every bit of that resolution.

Sent from iCloud's ridiculous UI, so, sorry about the formatting

 
___

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: NSBitmapImageRep setSize: doesn't always do the right thing

2016-03-14 Thread Quincey Morris
On Mar 14, 2016, at 12:55 , Steve Mills  wrote:
> 
> The cropped NSImage is created at the scaled-up size, drawn into, and finally 
> the cropped NSImage's first NSImageRep is set to draw at the perceived, 
> high-res size via [cropped.representations.firstObject 
> setSize:perceivedSize]. This all works when the MathML string is long enough, 
> but when it is short, it doesn't. The setSize ends up reducing the pixels, 
> even though the image rep's pixelWidth and pixelHeight still report the 
> correct high-res size.

It’s not clear what your intention is, in trying to set the size of the image 
rep. It’s a NSBitmageImageRep, right? The pixels are the pixels are the pixels, 
so I don’t think you should be doing anything to the image *rep* size.

> An example of one that does NOT work is 88px high and 107px wide at the 
> scaled-up size (13px high x 16px wide at the perceived size).

Normally, if you have a bitmap image (i.e. NSBitmageImageRep) that’s actually 
88px x 107px, but you want to appear as 13pt x 16pt — note points not pixels — 
you would set the NSImage size to CGSize (13, 16)** and let the drawing system 
determine how to scale the pixel data to the perceived image size.

The other problem here is that you’re drawing the “hi-res” data at about 7x, 
which means that you’re guaranteeing some loss of detail when the image is 
scaled down to its final physical size (2x or 3x, or even 1x on a very old 
Mac). Why not draw it at the correct pixel resolution for the current display, 
so that there’s no actual pixel scaling (interpolation) needed when drawing? 
That should produce better quality than what you’re doing. (Unless you’re 
drawing something to be cached for multiple pixel resolutions, but even then 
there’s no hardware resolution higher than 3x).

Note that things are a bit complicated these days, because they pixel 
resolution of a display may be different from the rendering/backing store 
resolution and both may be different from the nominal resolution.


** Except that you’d probably want to preserve the aspect ratio, but 88.0/13 != 
107.0/16.
___

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

NSBitmapImageRep setSize: doesn't always do the right thing

2016-03-14 Thread Steve Mills

I have some code that renders a MathML string into a WebView at a scaled-up 
size, then draws that into an NSImage of the scaled-up size, then draws that 
into a cropped NSImage to get rid of the extra space that the WebView throws in 
for scrollbars or whatever.

The cropped NSImage is created at the scaled-up size, drawn into, and finally 
the cropped NSImage's first NSImageRep is set to draw at the perceived, 
high-res size via [cropped.representations.firstObject setSize:perceivedSize]. 
This all works when the MathML string is long enough, but when it is short, it 
doesn't. The setSize ends up reducing the pixels, even though the image rep's 
pixelWidth and pixelHeight still report the correct high-res size.

Bug? It took me a few days to find the right combination of stuff to get the 
correct portion of the WebView and end up with a high-res image. I'm having to 
do all this with bitmaps because getting an EPS from the WebView via 
dataWithEPSInsideRect gives completely crappy and unusable results, like the 
top bar of the square root symbol isn't even connected to the √ part.

An example of one that works is 89px high and 349px wide at the scaled-up size 
(13px high x 50px wide at perceived size).

An example of one that does NOT work is 88px high and 107px wide at the 
scaled-up size (13px high x 16px wide at the perceived size).
Sent from iCloud's ridiculous UI, so, sorry about the formatting
___

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: question about last used date

2016-03-14 Thread Fritz Anderson

> On 14 Mar 2016, at 10:39 AM, Jens Alfke  wrote:
> 
> Unix filesystems do keep a last-accessed date for files, but it looks like 
> NSFileManager doesn’t expose an attribute for it. You can call stat() and get 
> the st_atimespec field of the result.

NSURL *Resource* methods can get at NSURLContentAccessDateKey:

> The time at which the resource was most recently accessed, returned as an 
> NSDate object if the volume supports accessdates, or nil if access dates are 
> unsupported (read-only).

The resource stuff is painful, especially in Swift, but indispensable.

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

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

Re: Is a portrait-only launch image possible?

2016-03-14 Thread David Duncan
It is, but similarly we now prefer you use a launch storyboard – so it can look 
just like your welcome screen (at least to the point that you can describe that 
in Interface Builder). This should have been created with your project.

> On Mar 14, 2016, at 4:38 AM, Charles Jenkins  wrote:
> 
> Thank you, David. Is it possible then to have two launch images and the 
> system will select the correct one based on orientation? If not, I’ll have to 
> give up on my idea of a smooth transition, because my launch image won’t be 
> able to look anything like the welcome screen that follows.
> 
> -- 
> 
> Charles
> 
> On March 14, 2016 at 01:40:09, David Duncan (david.dun...@apple.com 
> ) wrote:
> 
>> 
>> > On Mar 13, 2016, at 12:32 PM, Charles Jenkins  wrote: 
>> >  
>> > I’m developing my first iOS app. On the General tab of my app’s build 
>> > settings, I have checked only Portrait as the supported orientation. When 
>> > testing on an iPad today, I noticed that if I start the app with the iPad 
>> > held in landscape mode, the launch image appears in landscape and of 
>> > course looks terrible because parts of it are cut off. 
>> >  
>> > The next screen that appears is my welcome/splash screen, which is very 
>> > similar to the launch image; I meant for the transition from launch image 
>> > to welcome screen to be subtle. But the welcome screen appears in portrait 
>> > mode as it should, so the transition is jarring. 
>> >  
>> > It is not possible to have a Portrait-only launch image? If so, where else 
>> > do I need to look for settings controlling the orientation of the launch 
>> > image? 
>> 
>> Modern iPad apps (which support multitasking) do not support control of 
>> interface orientation – your application will have to support all 
>> orientations. You can opt out of this by setting an Info.plist setting that 
>> states that your application must always be presented fullscreen (I don’t 
>> recall the property off hand, but it shouldn’t be too hard to find it if you 
>> really need it) but the recommendation would be to instead support all 
>> orientations so that your application will participate in multitasking. 
>> 
>> -- 
>> David Duncan

--
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: How to set a TextField

2016-03-14 Thread Pascal Bourguignon



> On 14 Mar 2016, at 09:17, Gerriet M. Denkmann  wrote:
> 
> You are absolutely right that a background would be the right thing.
> But this is just a small tool for testing, and it will not take more than a 
> few seconds, so I am trying to avoid this.

For testing you can use NSLog instead.

-- 
__Pascal Bourguignon__

___

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: Is a portrait-only launch image possible?

2016-03-14 Thread Charles Jenkins
Thank you, David. Is it possible then to have two launch images and the system 
will select the correct one based on orientation? If not, I’ll have to give up 
on my idea of a smooth transition, because my launch image won’t be able to 
look anything like the welcome screen that follows.

-- 

Charles

On March 14, 2016 at 01:40:09, David Duncan (david.dun...@apple.com) wrote:


> On Mar 13, 2016, at 12:32 PM, Charles Jenkins  wrote:  
>  
> I’m developing my first iOS app. On the General tab of my app’s build 
> settings, I have checked only Portrait as the supported orientation. When 
> testing on an iPad today, I noticed that if I start the app with the iPad 
> held in landscape mode, the launch image appears in landscape and of course 
> looks terrible because parts of it are cut off.  
>  
> The next screen that appears is my welcome/splash screen, which is very 
> similar to the launch image; I meant for the transition from launch image to 
> welcome screen to be subtle. But the welcome screen appears in portrait mode 
> as it should, so the transition is jarring.  
>  
> It is not possible to have a Portrait-only launch image? If so, where else do 
> I need to look for settings controlling the orientation of the launch image?  

Modern iPad apps (which support multitasking) do not support control of 
interface orientation – your application will have to support all orientations. 
You can opt out of this by setting an Info.plist setting that states that your 
application must always be presented fullscreen (I don’t recall the property 
off hand, but it shouldn’t be too hard to find it if you really need it) but 
the recommendation would be to instead support all orientations so that your 
application will participate in multitasking.  

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

question about protocol

2016-03-14 Thread bigpig
Hi everyone
I get confused in SDWebImage code.The author declare a custom protocol 
“SDWebImageOperation” and have only a method “- (void)cancel”.Then some class 
comply with this protocol and implement the method “cancel”.But this protocol 
does not do anything,why write this way.why not every class which comply with 
this protocol implement a interface named cancel.

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

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

question about last used date

2016-03-14 Thread Rick C.
Hi everyone,

I’m having some troubles getting the last used date of a file, can anyone see 
issues here with my code?

NSDictionary *fileAttributes = [[NSFileManager defaultManager] 
attributesOfItemAtPath:anObject error:NULL];
if (fileAttributes != nil)
{
MDItemRef item = MDItemCreate(NULL, (CFStringRef)anObject);
NSDate *aDate = (NSDate*)CFBridgingRelease(MDItemCopyAttribute(item, 
kMDItemLastUsedDate));
if (!aDate)
{
NSDate *fileCreateDate = [fileAttributes 
objectForKey:NSFileModificationDate];
}
}

My problem is I’m only getting a kMDItemLastUsedDate on about 10% of files I 
check, and even though I always get a value for NSFileModificationDate it still 
doesn’t seem to always be the true last used date.  For example looking at how 
Path Finder does it they have an Attribute tag that seems to more correctly 
give the last date file was used.  Any input here would be appreciated thanks 
in advance...


___

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

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

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

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

Reading XML 1.1

2016-03-14 Thread John Brownie
Is it possible to read an XML 1.1 file using NSXMLDocument? The crucial 
thing for my purposes is that the character set allowed in XML 1.1 is 
larger. XML 1.0 defines characters as:


Char   ::=   #x9 | #xA | #xD | [#x20-#xD7FF] | [#xE000-#xFFFD] | 
[#x1-#x10]


XML 1.1 defines:

#2   Char  ::=   [#x1-#xD7FF] | [#xE000-#xFFFD] | 
[#x1-#x10]/* any Unicode character, excluding the surrogate 
blocks, FFFE, and . */
#2a   RestrictedChar  ::=   [#x1-#x8] | [#xB-#xC] | 
[#xE-#x1F] | [#x7F-#x84] | [#x86-#x9F]


I need to be able to handle the RestrictedChar characters, but 
NSXMLDocument apparently only handles the XML 1.0 character set.


Is there a way to make NSXMLDocument handle the fuller character set? If 
not, is there an alternative that will enable me to parse an XML 1.1 
file with a minimum of effort?


Thanks,
John
--
John Brownie, john_brow...@sil.org or j.brow...@sil.org.pg
Summer Institute of Linguistics, Ukarumpa, Eastern Highlands Province, 
Papua New Guinea

Mussau-Emira language, Mussau Island, New Ireland Province, Papua New Guinea
___

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

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

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

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

Re: How to set a TextField

2016-03-14 Thread Alex Zavatone
Just do the calculation within a dispatch_async within computeSimething.


On Mar 14, 2016, at 4:17 AM, Gerriet M. Denkmann wrote:

> 
>> On 14 Mar 2016, at 14:17, Quincey Morris 
>>  wrote:
>> 
>> On Mar 13, 2016, at 23:50 , Gerriet M. Denkmann  wrote:
>>> 
>>> - (void)computeSomething
>>> {
>>> self.message1 = @“Start computing”;
>>> //  some seconds of computations
>>> self.message1 = @“Result = 42”;
>>> }
>> 
>> Assume, conceptually, that drawing only takes place asynchronously (that is 
>> to say, setting a new value on the string invokes setNeedsDisplay, that’s 
>> all), and it’s obvious why this isn’t going to work.
>> 
>> But the real issue is not that the text field won’t update, it’s that you’re 
>> blocking the main thread with computation. You should move the computation 
>> off the main thread — using dispatch_async to a default queue. At the end of 
>> the computation, go back to the main thread (dispatch_async again, 
>> specifying the main queue this time) and put the result in the text field.
>> 
>> This is, of course, going to introduce threading issues into your design. If 
>> the background thread keeps its results private (within the thread) until 
>> you switch back to the main thread, you can actually update any permanent 
>> data structures on the main thread, avoiding the need for locks or other 
>> synchronization techniques. However, you have to arrange for the main thread 
>> to avoid trying to use the results before the background computation is 
>> done, or to start any new computations, until the old ones are done, as far 
>> as such safety checks are necessary for your app.
>> 
>> (You can use NSOperationQueue instead of GCD, but I don’t see a lot of 
>> advantage in that. The consequences are the same.)
> 
> You are absolutely right that a background would be the right thing.
> But this is just a small tool for testing, and it will not take more than a 
> few seconds, so I am trying to avoid this.
> 
> But I have found a solution (you mentioning setNeedsDisplay was a great help):
> 
> - (void)computeSomething
> {
>   self.textField1.stringValue = @“Start computing”;
>   [self.textField1 display];
>   //  some seconds of computations
>   self.textField1.stringValue = @“Result = 42”;
> }
> 
> Gerriet.
> 
> 
> 
> ___
> 
> Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)
> 
> Please do not post admin requests or moderator comments to the list.
> Contact the moderators at cocoa-dev-admins(at)lists.apple.com
> 
> Help/Unsubscribe/Update your Subscription:
> 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

Re: How to set a TextField

2016-03-14 Thread Gerriet M. Denkmann

> On 14 Mar 2016, at 14:17, Quincey Morris 
>  wrote:
> 
> On Mar 13, 2016, at 23:50 , Gerriet M. Denkmann  wrote:
>> 
>> - (void)computeSomething
>> {
>>  self.message1 = @“Start computing”;
>>  //  some seconds of computations
>>  self.message1 = @“Result = 42”;
>> }
> 
> Assume, conceptually, that drawing only takes place asynchronously (that is 
> to say, setting a new value on the string invokes setNeedsDisplay, that’s 
> all), and it’s obvious why this isn’t going to work.
> 
> But the real issue is not that the text field won’t update, it’s that you’re 
> blocking the main thread with computation. You should move the computation 
> off the main thread — using dispatch_async to a default queue. At the end of 
> the computation, go back to the main thread (dispatch_async again, specifying 
> the main queue this time) and put the result in the text field.
> 
> This is, of course, going to introduce threading issues into your design. If 
> the background thread keeps its results private (within the thread) until you 
> switch back to the main thread, you can actually update any permanent data 
> structures on the main thread, avoiding the need for locks or other 
> synchronization techniques. However, you have to arrange for the main thread 
> to avoid trying to use the results before the background computation is done, 
> or to start any new computations, until the old ones are done, as far as such 
> safety checks are necessary for your app.
> 
> (You can use NSOperationQueue instead of GCD, but I don’t see a lot of 
> advantage in that. The consequences are the same.)

You are absolutely right that a background would be the right thing.
But this is just a small tool for testing, and it will not take more than a few 
seconds, so I am trying to avoid this.

But I have found a solution (you mentioning setNeedsDisplay was a great help):

- (void)computeSomething
{
self.textField1.stringValue = @“Start computing”;
[self.textField1 display];
//  some seconds of computations
self.textField1.stringValue = @“Result = 42”;
}

Gerriet.



___

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

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

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

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

Re: How to set a TextField

2016-03-14 Thread Quincey Morris
On Mar 13, 2016, at 23:50 , Gerriet M. Denkmann  wrote:
> 
> - (void)computeSomething
> {
>   self.message1 = @“Start computing”;
>   //  some seconds of computations
>   self.message1 = @“Result = 42”;
> }

Assume, conceptually, that drawing only takes place asynchronously (that is to 
say, setting a new value on the string invokes setNeedsDisplay, that’s all), 
and it’s obvious why this isn’t going to work.

But the real issue is not that the text field won’t update, it’s that you’re 
blocking the main thread with computation. You should move the computation off 
the main thread — using dispatch_async to a default queue. At the end of the 
computation, go back to the main thread (dispatch_async again, specifying the 
main queue this time) and put the result in the text field.

This is, of course, going to introduce threading issues into your design. If 
the background thread keeps its results private (within the thread) until you 
switch back to the main thread, you can actually update any permanent data 
structures on the main thread, avoiding the need for locks or other 
synchronization techniques. However, you have to arrange for the main thread to 
avoid trying to use the results before the background computation is done, or 
to start any new computations, until the old ones are done, as far as such 
safety checks are necessary for your app.

(You can use NSOperationQueue instead of GCD, but I don’t see a lot of 
advantage in that. The consequences are the same.)

___

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

How to set a TextField

2016-03-14 Thread Gerriet M. Denkmann
I have a String message1, bound to TextField textField1. (OS X 10.10.5).

- (void)computeSomething
{
self.message1 = @“Start computing”;
//  some seconds of computations
self.message1 = @“Result = 42”;
}

This never shows “Start computing”.
(same problem with self. textField1.stringValue = @“Start computing”;)

This rather ugly hack works:

self.message1 = @“Start computing”;
//  0.01 ok; 0.001 mostly ok; 0.0001 too small
[ self performSelector: @selector(computeSomething) withObject: nil afterDelay: 
0.01 ]; 

Is there a better way (without this rather arbitrary delay)?

Gerriet.


___

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

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

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

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