NSTableView - kill the blue (Obj-C)

2015-07-26 Thread 2551
I’ve been struggling with NSTableView for the last two days. All I want to do 
is ensure the alternative “gray” highlight is used on a selection consistently 
instead of the heavy blue. Here’s my code:

-(void) killBlue
{
NSInteger selectedRow = [_tableView selectedRow];

if ([_tableView selectedRow] != -1) //only call this if there is a 
selection
{
NSTableRowView *myRowView = [_tableView rowViewAtRow:selectedRow 
makeIfNecessary:NO];

   [myRowView 
setSelectionHighlightStyle:NSTableViewSelectionHighlightStyleRegular];

[myRowView setEmphasized:NO];

[_tableView 
setSelectionHighlightStyle:NSTableViewSelectionHighlightStyleNone];

}

}

I’m calling this from three places:

1. In -tableViewSelectionDidChange: //to take care of user-initiated selection 
changes
2. In -tabViewToggle//because the blue comes back when the TabView the 
TableView is embedded in is switched back and forth

and

3 and in -(void)applicationDidBecomeActive:(NSNotification *)aNotification 
//because the blue comes back when the app is switched in and out of frontmost

1 and 2 work fine. At first 3 only worked when the app was switched in an out 
of focus with the cmd-tab app switcher keys, but not when mouse clicks were 
used to change the frontmost app. To solve that problem, I also had to ensure 
something else was firstResponder when the app was made frontmost. 

I thought my troubles were over, until I discovered that despite those three 
implementations, I **still** get the blue highlighting in a situation where a 
row is highlighted (correctly appearing gray), then I click on any other app, 
then click back on the highlighted row (rather than somewhere else in the 
window) to make my app active again. Sure enough, there’s the blue. I’m 
exhausted trying to think of all the ways to defeat this blue highlighting and 
would appreciate some guidance. 

I’ve seen SE posts suggesting subclassing NSTableRowView, but I don’t 
understand why, since the property setEmphasized already exists in the parent 
class and should work across the board (shouldn’t it??).

Any thoughts much appreciated. 


Best

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

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

Re: WKWebView loading local files (and relative paths)

2015-07-26 Thread Tim Fletcher
Solved

Sorry for the noise List.

It was user error. I wasn’t using the WebView correctly.

Tim

> On 26 Jul 2015, at 07:30, Tim Fletcher  wrote:
> 
> Sorry, massive omission on my part. I'm building a desktop OS X 10.10.4
> application. Using the latest Xcode
> 
> On Sunday, July 26, 2015, Jens Alfke  wrote:
> 
>> The path in your example (starting with /Users) isn't valid for iOS. What
>> path are you really using? Are you sure that it's a real path to an HTML
>> file?
>> 
>> --Jens [via iPhone]
> ___
> 
> 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/timothy.m.fletcher%40gmail.com
> 
> This email sent to timothy.m.fletc...@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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

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

Re: NSTableView - kill the blue (Obj-C)

2015-07-26 Thread Ken Thomases
On Jul 26, 2015, at 7:25 AM, 2551 <2551p...@gmail.com> wrote:

> I’ve been struggling with NSTableView for the last two days. All I want to do 
> is ensure the alternative “gray” highlight is used on a selection 
> consistently instead of the heavy blue.

My first question is why do you want to trick your uses into seeing your table 
as being in a non-key window?  If you're going to use a non-standard selection 
highlight, you should use a different color entirely, one that doesn't have 
strong connotations already.


> I’ve seen SE posts suggesting subclassing NSTableRowView, but I don’t 
> understand why, since the property setEmphasized already exists in the parent 
> class and should work across the board (shouldn’t it??).

