Swift Enums and CoreData

2015-07-06 Thread Rick Aurbach
I have an object class which maps to a CoreData object. Each instance of this 
object contains a one-to-many relationship to a set of subsidiary objects, each 
of which describes an event. That is, each main object has an array of events.

Now there are a number of different event types (around a half-dozen or so), 
each with its own associated data. That is, different events use different 
data. I am trying to figure out the best way to represent this situation in 
both CoreData and Swift.

Here’s what I’m thinking:
 From a Swift perspective, an Event object would contain a Swift enumeration 
 as a data member. This data member would map to an integer (its value) in 
 the associated CoreData object.
 The enumeration-specific data would be represented in CoreData by a 
 Transformable field that mapped to an NSMutableDictionary in the Event 
 object.
 In C++, I’d write EventT as an abstract class, then construct a set of 
 explicit template specialization classes that handles each valid value of 
 the enumeration type T. EventT would contain the dictionary; each 
 specialization would contain data members for the specific data items that 
 event-type used.
 The question is whether this is a good (or even viable) model for a Swift 
 implementation. I can envision using the enumeration’s associated data to 
 store the event-specific data. I can also envision using generics to 
 implement what I’d call template specialization if I were writing in C++.
 On the data side, actual classes could store data in data members (moving 
 data between the dictionary and local storage explicitly) or it could 
 implement data members that hid dictionary keyed-access behind the scenes 
 (i.e. the getter call event.foo is implemented via accessing the “foo” key 
 of the dictionary).

So my question: does this make any sense? Is anyone out there dealing with this 
type of problem, and if so have you thought of a better approach? If you had a 
problem like this, how would YOU tackle it? Since I’m a Swift newbie (well, I 
guess everybody still is, but I’m more so than most), I would appreciate any 
thoughts or suggestions for the best way to tackle this problem.

Thanks.

Cheers,

Rick Aurbach
Aurbach  Associates, Inc.


___

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: selectText of NSTextField on focus

2015-07-06 Thread Quincey Morris
On Jul 6, 2015, at 12:38 , Richard Charles rcharles...@gmail.com wrote:
 
 The delegate methods textDidBeginEditing: and controlTextDidBeginEditing: are 
 not called when clicking into the view. They are called when the first edit 
 is actually attempted. So that did not work.

My only other suggestion is that the frameworks might *always* issue a text 
selection, or at least the first time the text field is entered. (And you said 
this seems to be happening.) You might be able to override selectText: and use 
a flag to keep track of whether it’s the first time.



___

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: selectText of NSTextField on focus

2015-07-06 Thread Mike Abdullah

 On 6 Jul 2015, at 20:38, Richard Charles rcharles...@gmail.com wrote:
 
 On Jul 6, 2015, at 12:12 PM, Gary L. Wade wrote:
 
 You want to select the text using the associated text view of the 
 NSTextField control.
 
 Not sure what you mean by the associated text view of the control. Do you 
 mean the field editor of the control? I have subclassed NSTextField and 
 overridden becomeFirstResponder. NSTextField is a subclass of NSControl which 
 is a subclass of NSView.
 
 
 On Jul 6, 2015, at 12:07 PM, Quincey Morris wrote:
 
 On Jul 6, 2015, at 10:54 , Richard Charles wrote:
 
  [self performSelector:@selector(selectText:) withObject:self 
 afterDelay:0];
 
 I dunno, but I suspect that this isn’t good enough. You’re merely guessing 
 that “on the next iteration of the run loop” is *after* the text field 
 finished becoming first responder, but it may take time to get the text 
 field into a state where its selection can be set.
 
 Yes I think that is the case. The following code works.
 
 [self performSelector:@selector(selectText:) withObject:self afterDelay:0.1];
 
 
 I’d suggest you try selecting the text in a delegate method 
 (textDidBeginEditing or controlTextDidBeginEditing) instead.
 
 The delegate methods textDidBeginEditing: and controlTextDidBeginEditing: are 
 not called when clicking into the view. They are called when the first edit 
 is actually attempted. So that did not work.
 
 
 In fiddling around with afterDelay: values this is what I found.
 
 afterDelay:0.01 // This did not work. Text not selected.
 
 afterDelay:0.02 // This works. Text is selected.
 
 afterDelay:0.1 // This works. Text is selected.
 
 afterDelay:1.0 // This works but the delay is too long.
 
 So do you think I am safe using this call.
 
 [self performSelector:@selector(selectText:) withObject:self afterDelay:0.1];

No.

Almost any time you have a delayed perform in your code, you’re doing something 
a bit dubious, and you’ve just wandered into proper dodgy territory, where your 
code is guaranteed to be unreliable.


___

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: Errors resulting from Cocoa datatype changes 10.9 - 10.10

2015-07-06 Thread Thomas Wetmore
Carl,

There is nothing wrong with the code. It is good C code from the good ole days. 
Size of pointers has no effect, other than in the total sizes of the arrays 
being allocated. Similar for the size of ints themselves.

However, you stop short in your example, and you don’t show either how you 1) 
put values into the arrays, or 2) use those values. I would guess the problem 
is in one of those two places, and not in the allocation of the arrays nor in 
the nature of 64-bit arithmetic.

I would recommend you insert some code directly after you create the arrays, 
that first loads them with a simple pattern of values, and you then immediately 
print them out or look at them with a debugger. You need to first assure 
yourself that the arrays are holding exactly what you think they should be 
holding before you start looking at the overall results of arithmetic 
operations.

Good luck,

Tom Wetmore

 On Jul 6, 2015, at 3:38 PM, Carl Hoefs newsli...@autonomy.caltech.edu wrote:
 
 We have a legacy Cocoa library of mathematical algorithms that has worked
 fine since OS X 10.6, but running this same code on 10.10 results in odd
 numerical errors (that is, incorrect results). I'm thinking this could be
 the result of differences in ILP32 vs LP64?
 
 The code variables are ints and pointers, and there's a bunch of memory
 allocation for arrays that looks fragile. I know that the size of ints has
 not changed, but pointers have gone from 4 bytes to 8 bytes in LP64. Could
 this be the problem?
 
 Here's a sample of affected code:
 
 int ***hov;
 
 /* memory allocation for data arrays */
 if((hov=(int ***)malloc(LNUM*sizeof(int **)))==NULL)
 {
   fprintf(stderr,Error in memory allocation for hov!\n);
   return(-1);
 }
 for(k=0;kLNUM;k++)
 {
   if((hov[k]=(int **)malloc(XDIM*sizeof(int *)))==NULL)
   {
 fprintf(stderr,Error in memory allocation for hov[%d]!\n,k);
 return(-1);
   }
   for(i=0;iXDIM;i++)
   {
  if((hov[k][i]=(int *)malloc(YDIM*sizeof(int)))==NULL)
  {
 fprintf(stderr, in memory allocation for hov[%d][%d]!\n,k,i);
 return(-1);
  }
}
  }
 
  /* calculate total field in deg^2 tested per level */
  TOTAL_VF=XDIM*YDIM*(GRES/60.0)*(GRES/60.0);
 
. . . etc.
 
 I've tried promoting the ints to longs, but the errors in the mathematical
 computations became much worse.
 -Carl
 
 
 ___
 
 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/ttw4%40verizon.net
 
 This email sent to t...@verizon.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: selectText of NSTextField on focus

2015-07-06 Thread Richard Charles

 On Jul 6, 2015, at 10:15 AM, Richard Charles rcharles...@gmail.com wrote:
 
 I have a NSTextField subclass that selects all of the text when the user 
 clicks it. This is accomplished by overriding becomeFirstResponder.
 
 - (BOOL)becomeFirstResponder
 {
BOOL result = [super becomeFirstResponder];
if(result) {
[self performSelector:@selector(selectText:) withObject:self 
 afterDelay:0];
}
return result;
 }
 
 http://stackoverflow.com/questions/2195704/selecttext-of-nstextfield-on-focus
 
 This has worked perfectly for years until 10.10 Yosemite. Now when the user 
 clicks into the text field nothing is selected.
 
 Also the following error will often occur on 10.10 Yosemite when clicking on 
 the text field.
 
 2015-07-06 10:09:04.287 MyApp[727:15035] Bad cursor rect event, flags = 256
 
 Does anyone have any insight into what is going on?
 
 Thanks so much.
 
 --Richard Charles

Update

The documentation for -[NSTextField selectText:] states If the receiver isn’t 
in some window’s view hierarchy, this method has no effect.”

I have verified that the text field is in the window’s view hierarchy. I have 
verified that -[NSTextField selectText:] is getting called. (Actually it is 
getting called twice, once by the frameworks for some reason, and once by me.) 
Calling the method -[NSTextField isSelectable] returns YES.

It appears that -[NSTextField selectText:] is broken in 10.10 Yosemite. It just 
does not work.

--Richard Charles