That setter is used by Cocoa itself to inform the row view whether it is 
emphasized (in the key window).  If you call it yourself, you have no guarantee 
(as you've seen) that your value won't be replaced by Cocoa at some point.

The right approach is to subclass NSTableRowView.  It's not hard.  Why do you 
resist it?

You could have your subclass override the emphasized property to always return 
false, but I'm not sure that's best.

You could also override -drawSelectionInRect:, which is precisely for 
customizing how the selection is drawn.  If you do that, you should also 
override -interiorBackgroundStyle to return an appropriate value (generally 
NSBackgroundStyleLight).  Otherwise, it will return NSBackgroundStyleDark for a 
selected and emphasized row, which will cause text fields to draw white.

Regards,
Ken


___

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

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

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

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

Re: NSTableView - kill the blue (Obj-C)

2015-07-26 Thread 2551

> On 26 Jul 2015, at 22:17, Ken Thomases  wrote:
> 
> The right approach is to subclass NSTableRowView.  It's not hard.  Why do you 
> resist it?
> 

OK, got it. Thanks for the pointers. Much appreciated!


Best


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

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

Updating a screensaver from 10.6 to 10.10

2015-07-26 Thread Gabriel Zachmann
Dear all,

I have written a screensaver , but unfortunately, I didn't have the time to 
update the source code sine OS X 10.7 .
It is still working so-so, but showing signs of code aging.

Now I would like to bring the source code up to date.

Does anybody know of some guidelines , or a list of hints, or any other 
document anywhere, that would outline the exact changes
I need to do.
In particular, I'd like to learn more about the changes needed in 
CoreAnimation, in Scripting Bridge to retrieve photos from iPhoto-now-Photos,
and the way I identify the current display/monitor.
Below are a few code snippets, for your information.

And I am interesting in anything else you might deem worthy of upgrading in the 
source code.

Thanks a lot in advance.

Best regards, 
Gabriel.



-
Code snippet I used to make a layer (containing only one image) cross-dissolve 
with a new one:

[CATransaction begin];
if ( crossDissolve_ )
  [CATransaction setAnimationDuration: fading_duration];
else
  [CATransaction setValue: (id)kCFBooleanTrue forKey: 
kCATransactionDisableActions];
[mainLayer_ replaceSublayer: currentLayer_ with: newlayer];
currentLayer_ = newlayer;
[CATransaction commit];

--
Code snippet I used to identify monitors/displays (this seems to fail since OS 
X 10.9 ):

displayNumber_ = [ [[newWindow screen] deviceDescription] objectForKey: 
@"NSScreenNumber"];
displayID_ = [displayNumber_ unsignedIntValue]; 
unsigned int main_screen_id = [[ [[NSScreen mainScreen] 
deviceDescription] objectForKey: @"NSScreenNumber"] unsignedIntValue];

I suspect , this code does not work any more as intended, because I get often a 
new display ID for exactly the same monitor (just a cinema display).



___

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

NSPropertyListSerialization weirdness

2015-07-26 Thread Robert Martin
I’m having some issues. I’m tracking a folder that is I watch via kqueue, and 
if a .plist arrives, I process it immediately. The plist contains a dictionary, 
which is successfully read with dictionaryWithContentsOfFile:. If I log the 
dictionary description, it is accurate. The dictionary only contains strings, 
arrays of string, NSNumbers, or NSDates.

Though I can guarantee that the plist is well formed when it’s sent, if I try 
to serialize it with:

NSData* plist = [NSPropertyListSerialization 
dataWithPropertyList:updateDictionary];

I get a null, and an error (200) that the plist contains null.

Before I make that call, I put in a check for nulls, but none are found:

[updateDictionary enumerateKeysAndObjectsUsingBlock:^(id key, id obj, 
BOOL *stop) {

if( obj == nil ){
*stop = YES;
NSLog( @"nil obj for key: %@", key );
}

*stop =  NO;
}];

I cannot understand how a dictionary which contains no nulls and only valid 
classes can generate the NSPropertyListSerialization error. Any ideas?

Rob


___

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: NSPropertyListSerialization weirdness

2015-07-26 Thread Jens Alfke

> On Jul 26, 2015, at 2:28 PM, Robert Martin  wrote:
> 
> I get a null, and an error (200) that the plist contains null.
> 
> Before I make that call, I put in a check for nulls, but none are found:

You’re checking for nil pointers. (Which are illegal in Foundation collections, 
so you’ll never find any.)
It sounds like the error is complaining about instances of NSNull.

If that’s not the problem, then another possibility is that updateDictionary 
itself is nil — your snippet won’t log that as a problem because the entire 
enumeration will be silently skipped.

—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: NSPropertyListSerialization weirdness

2015-07-26 Thread Robert Martin
Thanks Jens, I’ll test for NSNulls instead. I know the dictionary is valid 
because after I read it with dictionaryWithContentsOfFile:, I log it, and it 
‘looks' fine…


> On Jul 26, 2015, at 5:44 PM, Jens Alfke  wrote:
> 
> 
>> On Jul 26, 2015, at 2:28 PM, Robert Martin  wrote:
>> 
>> I get a null, and an error (200) that the plist contains null.
>> 
>> Before I make that call, I put in a check for nulls, but none are found:
> 
> You’re checking for nil pointers. (Which are illegal in Foundation 
> collections, so you’ll never find any.)
> It sounds like the error is complaining about instances of NSNull.
> 
> If that’s not the problem, then another possibility is that updateDictionary 
> itself is nil — your snippet won’t log that as a problem because the entire 
> enumeration will be silently skipped.
> 
> —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

Generics Question

2015-07-26 Thread Michael de Haan 
I’m writing a coreData helper  which will rely on Generics. 

Could I get some input?

 I have synthesized the problem down to this somewhat nonsensical code.

From Playground:





func intFor(s:String) -> Int {

return Int(s)!

}

func genericIntFor(s:String) -> T {

return T(s)!  // T cannot be constructed because it has no accessible 
initializers.

}



let intFromStr = intFor("9”) // 9
let intFromStrB:Double = genericIntFor("9”)

<



The first function does pretty much what it says.
The second tries to use Generics, with an error as shown. Now, I **thought** ( 
which is often not a good thing) that T would allow , in this case, either an 
integer or double to be returned, given a valid string input that represents a 
number, say from 0 to 9.
Is it possible the way I wrote, or is there some fundamental misunderstanding 
of Generics? 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

Re: Generics Question

2015-07-26 Thread Michael de Haan 

Oops… I should have called it genericTfor etc as in: 


>>>

func intFor(s:String) -> Int {

return Int(s)!

}

func genericTFor(s:String) -> T {

return T(s)!

}



let intFromStr = intFor("9")
let intFromStrB:Double = genericTFor("9")


 in other words, write a generic function that will return an Int, Double for a 
given string value, depending upon the input i.e. T





> On Jul 26, 2015, at 3:44 PM, Alan Westbrook  wrote:
> 
> I think you want genericIntFor() to return Int instead of T
> 
> Alan
> 
>> On Jul 26, 2015, at 3:10 PM, Michael de Haan   wrote:
>> 
>> I’m writing a coreData helper  which will rely on Generics. 
>> 
>> Could I get some input?
>> 
>> I have synthesized the problem down to this somewhat nonsensical code.
>> 
>> From Playground:
>> 
>> 
>> 
>> 
>> 
>> func intFor(s:String) -> Int {
>> 
>>   return Int(s)!
>> 
>> }
>> 
>> func genericIntFor(s:String) -> T {
>> 
>>   return T(s)!  // T cannot be constructed because it has no accessible 
>> initializers.
>> 
>> }
>> 
>> 
>> 
>> let intFromStr = intFor("9”) // 9
>> let intFromStrB:Double = genericIntFor("9”)
>> 
>> <
>> 
>> 
>> 
>> The first function does pretty much what it says.
>> The second tries to use Generics, with an error as shown. Now, I **thought** 
>> ( which is often not a good thing) that T would allow , in this case, either 
>> an integer or double to be returned, given a valid string input that 
>> represents a number, say from 0 to 9.
>> Is it possible the way I wrote, or is there some fundamental 
>> misunderstanding of Generics? 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/voidref%40me.com
>> 
>> This email sent to void...@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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

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

CGFloat and literal floats in Swift

2015-07-26 Thread Rick Mann
I'm finding it a bit cumbersome to use CGFloat in graphics code in Swift, 
because the compiler won't let me pass a floating-point literal to a parameter 
that takes a CGFloat. I have to wrap them all in CGFloat().

This seems really, well, cumbersome. Why does the language impose this burden? 
Is there any way around it?

TIA,

-- 
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: Updating a screensaver from 10.6 to 10.10

2015-07-26 Thread Graham Cox

> On 27 Jul 2015, at 7:11 am, Gabriel Zachmann  wrote:
> 
> in Scripting Bridge to retrieve photos from iPhoto-now-Photos,


Don’t use Scripting Bridge for this. Since 10.9 there’s MLMediaLibrary and 
related classes which provide access to various media, including iPhoto and 
Photos content.

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

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

Re: CGFloat and literal floats in Swift

2015-07-26 Thread Quincey Morris
On Jul 26, 2015, at 15:57 , Rick Mann  wrote:
> 
> I'm finding it a bit cumbersome to use CGFloat in graphics code in Swift, 
> because the compiler won't let me pass a floating-point literal to a 
> parameter that takes a CGFloat. I have to wrap them all in CGFloat().

I’m not seeing this. Do you have an example that produces an error in a 
playground?



___

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: Generics Question

2015-07-26 Thread Quincey Morris
On Jul 26, 2015, at 15:49 , Michael de Haan   wrote:
> 
> func genericTFor(s:String) -> T {
> 
>return T(s)!
> 
> }
> 
> 
> 
> let intFromStr = intFor("9")
> let intFromStrB:Double = genericTFor("9")
> 
> 
> in other words, write a generic function that will return an Int, Double for 
> a given string value, depending upon the input i.e. T

Generics aren’t templates, which is what you’d need for this to work. However, 
what are you really trying to do? Your last example can just as well be written:

let intFromStrB = Double (“9”)

What you really need to do depends on what you’re really trying to achieve.



___

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: CGFloat and literal floats in Swift

2015-07-26 Thread Rick Mann

> On Jul 26, 2015, at 16:07 , Quincey Morris 
>  wrote:
> 
> On Jul 26, 2015, at 15:57 , Rick Mann  wrote:
>> 
>> I'm finding it a bit cumbersome to use CGFloat in graphics code in Swift, 
>> because the compiler won't let me pass a floating-point literal to a 
>> parameter that takes a CGFloat. I have to wrap them all in CGFloat().
> 
> I’m not seeing this. Do you have an example that produces an error in a 
> playground?

Well, I'm trying, but Xcode crashes evaluating it. Here's the (iOS) playground:

http://pastebin.com/UM8NWS34

import CoreGraphics
import UIKit

let ctx = UIGraphicsGetCurrentContext()

func
addArc(inCenter : CGPoint, _ inRadius : CGFloat, _ inStartAngle : CGFloat, _ 
inEndAngle : CGFloat, _ inClockwise : Bool = false)
{
CGContextAddArc(ctx, inCenter.x, inCenter.y, inRadius, inStartAngle, 
inEndAngle, inClockwise ? 1 : 0)
}


addArc(CGPoint(x: 0, y: 0), 50.0, 0.0, M_PI)


I thought maybe the problem is that I'm not naming arguments in my CG wrapper 
function, and Swift isn't matching it because of the types? Weird, 'cause 
there's just the one function (it's actually a member in a class).

But no, that doesn't seem to be it. I added names, and it still doesn't like 
it. The error I get in both cases is "cannot invoke 'addArc' with an argument 
list of type '(CGPoint, CGFloat, Double, Double)'"



-- 
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: Generics Question

2015-07-26 Thread Michael de Haan 

> 
> 
> What you really need to do depends on what you’re really trying to achieve.

Sorry, it’s been a long day :-)


I am really trying to understand this.  So….. given this… and I think this will 
make sense now,


*
func intFor(s:String) -> Int {

return Int(s)!

}

func genericFor(s:String) -> T {

return T(s)!  // error. ’T’ cannot be constructed because it has no 
accessible initializers
}

let intFromString = intFor("8") //  —>>>  1
let doubleFromStr:Double = genericFor("9") // 2
let anotherIntFromStr:Int = genericFor("7")
***

(1)   intFromString is straight forward. it returns an integer, 8


(2)  I create a constant, “doubleFromStr” and type it as a double, then call 
the “generic” "genericFor(s:String) -> T” 

thinking that the return

 "T(s)!”

 could do what was done similarly in the call to “intFromString”.

But, as you can see, I get the error shown. So, wondering if what I am trying 
to do is possible, or just a misreading of “Generics"

Sorry for all the confusion.
___

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: CGFloat and literal floats in Swift

2015-07-26 Thread Rick Mann
Also weird, I only have to cast the last two arguments, not the second.

> On Jul 26, 2015, at 16:07 , Quincey Morris 
>  wrote:
> 
> On Jul 26, 2015, at 15:57 , Rick Mann  wrote:
>> 
>> I'm finding it a bit cumbersome to use CGFloat in graphics code in Swift, 
>> because the compiler won't let me pass a floating-point literal to a 
>> parameter that takes a CGFloat. I have to wrap them all in CGFloat().
> 
> I’m not seeing this. Do you have an example that produces an error in a 
> playground?
> 


-- 
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: CGFloat and literal floats in Swift

2015-07-26 Thread Quincey Morris
On Jul 26, 2015, at 16:29 , Rick Mann  wrote:
> 
> addArc(CGPoint(x: 0, y: 0), 50.0, 0.0, M_PI)

The problem in this case is that M_PI is a Double variable in Swift, not a 
compile time constant like in Obj-C. You will unfortunately have to wrap it in 
CGFloat(), then the constants should work fine.



___

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: CGFloat and literal floats in Swift

2015-07-26 Thread Rick Mann

> On Jul 26, 2015, at 16:34 , Quincey Morris 
>  wrote:
> 
> On Jul 26, 2015, at 16:29 , Rick Mann  wrote:
>> 
>> addArc(CGPoint(x: 0, y: 0), 50.0, 0.0, M_PI)
> 
> The problem in this case is that M_PI is a Double variable in Swift, not a 
> compile time constant like in Obj-C. You will unfortunately have to wrap it 
> in CGFloat(), then the constants should work fine.

So, is a literal 0.0 not of type Double?

And can CGFloat be made to be implicitly assignable from Double?


-- 
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: Generics Question

2015-07-26 Thread Marco S Hyman
> func genericFor(s:String) -> T {
> 
>return T(s)!  // error. ’T’ cannot be constructed because it has no 
> accessible initializers
> }

At compile time there is no way of determining if T has an initializer that
takes a string. You could do something like this



protocol InitFromString {
init?(_ value: String)
}

func genericFor(s:String) -> T {

   return T(s)!
}



Then add extensions to the various types you want to convert to make sure
they conform to the InitFromString protocol.


___

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: Generics Question

2015-07-26 Thread Quincey Morris
On Jul 26, 2015, at 16:30 , Michael de Haan   wrote:
> 
> func genericFor(s:String) -> T {
> 
>return T(s)!  // error. ’T’ cannot be constructed because it has no 
> accessible initializers
> }


This *generic* definition asks for an invocation of ‘init (_ s: String)’ *for 
any type that satisfies the constraints on T*. Since there are no constraints, 
this is only compilable if every type has a keywordless String-parameter 
initializer, and that’s obviously not true.

If this were a template (like an Obj-C macro, sorta), then the compiler could 
take the actual type of T and see what initializers are available. But Swift 
generics don’t work that way. 

To do literally what you’re asking for, you’d have to declare a new protocol P 
that contains the form of ‘init’ you want to use, then use protocol extensions 
to add conformance to P, then write your function like this:

func genericFor …

But it’s not clear that this is what you’re aiming at — your example doesn’t 
need any generic function at all. That’s why I was asking about a more 
realistic example of the problem you’re trying to solve.

___

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: Generics Question

2015-07-26 Thread Michael de Haan 
> . That’s why I was asking about a more realistic example of the problem 
> you’re trying to solve.

Point taken. 


This was just a “trivial” … well it seems not that trivial…example to deepen my 
understanding of Generics. So, I thank you, and will repost with a more 
specific example if and when I need it.
But, you answer does help, however.
Thank you.


___

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: CGFloat and literal floats in Swift

2015-07-26 Thread Quincey Morris
On Jul 26, 2015, at 16:38 , Rick Mann  wrote:
> 
> So, is a literal 0.0 not of type Double?

No, it’s a numeric literal, so it has no numeric type. However your ‘addArc’ 
function requires CGFloat parameters. Literal 0.0 is convertible to CGFloat, 
but Double M_PI isn’t convertible automatically.

> And can CGFloat be made to be implicitly assignable from Double?

No. Swift doesn’t convert between numeric types automatically, so Double —> 
CGFloat produces an error. However, many types satisfy a ‘…LiteralConvertible’ 
protocol, which allows the compiler to treat a compile-time literal such as 0 
(which is ambiguous as to Swift type) to the type expected in a given context.



___

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: CGFloat and literal floats in Swift

2015-07-26 Thread Rick Mann


> On Jul 26, 2015, at 16:50 , Quincey Morris 
>  wrote:
> 
> On Jul 26, 2015, at 16:38 , Rick Mann  wrote:
>> 
>> So, is a literal 0.0 not of type Double?
> 
> No, it’s a numeric literal, so it has no numeric type. However your ‘addArc’ 
> function requires CGFloat parameters. Literal 0.0 is convertible to CGFloat, 
> but Double M_PI isn’t convertible automatically.
> 
>> And can CGFloat be made to be implicitly assignable from Double?
> 
> No. Swift doesn’t convert between numeric types automatically, so Double —> 
> CGFloat produces an error. However, many types satisfy a 
> ‘…LiteralConvertible’ protocol, which allows the compiler to treat a 
> compile-time literal such as 0 (which is ambiguous as to Swift type) to the 
> type expected in a given context.

So, why can I do this?

let n : NSNumber = M_PI




-- 
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: CGFloat and literal floats in Swift

2015-07-26 Thread Quincey Morris
On Jul 26, 2015, at 17:42 , Rick Mann  wrote:
> 
> So, why can I do this?
> 
> let n : NSNumber = M_PI

That’s bridged, not converted. :)

The Swift compiler has built-in knowledge of what can be bridged, and does a 
typecast or value conversion according to context.

___

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: NSPropertyListSerialization weirdness

2015-07-26 Thread Gary L. Wade
When the file arrives, verify that the contents of it have also arrived. It's 
possible you may just be processing that a file was created but nothing yet has 
been put into it.
--
Gary L. Wade (Sent from my iPad)
http://www.garywade.com/

> On Jul 26, 2015, at 2:28 PM, Robert Martin  wrote:
> 
> I’m having some issues. I’m tracking a folder that is I watch via kqueue, and 
> if a .plist arrives, I process it immediately. The plist contains a 
> dictionary, which is successfully read with dictionaryWithContentsOfFile:. If 
> I log the dictionary description, it is accurate. The dictionary only 
> contains strings, arrays of string, NSNumbers, or NSDates.
> 
> Though I can guarantee that the plist is well formed when it’s sent, if I try 
> to serialize it with:
> 
> NSData* plist = [NSPropertyListSerialization 
> dataWithPropertyList:updateDictionary];
> 
> I get a null, and an error (200) that the plist contains null.
> 
> Before I make that call, I put in a check for nulls, but none are found:
> 
>[updateDictionary enumerateKeysAndObjectsUsingBlock:^(id key, id obj, BOOL 
> *stop) {
>
>if( obj == nil ){
>*stop = YES;
>NSLog( @"nil obj for key: %@", key );
>}
>
>*stop =  NO;
>}];
> 
> I cannot understand how a dictionary which contains no nulls and only valid 
> classes can generate the NSPropertyListSerialization error. Any ideas?
> 
> Rob

___

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: CGFloat and literal floats in Swift

2015-07-26 Thread Jens Alfke

> On Jul 26, 2015, at 4:50 PM, Quincey Morris 
>  wrote:
> 
> No. Swift doesn’t convert between numeric types automatically, so Double —> 
> CGFloat produces an error.

I’m guessing this is only a problem when building 32-bit? Because in 64-bit, 
CGFloat is equivalent to Double, so there shouldn’t be a problem there.

Rick: You could just define your own CGFloat constant equal to M_PI. (You could 
even name it π …!)

—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: CGFloat and literal floats in Swift

2015-07-26 Thread Rick Mann

> On Jul 26, 2015, at 20:57 , Jens Alfke  wrote:
> 
> 
>> On Jul 26, 2015, at 4:50 PM, Quincey Morris 
>>  wrote:
>> 
>> No. Swift doesn’t convert between numeric types automatically, so Double —> 
>> CGFloat produces an error.
> 
> I’m guessing this is only a problem when building 32-bit? Because in 64-bit, 
> CGFloat is equivalent to Double, so there shouldn’t be a problem there.

I don't think this is a 32- vs 64-bit issue. For example, both of these fail:

let f : CGFloat = Float(1.0)
let g : CGFloat = Double(1.0)

> Rick: You could just define your own CGFloat constant equal to M_PI. (You 
> could even name it π …!)

I guess, but that's not really the problem. I think it would not be unusual for 
code in one place to produce Double (or other arithmetic type) values that you 
then want to pass to CG. But you have to explicitly convert them. Seems very 
clunky to me. I prefer C's approach where a conversion that doesn't lose data 
is allowed, and you can turn on warnings for ones that might lose data.

> 
> —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/rmann%40latencyzero.com
> 
> This email sent to rm...@latencyzero.com


-- 
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: CGFloat and literal floats in Swift

2015-07-26 Thread Tim Fletcher
Slightly off topic; I would love to see some form of what Scala calls
implicits in swift. For exactly this reason.

On Mon, 27 Jul 2015 05:10 Rick Mann  wrote:

>
> > On Jul 26, 2015, at 20:57 , Jens Alfke  wrote:
> >
> >
> >> On Jul 26, 2015, at 4:50 PM, Quincey Morris <
> quinceymor...@rivergatesoftware.com> wrote:
> >>
> >> No. Swift doesn’t convert between numeric types automatically, so
> Double —> CGFloat produces an error.
> >
> > I’m guessing this is only a problem when building 32-bit? Because in
> 64-bit, CGFloat is equivalent to Double, so there shouldn’t be a problem
> there.
>
> I don't think this is a 32- vs 64-bit issue. For example, both of these
> fail:
>
> let f : CGFloat = Float(1.0)
> let g : CGFloat = Double(1.0)
>
> > Rick: You could just define your own CGFloat constant equal to M_PI.
> (You could even name it π …!)
>
> I guess, but that's not really the problem. I think it would not be
> unusual for code in one place to produce Double (or other arithmetic type)
> values that you then want to pass to CG. But you have to explicitly convert
> them. Seems very clunky to me. I prefer C's approach where a conversion
> that doesn't lose data is allowed, and you can turn on warnings for ones
> that might lose data.
>
> >
> > —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/rmann%40latencyzero.com
> >
> > This email sent to rm...@latencyzero.com
>
>
> --
> 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/timothy.m.fletcher%40gmail.com
>
> This email sent to timothy.m.fletc...@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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

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