___

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

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

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

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

Re: selectText of NSTextField on focus

2015-07-06 Thread Quincey Morris
On Jul 6, 2015, at 10:54 , Richard Charles rcharles...@gmail.com wrote:

[self performSelector:@selector(selectText:) withObject:self 
 afterDelay:0];

I dunno, but I suspect that this isn’t good enough. You’re merely guessing that 
“on the next iteration of the run loop” is *after* the text field finished 
becoming first responder, but it may take time to get the text field into a 
state where its selection can be set.

I’d suggest you try selecting the text in a delegate method 
(textDidBeginEditing or controlTextDidBeginEditing) instead.


___

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

selectText of NSTextField on focus

2015-07-06 Thread Richard Charles
I have a NSTextField subclass that selects all of the text when the user clicks 
it. This is accomplished by overriding becomeFirstResponder.

- (BOOL)becomeFirstResponder
{
BOOL result = [super becomeFirstResponder];
if(result) {
[self performSelector:@selector(selectText:) withObject:self 
afterDelay:0];
}
return result;
}

http://stackoverflow.com/questions/2195704/selecttext-of-nstextfield-on-focus

This has worked perfectly for years until 10.10 Yosemite. Now when the user 
clicks into the text field nothing is selected.

Also the following error will often occur on 10.10 Yosemite when clicking on 
the text field.

2015-07-06 10:09:04.287 MyApp[727:15035] Bad cursor rect event, flags = 256

Does anyone have any insight into what is going on?

Thanks so much.

--Richard Charles


___

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

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

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

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

Re: selectText of NSTextField on focus

2015-07-06 Thread Richard Charles
 On Jul 6, 2015, at 12:12 PM, Gary L. Wade wrote:
 
 You want to select the text using the associated text view of the NSTextField 
 control.

Not sure what you mean by the associated text view of the control. Do you 
mean the field editor of the control? I have subclassed NSTextField and 
overridden becomeFirstResponder. NSTextField is a subclass of NSControl which 
is a subclass of NSView.


 On Jul 6, 2015, at 12:07 PM, Quincey Morris wrote:
 
 On Jul 6, 2015, at 10:54 , Richard Charles wrote:
 
   [self performSelector:@selector(selectText:) withObject:self 
 afterDelay:0];
 
 I dunno, but I suspect that this isn’t good enough. You’re merely guessing 
 that “on the next iteration of the run loop” is *after* the text field 
 finished becoming first responder, but it may take time to get the text field 
 into a state where its selection can be set.

Yes I think that is the case. The following code works.

[self performSelector:@selector(selectText:) withObject:self afterDelay:0.1];


 I’d suggest you try selecting the text in a delegate method 
 (textDidBeginEditing or controlTextDidBeginEditing) instead.

The delegate methods textDidBeginEditing: and controlTextDidBeginEditing: are 
not called when clicking into the view. They are called when the first edit is 
actually attempted. So that did not work.


In fiddling around with afterDelay: values this is what I found.

 afterDelay:0.01 // This did not work. Text not selected.

 afterDelay:0.02 // This works. Text is selected.

 afterDelay:0.1 // This works. Text is selected.

 afterDelay:1.0 // This works but the delay is too long.

So do you think I am safe using this call.

[self performSelector:@selector(selectText:) withObject:self afterDelay:0.1];

--Richard Charles


___

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

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

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

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

Re: selectText of NSTextField on focus

2015-07-06 Thread Gary L. Wade
You want to select the text using the associated text view of the NSTextField 
control.
--
Gary L. Wade (Sent from my iPhone)
http://www.garywade.com/

 On Jul 6, 2015, at 10:54 AM, Richard Charles rcharles...@gmail.com wrote:
 
 
 On Jul 6, 2015, at 10:15 AM, Richard Charles rcharles...@gmail.com wrote:
 
 I have a NSTextField subclass that selects all of the text when the user 
 clicks it. This is accomplished by overriding becomeFirstResponder.
 
 - (BOOL)becomeFirstResponder
 {
   BOOL result = [super becomeFirstResponder];
   if(result) {
   [self performSelector:@selector(selectText:) withObject:self 
 afterDelay:0];
   }
   return result;
 }
 
 http://stackoverflow.com/questions/2195704/selecttext-of-nstextfield-on-focus
 
 This has worked perfectly for years until 10.10 Yosemite. Now when the user 
 clicks into the text field nothing is selected.
 
 Also the following error will often occur on 10.10 Yosemite when clicking on 
 the text field.
 
 2015-07-06 10:09:04.287 MyApp[727:15035] Bad cursor rect event, flags = 256
 
 Does anyone have any insight into what is going on?
 
 Thanks so much.
 
 --Richard Charles
 
 Update
 
 The documentation for -[NSTextField selectText:] states If the receiver 
 isn’t in some window’s view hierarchy, this method has no effect.”
 
 I have verified that the text field is in the window’s view hierarchy. I have 
 verified that -[NSTextField selectText:] is getting called. (Actually it is 
 getting called twice, once by the frameworks for some reason, and once by 
 me.) Calling the method -[NSTextField isSelectable] returns YES.
 
 It appears that -[NSTextField selectText:] is broken in 10.10 Yosemite. It 
 just does not work.
 
 --Richard Charles

___

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

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

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

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

Errors resulting from Cocoa datatype changes 10.9 - 10.10

2015-07-06 Thread Carl Hoefs
We have a legacy Cocoa library of mathematical algorithms that has worked
fine since OS X 10.6, but running this same code on 10.10 results in odd
numerical errors (that is, incorrect results). I'm thinking this could be
the result of differences in ILP32 vs LP64?

The code variables are ints and pointers, and there's a bunch of memory
allocation for arrays that looks fragile. I know that the size of ints has
not changed, but pointers have gone from 4 bytes to 8 bytes in LP64. Could
this be the problem?

Here's a sample of affected code:

 int ***hov;

 /* memory allocation for data arrays */
 if((hov=(int ***)malloc(LNUM*sizeof(int **)))==NULL)
 {
   fprintf(stderr,Error in memory allocation for hov!\n);
   return(-1);
 }
 for(k=0;kLNUM;k++)
 {
   if((hov[k]=(int **)malloc(XDIM*sizeof(int *)))==NULL)
   {
 fprintf(stderr,Error in memory allocation for hov[%d]!\n,k);
 return(-1);
   }
   for(i=0;iXDIM;i++)
   {
  if((hov[k][i]=(int *)malloc(YDIM*sizeof(int)))==NULL)
  {
 fprintf(stderr, in memory allocation for hov[%d][%d]!\n,k,i);
 return(-1);
  }
}
  }

  /* calculate total field in deg^2 tested per level */
  TOTAL_VF=XDIM*YDIM*(GRES/60.0)*(GRES/60.0);

. . . etc.

I've tried promoting the ints to longs, but the errors in the mathematical
computations became much worse.
-Carl


___

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: selectText of NSTextField on focus

2015-07-06 Thread Quincey Morris
On Jul 6, 2015, at 16:16 , Richard Charles rcharles...@gmail.com wrote:
 
 Finder does something similar when renaming files and folders. The first 
 click selects the file or folder. The next click selects the name of the file 
 or folder ready for replacement. The third click will place the insertion 
 point somewhere within the text field ready for fine grain editing of the 
 file or folder name.

In general, if the text field doesn’t look editable until you “click to edit” 
(click #2 in the above, because I assume you don’t have click #1 at all in your 
app), then I think it’s fine for it to do a select all (or select 
something-predefined-like-Finder-does), because there’s no expectation from the 
appearance of the text that you might start with a drag-to-select-and-begin 
editing.

In your case, where the “click to edit” behavior is already expected by users, 
I don’t see a big problem in what you’re proposing, though I think the *classy* 
solution would be to have a subtle difference in appearance in the text field 
when a click is needed to start editing, even if it flies under the perceptual 
radar of experienced users.



___

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: selectText of NSTextField on focus

2015-07-06 Thread Richard Charles

 On Jul 6, 2015, at 4:09 PM, Quincey Morris wrote:
 
 Incidentally — this is the part where we make you sorry you asked the 
 question — what are you trying to achieve here? Auto-self-selecting text 
 fields are an incredibly annoying UI, if the user is ever likely to want to 
 select only part of the field.

The text field contains a numeric values like 58.35 or -2.41 or something 
similar. The gold standard for this type of application and this type of data 
is to have the contents of the text field selected when the user clicks on it 
so he or she can quickly key in a new value to replace the existing value. 
Behavior other than this is a pain and not appreciated by typical users of this 
application.

Finder does something similar when renaming files and folders. The first click 
selects the file or folder. The next click selects the name of the file or 
folder ready for replacement. The third click will place the insertion point 
somewhere within the text field ready for fine grain editing of the file or 
folder name.

--Richard Charles


___

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

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

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

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

Re: selectText of NSTextField on focus

2015-07-06 Thread Joel Norvell
Hi Richard,

When the instance of your NSTextField subclass becomes first responder, you 
have access to the NSText object (the field editor) and I believe you can use 
its methods to select the text. (I don't see why you can't, but since I haven't 
tried it myself, I'm saying I believe.)
Sincerely,Joel
Override - (BOOL)becomeFirstResponder in your subclass.
Get the field editor:
NSText * itsText = [[self window] fieldEditor:YES forObject:self];
Use -selectAll or -setSelectedRange
___

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: Swift Enums and CoreData

2015-07-06 Thread Rick Aurbach

On Jul 6, 2015, at 5:15 PM, Quincey Morris 
quinceymor...@rivergatesoftware.commailto:quinceymor...@rivergatesoftware.com
 wrote:

On Jul 6, 2015, at 13:10 , Rick Aurbach 
r...@aurbach.commailto:r...@aurbach.com wrote:

So my question: does this make any sense?

If I was going to Swift-ify the Event concept, I wouldn’t use an enum *inside* 
an Event object, I’d use an enum (with associated values) *instead of* an Event 
object. In the context of Core Data, this would similar to creating a custom 
scalar property that’s backed by a Core Data property, which is not hard but 
incredibly badly documented in the Core Data reference guide.

But since this is Core Data, I’m not sure it’s a good idea to add an eighth 
hell to the seven you’re in already. It may be better to stick to whatever is 
most natural for Core Data, which is whatever you’d do in Obj-C.


Quincy,

Thanks for your response.

Are you suggesting that we implement a custom fetched property rather than an 
entity as a way of implementing the idea that a “main” object may have a whole 
set of events associated with it (presumably ordered by date/time)? That’s an 
interesting idea, although I must say I’ve never used fetched properties before 
and don’t really understand the pluses and minuses of this approach.

I was thinking about uses a one-to-many relationship between “main” objects and 
event objects. (It’s what I’m familiar with.) But I am certainly willing to be 
convinced to try something new!

If I am correctly understanding you, then I hope you will be willing to share 
why you think a fetched property might be useful in this situation. (I’m 
learning Swift for this project; it would be fun to learn something new about 
CoreData, too.)

Thanks,

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: Swift Enums and CoreData

2015-07-06 Thread Quincey Morris
On Jul 6, 2015, at 16:21 , Rick Aurbach r...@aurbach.com wrote:
 
 Are you suggesting that we implement a custom fetched property

No, I’m thinking of this:

https://developer.apple.com/library/ios/documentation/Cocoa/Conceptual/CoreData/Articles/cdNSAttributes.html#//apple_ref/doc/uid/TP40001919-SW13
 
https://developer.apple.com/library/ios/documentation/Cocoa/Conceptual/CoreData/Articles/cdNSAttributes.html#//apple_ref/doc/uid/TP40001919-SW13

under the heading “Scalar Value”, but some of the details are here:

https://developer.apple.com/library/ios/documentation/Cocoa/Conceptual/CoreData/Articles/cdAccessorMethods.html#//apple_ref/doc/uid/TP40002154-SW1
 
https://developer.apple.com/library/ios/documentation/Cocoa/Conceptual/CoreData/Articles/cdAccessorMethods.html#//apple_ref/doc/uid/TP40002154-SW1

The idea is that you create non-primitive accessors that have a type that’s not 
known to Core Data. You back it with a Core Data property, using any convenient 
mechanism. Optionally, you can have an instance variable that caches the non-CD 
value, or you can just convert it back and forth on the fly.

Note that you can, of course, back your customized property with multiple CD 
properties, or with a CD property whose value themselves have sub-properties.



___

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: selectText of NSTextField on focus

2015-07-06 Thread Quincey Morris
On Jul 6, 2015, at 09:15 , Richard Charles rcharles...@gmail.com wrote:
 
 I have a NSTextField subclass that selects all of the text when the user 
 clicks it.

Incidentally — this is the part where we make you sorry you asked the question 
— what are you trying to achieve here? Auto-self-selecting text fields are an 
incredibly annoying UI, if the user is ever likely to want to select only part 
of the field.

If you’re selecting everything to allow it to be copied easily, then a “Copy” 
button next to the text is probably a better idea.

If you’re selecting everything in order to cause it to be deleted on the first 
keystroke, a “Clear” button (probably an “x” icon button) similar to iOS search 
fields is probably a better idea.

That is, if at all possible, augment the standard behavior, don’t change 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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

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

Re: Swift Enums and CoreData

2015-07-06 Thread Quincey Morris
On Jul 6, 2015, at 13:10 , Rick Aurbach r...@aurbach.com wrote:
 
 So my question: does this make any sense?

If I was going to Swift-ify the Event concept, I wouldn’t use an enum *inside* 
an Event object, I’d use an enum (with associated values) *instead of* an Event 
object. In the context of Core Data, this would similar to creating a custom 
scalar property that’s backed by a Core Data property, which is not hard but 
incredibly badly documented in the Core Data reference guide.

But since this is Core Data, I’m not sure it’s a good idea to add an eighth 
hell to the seven you’re in already. It may be better to stick to whatever is 
most natural for Core Data, which is whatever you’d do in Obj-C.



___

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: Unable to connect IBOutlet in Swift Xcode 7b2

2015-07-06 Thread Charles Srstka
On Jul 6, 2015, at 7:46 PM, Rick Mann rm...@latencyzero.com wrote:
 
 I'm having a heck of a time connecting UIViews to my classes. I have a 
 UICollectionViewCell subclass with a bunch of subviews. One of those is 
 custom.
 
 While I can drag from views to the Swift code for the UICollectionViewCell 
 subclass, it keeps trying to connect it to a storyboard in a completely 
 unrelated project in a separate directory. It appears to do the right thing, 
 but at runtime the outlet is nil, and clicking on the little dot by the line 
 of code pops up a menu referencing this other storyboard.*
 
 There's a custom subview in the cell that's also implemented in a Swift file. 
 I want to connect subviews of that to it, but Xcode won't prompt to create 
 the IBOutlet when I drag from those.
 
 I can't figure out what's going on, but it's very broken. I've tried cleaning 
 and restarting Xcode to no avail.
 
 *The UICollectionViewCell subclass view hierarchy was dragged over from 
 another storyboard in another project. That's the file my new project keeps 
 trying to reference, but I can't figure out why. The other project isn't even 
 open when this happens. I've looked inside the pbxproj file and the 
 storyboard file, and there are no references to that other file. But Xcode 
 keeps showing it.
 
 I've reported this behavior in bugreporter, but I'm really stuck here.

I’ve occasionally had issues getting Xcode to connect outlets and actions. My 
workaround for it is to open the Assistant view, and drag from your view into 
the source file, and let Xcode create an outlet or action automatically. Then 
you can delete the one it created and it should work with the one you already 
had.

Charles

___

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

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

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

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

Unable to connect IBOutlet in Swift Xcode 7b2

2015-07-06 Thread Rick Mann
I'm having a heck of a time connecting UIViews to my classes. I have a 
UICollectionViewCell subclass with a bunch of subviews. One of those is custom.

While I can drag from views to the Swift code for the UICollectionViewCell 
subclass, it keeps trying to connect it to a storyboard in a completely 
unrelated project in a separate directory. It appears to do the right thing, 
but at runtime the outlet is nil, and clicking on the little dot by the line of 
code pops up a menu referencing this other storyboard.*

There's a custom subview in the cell that's also implemented in a Swift file. I 
want to connect subviews of that to it, but Xcode won't prompt to create the 
IBOutlet when I drag from those.

I can't figure out what's going on, but it's very broken. I've tried cleaning 
and restarting Xcode to no avail.

*The UICollectionViewCell subclass view hierarchy was dragged over from another 
storyboard in another project. That's the file my new project keeps trying to 
reference, but I can't figure out why. The other project isn't even open when 
this happens. I've looked inside the pbxproj file and the storyboard file, and 
there are no references to that other file. But Xcode keeps showing it.

I've reported this behavior in bugreporter, but I'm really stuck here.

-- 
Rick Mann
rm...@latencyzero.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: Unable to connect IBOutlet in Swift Xcode 7b2

2015-07-06 Thread Rick Mann

 On Jul 6, 2015, at 17:54 , Charles Srstka cocoa...@charlessoft.com wrote:
 
 I’ve occasionally had issues getting Xcode to connect outlets and actions. My 
 workaround for it is to open the Assistant view, and drag from your view into 
 the source file, and let Xcode create an outlet or action automatically. Then 
 you can delete the one it created and it should work with the one you already 
 had.

This is what Xcode is refusing to do. As if the class definition wasn't 
matching the class I specified in the storyboard (but it does; I copied and 
pasted the name).

-- 
Rick Mann
rm...@latencyzero.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