Re: Unable to connect IBOutlet in Swift Xcode 7b2

2015-07-07 Thread Kyle Sluder
On Mon, Jul 6, 2015, at 07:57 PM, Rick Mann wrote:
 
  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).

Is the Module correct?

--Kyle Sluder

___

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

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

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

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

Possible to defer initialization of let variable?

2015-07-07 Thread Rick Mann
I thought I saw some Swift code that did this:

let someString : String?

if some things
{
// some stuff

someString = a string from something

// some other stuff
}

//  use someString

But I can't get Swift 2 to let me.

Basically, I want to make someString available outside the scope in which it's 
initialized, but I don't want its assignment to ever change after that. I could 
do the former with var instead of let, of course, but I'd like it to be treated 
as a let after the first assignment. Is that possible?

-- 
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: Possible to defer initialization of let variable?

2015-07-07 Thread Quincey Morris
On Jul 7, 2015, at 01:08 , Rick Mann rm...@latencyzero.com wrote:
 
 But I can't get Swift 2 to let me.

You’ve left a path through the code that doesn’t set ‘someString’. So, you’ll 
need to add:

 else
 {
   someString = nil
 }

to the ‘if’.

___

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: cannot invoke 'substringToIndex' with an argument list of type '(Int)'

2015-07-07 Thread Roland King
The docs for NSString say that substringToIndex is declared like that. If you 
looked at the autocomplete when you typed it in you’d see it wants an Index, 
that’s a method on String. And no it’s not in the documentation but it is in 
the API diffs and autocomplete gets it right (for me at least) and Cmd Clicking 
takes me there too. 

If you want to use an NSString method with the same name as a String one, cast 
to an NSString, ( s as NSString )

same with substringFromIndex

and NSURL is a fallible initializer so you can’t return it like that, you 
unwrap it, or throw, or test it or something. 

Your last mail about NSURLs didn’t make any sense either by the way. You were 
using .rawValue() on things typed as Strings, Strings don’t have raw values, so 
I think that isn’t really your code. 


 On 7 Jul 2015, at 15:02, Rick Mann rm...@latencyzero.com wrote:
 
 What? The docs say that substringToIndex is declared like this:
 
   func substringToIndex(_ to: Int) - String
 
 So, why can't I call that here:
 
 extension
 NSURL
 {
   func
   normalizedURLByAppendingPathComponent(var inComponent : String)
   - NSURL
   {
   var s = self.absoluteString;
   if s.hasSuffix(/)
   {
   s = s.substringToIndex(s.characters.count - 1)
   }
 
   if inComponent.hasPrefix(/)
   {
   inComponent = inComponent.substringFromIndex(1);
   }
 
   s = s.stringByAppendingString(/);
   s = s.stringByAppendingString(inComponent);
 
   let u = NSURL(string: s);
   return u;
   }
 }
 
 
 -- 
 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/rols%40rols.org
 
 This email sent to r...@rols.org


___

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

Swift enums with raw values

2015-07-07 Thread Rick Mann
I want to implement some support for HTTP Headers in enums, such that I can 
write this:

extension
NSMutableURLRequest
{
func
set(inHeader : String, _ inVal : String)
{
self.setValue(inVal.rawValue, forHTTPHeaderField: 
inHeader.rawValue())
}
}

and then call it like this:

req.set(.ContentType, .JSON)
req.set(.ContentType, some other type)

where

enum
HTTPHeader : String
{
case Accept =   Accept
case ContentDisposition =   Content-Disposition
case ContentLength  =   Content-Length
case ContentType=   Content-Type
case Authorization  =   Authorization
case Date   =   Date
case IfModifiedSince=   If-Modified-Since
case UserAgent  =   User-Agent


enum
HTTPContentType : String
{
case JSON   =   application/json
case JSONUTF8   =   application/json; 
charset=UTF-8
case OctetStream=   application/octet-stream
}

That is, I'd like to not have to explicitly call .rawValue() every time I use 
one of the enum cases, and I'd like the Header field name to be one enum, and 
the value to be any of a number of different enums. Finally, I'd like to be 
able to call set() with one or both parameters of type String, but I think I 
can accomplish that with overloading.

Unfortunately, I can't figure out how to make a set of enum types I define 
conform to a single type (protocol, class, or abstract enum) such that Swift 
doesn't complain.

Any suggestions? Thanks.

-- 
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: Possible to defer initialization of let variable?

2015-07-07 Thread Rick Mann

 On Jul 7, 2015, at 01:16 , Quincey Morris 
 quinceymor...@rivergatesoftware.com wrote:
 
 On Jul 7, 2015, at 01:08 , Rick Mann rm...@latencyzero.com wrote:
 
 But I can't get Swift 2 to let me.
 
 You’ve left a path through the code that doesn’t set ‘someString’. So, you’ll 
 need to add:
 
 else
 {
  someString = nil
 }
 
 to the ‘if’.

Well, I wanted to do this:

//  Get the hero thumbnail…

let thumbURL: String?
for imgD in images
{
if let isHero = imgD[is_hero] as? Bool where isHero,
let t = imgD[thumbnail_signed_src] as? String
{
thumbURL = t
break
}
}

print(Thumb: \(thumbURL))

But it complains that it's used before being initialized. I guess I want it to 
initialize it to nil, then let me assign it once, then keep it constant.

-- 
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: Possible to defer initialization of let variable?

2015-07-07 Thread Rick Mann

 On Jul 7, 2015, at 01:37 , Quincey Morris 
 quinceymor...@rivergatesoftware.com wrote:
 
 On Jul 7, 2015, at 01:33 , Rick Mann rm...@latencyzero.com wrote:
 
 Yeah, there doesn't seem to be an elegant way to do it
 
 Actually, there is:
 
 let thumbURL: String? =
 {
  for imgD in images
  {
  if let isHero = imgD[is_hero] as? Bool where isHero,
  let t = imgD[thumbnail_signed_src] as? String
  {
  return t
  }
  }
  
  return nil
 } ()
 
 Or, if you prefer, instead of using a closure, you can define a nested 
 function and call it to get the initial value.

I tried it as a closure. The problem arises when you want to initialize more 
than one variable in that block of work.

-- 
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: Possible to defer initialization of let variable?

2015-07-07 Thread Rick Mann

 On Jul 7, 2015, at 01:49 , Quincey Morris 
 quinceymor...@rivergatesoftware.com wrote:
 
 On Jul 7, 2015, at 01:39 , Rick Mann rm...@latencyzero.com wrote:
 
 The problem arises when you want to initialize more than one variable in 
 that block of work.
 
 If you ask the wrong question, you get a wrong answer. :)

Whether or not it was the wrong question is debatable.

 You can use a tuple:

Unfortunately, that requires you to have the values all ready at once. Thanks 
for trying, but I think there's no good way to do this. Best is to just deal 
with var. Or do the hacky thing you suggested earlier, with local vars that get 
assigned at the very end to their lets.

-- 
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: Possible to defer initialization of let variable?

2015-07-07 Thread Quincey Morris
On Jul 7, 2015, at 01:39 , Rick Mann rm...@latencyzero.com wrote:
 
 The problem arises when you want to initialize more than one variable in that 
 block of work.

If you ask the wrong question, you get a wrong answer. :)

You can use a tuple:

 let (thumbURL, isHero) =
 {
   () - (String?, Bool) in
   
   for imgD in images
   {
   if let isHero = imgD[is_hero] as? Bool where isHero,
   let t = imgD[thumbnail_signed_src] as? String
   {
   return (t, isHero)
   }
   }
   
   return (nil, false)
 } ()

___

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-07 Thread Rick Mann

 On Jul 6, 2015, at 23:22 , Kyle Sluder k...@ksluder.com wrote:
 
 On Mon, Jul 6, 2015, at 07:57 PM, Rick Mann wrote:
 
 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).
 
 Is the Module correct?

It's in the same source file as the other view that it does connect to; both 
module fields are blank in IB


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

cannot invoke 'substringToIndex' with an argument list of type '(Int)'

2015-07-07 Thread Rick Mann
What? The docs say that substringToIndex is declared like this:

func substringToIndex(_ to: Int) - String

So, why can't I call that here:

extension
NSURL
{
   func
   normalizedURLByAppendingPathComponent(var inComponent : String)
   - NSURL
   {
   var s = self.absoluteString;
   if s.hasSuffix(/)
   {
   s = s.substringToIndex(s.characters.count - 1)
   }

   if inComponent.hasPrefix(/)
   {
   inComponent = inComponent.substringFromIndex(1);
   }

   s = s.stringByAppendingString(/);
   s = s.stringByAppendingString(inComponent);

   let u = NSURL(string: s);
   return u;
   }
}


-- 
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: cannot invoke 'substringToIndex' with an argument list of type '(Int)'

2015-07-07 Thread Stephen J. Butler
You should file a documentation bug. The signature is actually:

func substringFromIndex(index: String.Index) - String

So what you really want I believe is:

s = s.substringToIndex(advance(s.endIndex, -1))


On Tue, Jul 7, 2015 at 2:02 AM, Rick Mann rm...@latencyzero.com wrote:

 What? The docs say that substringToIndex is declared like this:

 func substringToIndex(_ to: Int) - String

 So, why can't I call that here:

 extension
 NSURL
 {
func
normalizedURLByAppendingPathComponent(var inComponent : String)
- NSURL
{
var s = self.absoluteString;
if s.hasSuffix(/)
{
s = s.substringToIndex(s.characters.count - 1)
}

if inComponent.hasPrefix(/)
{
inComponent = inComponent.substringFromIndex(1);
}

s = s.stringByAppendingString(/);
s = s.stringByAppendingString(inComponent);

let u = NSURL(string: s);
return u;
}
 }


 --
 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/stephen.butler%40gmail.com

 This email sent to stephen.but...@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: cannot invoke 'substringToIndex' with an argument list of type '(Int)'

2015-07-07 Thread Quincey Morris
On Jul 7, 2015, at 00:22 , Roland King r...@rols.org wrote:
 
 If you want to use an NSString method with the same name as a String one, 
 cast to an NSString, ( s as NSString )

The other thing to be really, really careful of when bridging is that all 
indexes and ranges derived from NSString API are counting by UTF-16 code 
units**, as they’ve always done. Indexes and ranges derived from String API are 
counting by graphemes.


** At least, that was the situation in Swift 1.2. I haven’t looked into what’s 
changed with NSString bridging in Swift 2, but I suspect caution is still 
advisable.



___

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: cannot invoke 'substringToIndex' with an argument list of type '(Int)'

2015-07-07 Thread Roland King
The bug is really that they haven’t documented the new String method so you 
only get the old (and still-existing) NSString method. 

I did find it in some documentation which pointed to online documentation (you 
can tell by the lag) so I went to prefs, updated my docsets, and now I don’t 
have it any more, which is rather par for the course and generally sad. 

new Xcode tomorrow (?), perhaps we’ll get a docs update. 

 On 7 Jul 2015, at 15:25, Stephen J. Butler stephen.but...@gmail.com wrote:
 
 You should file a documentation bug. The signature is actually:
 
 func substringFromIndex(index: String.Index) - String
 
 So what you really want I believe is:
 
 s = s.substringToIndex(advance(s.endIndex, -1))
 
 
 On Tue, Jul 7, 2015 at 2:02 AM, Rick Mann rm...@latencyzero.com wrote:
 
 What? The docs say that substringToIndex is declared like this:
 
func substringToIndex(_ to: Int) - String
 
 So, why can't I call that here:
 
 extension
 NSURL
 {
   func
   normalizedURLByAppendingPathComponent(var inComponent : String)
   - NSURL
   {
   var s = self.absoluteString;
   if s.hasSuffix(/)
   {
   s = s.substringToIndex(s.characters.count - 1)
   }
 
   if inComponent.hasPrefix(/)
   {
   inComponent = inComponent.substringFromIndex(1);
   }
 
   s = s.stringByAppendingString(/);
   s = s.stringByAppendingString(inComponent);
 
   let u = NSURL(string: s);
   return u;
   }
 }
 
 
 --
 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/stephen.butler%40gmail.com
 
 This email sent to stephen.but...@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/rols%40rols.org
 
 This email sent to r...@rols.org


___

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: Possible to defer initialization of let variable?

2015-07-07 Thread Rick Mann
Yeah, there doesn't seem to be an elegant way to do it, so I gave up and used a 
var.

 On Jul 7, 2015, at 01:31 , Quincey Morris 
 quinceymor...@rivergatesoftware.com wrote:
 
 On Jul 7, 2015, at 01:21 , Rick Mann rm...@latencyzero.com wrote:
 
  let thumbURL: String?
  for imgD in images
  {
  if let isHero = imgD[is_hero] as? Bool where isHero,
  let t = imgD[thumbnail_signed_src] as? String
  {
  thumbURL = t
  break
  }
  }
 
 You’ve still got a path where ‘thumbURL’ is uninitialized — when ‘images’ is 
 empty. I’m not sure if there’s an elegant way to do it, but you can do it by 
 brute force something like this:
 
 do
 {
  var url: String? = nil
 
  for imgD in images
  {
  if let isHero = imgD[is_hero] as? Bool where isHero,
  let t = imgD[thumbnail_signed_src] as? String
  {
  url = t
  break
  }
  }
  
  thumbURL = url
 }


-- 
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: Possible to defer initialization of let variable?

2015-07-07 Thread Quincey Morris
On Jul 7, 2015, at 01:33 , Rick Mann rm...@latencyzero.com wrote:
 
 Yeah, there doesn't seem to be an elegant way to do it

Actually, there is:

 let thumbURL: String? =
 {
   for imgD in images
   {
   if let isHero = imgD[is_hero] as? Bool where isHero,
   let t = imgD[thumbnail_signed_src] as? String
   {
   return t
   }
   }
   
   return nil
 } ()

Or, if you prefer, instead of using a closure, you can define a nested function 
and call it to get the initial value.
___

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 with raw values

2015-07-07 Thread Quincey Morris
On Jul 7, 2015, at 00:02 , Rick Mann rm...@latencyzero.com wrote:
 
 I want to implement some support for HTTP Headers in enums, such that I can 
 write this:
 
 extension
 NSMutableURLRequest
 {
   func
   set(inHeader : String, _ inVal : String)
   {
   self.setValue(inVal.rawValue, forHTTPHeaderField: 
 inHeader.rawValue())
   }
 }
 
 and then call it like this:
 
   req.set(.ContentType, .JSON)
   req.set(.ContentType, some other type)
 

Like this:

 extension NSMutableURLRequest
 {
   func setT, U where T: RawRepresentable, T.RawValue == String, U: 
 RawRepresentable, U.RawValue == String (inHeader : T, _ inVal : U)
   {
   self.setValue (inVal.rawValue, forHTTPHeaderField: 
 inHeader.rawValue)
   }
   
 }

At least, that compiles in a playground. As you say, overloading should work 
for pure String values of the second parameter.



___

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: Possible to defer initialization of let variable?

2015-07-07 Thread Quincey Morris
On Jul 7, 2015, at 01:21 , Rick Mann rm...@latencyzero.com wrote:
 
   let thumbURL: String?
   for imgD in images
   {
   if let isHero = imgD[is_hero] as? Bool where isHero,
   let t = imgD[thumbnail_signed_src] as? String
   {
   thumbURL = t
   break
   }
   }

You’ve still got a path where ‘thumbURL’ is uninitialized — when ‘images’ is 
empty. I’m not sure if there’s an elegant way to do it, but you can do it by 
brute force something like this:

 do
 {
   var url: String? = nil
 
   for imgD in images
   {
   if let isHero = imgD[is_hero] as? Bool where isHero,
   let t = imgD[thumbnail_signed_src] as? String
   {
   url = t
   break
   }
   }
   
   thumbURL = url
 }


___

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: cannot invoke 'substringToIndex' with an argument list of type '(Int)'

2015-07-07 Thread Charles Srstka
On Jul 7, 2015, at 2:47 AM, Rick Mann rm...@latencyzero.com wrote:
 
 
 On Jul 7, 2015, at 00:46 , Charles Srstka cocoa...@charlessoft.com wrote:
 
 You don’t have an NSString. You have a String. It works differently.
 
 Well, they're toll-free bridged, and substringToIndex() is a method on 
 NSString (or so I thought). Anyway, it turns out to be an error in the 
 documentation, so now I understand.

They are *not* toll-free bridged. When you cast one to the other, it actually 
does a conversion.

The documentation is not incorrect; the method on NSString *does* take an Int. 
If you try it on strings that are actually typed as NSString, you’ll see that 
they take an Int:

import Foundation

let str = foobar as NSString
let str2 = str.substringFromIndex(3)

This results in str2 being “bar”. Swift Strings, however, follow different 
rules, in order to be safe about cases where a character in a string takes up 
more than one UTF-16 code unit.

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-07 Thread Richard Charles

 On Jul 7, 2015, at 8:27 AM, Willeke willeke2...@gmail.com wrote:
 
 Op 6 jul. 2015, om 18:15 heeft Richard Charles rcharles...@gmail.com het 
 volgende geschreven:
 
 Does anyone have any insight into what is going on?
 
 The animation of the focus ring isn't finished. If the focus ring is switched 
 off, the text is selected.
 
 Safari's Address and Search field calls setSelectedRange: of currentEditor in 
 mouseDown:
 
 - Willeke

Yes Safari’s Address and Search field has the behavior that I am looking for. 
First click selects the entire text field and you also get an animated focus 
ring.

Exactly how to achieve that on OS X 10.10 (with or without a focus ring) is 
another matter. I have parred back my custom NSTextField subclass to just what 
is shown below. A custom NSNumberFormatter is used but I removed it. The only 
other thing going on is the text field is programmatically placed in the super 
view.



Your initial suggestion.

@implementation MyTextField

- (instancetype)initWithFrame:(NSRect)frame
{
self = [super initWithFrame:frame];
if (self) {
[self.cell setFocusRingType:NSFocusRingTypeNone];
}
return self;
}

- (void)awakeFromNib
{
[self.cell setFocusRingType:NSFocusRingTypeNone];
}

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

@end

RESULTS: Text is selected but rapidly changes to no selection. No focus ring as 
expected. Intermittent error Bad cursor rect event, flags = 256.



You say that Safari apparently does this.

@implementation MyTextField

- (void)mouseDown:(NSEvent *)event
{
NSText *editor = self.currentEditor;
assert(editor  Current editor is nil!);
assert(editor.isFieldEditor  Editor not a field editor!);
NSRange range = NSMakeRange(0, editor.string.length);
[editor setSelectedRange:range];

[super mouseDown:event];
}

@end

RESULTS: Text not selected. Focus ring normal. No error message.



Another version of what Safari may do.

@implementation MyTextField

- (void)mouseDown:(NSEvent *)event
{
[self selectText:self];

[super mouseDown:event];
}

@end

RESULTS: Text is selected but rapidly changes to no selection. Focus ring is 
intermittent. No error message.



So in summary Safari’s Address and Search field has the behavior that I am 
looking for. First click selects the entire text field and you also get an 
animated focus ring. However on OS X 10.10 Yosemite nothing works for me except 
performSelector:withObject:afterDelay: using a non-zero delay value.

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

Sizing NSScrollView width to exactly fit NSTableView

2015-07-07 Thread Matthew LeRoy
Hi,

I’m trying to figure out how to correctly calculate the required width of an 
NSScrollView such that it will exactly fit the NSTableView inside, with no 
horizontal scroller and no “filler column” to the right of the last column in 
the table.

The number of columns in the table changes based on the selection in an 
NSPopUpButton elsewhere on the screen. The columns are all the same width and 
are not resizable. When a new selection is made in the popup button, I want to 
reset the table with however many columns correspond to that selection, and 
then resize the scroll view’s width to exactly fit those columns. Both the 
height of the scroll view and the number of rows in the table are fixed, and 
there are more rows than will fit in the scroll view’s height so there will 
always be vertical scrolling — either legacy or overlay style depending on the 
user’s preference — so I need to account for the width of the vertical scroller 
when calculating the required width of the scroll view, if using a legacy 
scroller.

From reading the docs, I gather that [NSScrollView 
frameSizeForContentSize:horizontalScrollerClass:verticalScrollerClass:borderType:controlSize:scrollerStyle]
 can be used to calculate the required frame size for the scroll view — but I 
don’t know how to calculate the required size of the table view to pass as the 
first argument (contentSize). I tried simply summing the column widths and 
using a dummy value for the height (since the height of the scroll view is 
fixed anyway), but that didn’t quite work (as I expected it wouldn’t) — the 
returned size wasn’t wide enough.

Any pointers?

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

Re: Any way to combine for and if-let?

2015-07-07 Thread Quincey Morris
On Jul 7, 2015, at 16:42 , Rick Mann rm...@latencyzero.com wrote:
 
 for item in enumerator!


Like this:

 for case let item? in enumerator!


(Yes, it’s stupid.)



___

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

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

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

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

Re: Any way to combine for and if-let?

2015-07-07 Thread Rick Mann

 On Jul 7, 2015, at 16:52 , Quincey Morris 
 quinceymor...@rivergatesoftware.com wrote:
 
 On Jul 7, 2015, at 16:42 , Rick Mann rm...@latencyzero.com wrote:
 
 for item in enumerator!
 
 Like this:
 
 for case let item? in enumerator!
 
 (Yes, it’s stupid.)

Hmm. It doesn't seem to like that: '?' pattern cannot match values of type 
'Element'. It puts the carat on the '?' of item.

Also, the enumerator is a NSDirectoryEnumerator. It returns AnyObject type, so 
wouldn't there have to be an NSURL cast in there somewhere?




-- 
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: Any way to combine for and if-let?

2015-07-07 Thread Rick Mann
Thanks. I was looking at the Swift reference. The docs seem to be incorrect:

https://developer.apple.com/library/prerelease/ios/documentation/Swift/Conceptual/Swift_Programming_Language/Patterns.html#//apple_ref/swift/grammar/pattern

There are two type-casting patterns, the is pattern and the as pattern. Both 
type-casting patterns appear only in switch statement case labels.

 On Jul 7, 2015, at 17:26 , Quincey Morris 
 quinceymor...@rivergatesoftware.com wrote:
 
 On Jul 7, 2015, at 16:58 , Rick Mann rm...@latencyzero.com wrote:
 
 Also, the enumerator is a NSDirectoryEnumerator. It returns AnyObject type, 
 so wouldn't there have to be an NSURL cast in there somewhere?
 
 Try:
 
 for case let url as NSURL in enumerator
 
 The way to figure these things out is to start with a switch statement, where 
 the patterns are a bit more intuitive, or at least better documented:
 
 switch anyObject {
 case let url as NSURL:
 …
 }
 
 and the case is what you drop into the “for … in enumerator” statement.
 


-- 
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: Any way to combine for and if-let?

2015-07-07 Thread Greg Parker

 On Jul 7, 2015, at 4:58 PM, Rick Mann rm...@latencyzero.com wrote:
 
 On Jul 7, 2015, at 16:52 , Quincey Morris 
 quinceymor...@rivergatesoftware.com wrote:
 
 On Jul 7, 2015, at 16:42 , Rick Mann rm...@latencyzero.com wrote:
 
 for item in enumerator!
 
 Like this:
 
 for case let item? in enumerator!
 
 (Yes, it’s stupid.)
 
 Hmm. It doesn't seem to like that: '?' pattern cannot match values of type 
 'Element'. It puts the carat on the '?' of item.
 
 Also, the enumerator is a NSDirectoryEnumerator. It returns AnyObject type, 
 so wouldn't there have to be an NSURL cast in there somewhere?

`for case` uses Swift's pattern matching system, as seen in `switch`. Something 
like this should work:

for case let item as NSURL in enumerator! {
…
}


-- 
Greg Parker gpar...@apple.com Runtime Wrangler



___

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

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

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

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

Re: Any way to combine for and if-let?

2015-07-07 Thread Roland King

 On 8 Jul 2015, at 08:26, Quincey Morris quinceymor...@rivergatesoftware.com 
 wrote:
 
 On Jul 7, 2015, at 16:58 , Rick Mann rm...@latencyzero.com wrote:
 
 Also, the enumerator is a NSDirectoryEnumerator. It returns AnyObject type, 
 so wouldn't there have to be an NSURL cast in there somewhere?
 
 
 Try:
 
 for case let url as NSURL in enumerator
 

Two obersvations

1) If you’re sure it’s not nil, which for that particular case of an enumerator 
from a filemanager I’d agree it’s not (can’t make one work in a playground to 
test) then just force-unwrap it
2) As concise as ‘for case let url as NSURL in eumerator’ is, I think the 
original code was somewhat clearer for the next guy maintaining 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

Any way to combine for and if-let?

2015-07-07 Thread Rick Mann
Is there any way to combine the for and if-let into one line that gives me 
unwrapped NSURL objects to work on? I believe the enumerator (which came from 
NSFileManager) will only have valid NSURLs in it.

for item in enumerator!
{
if let url = item as? NSURL
{
let sid = url.lastPathComponent!
print(Found: \(sid), \(url.path))
processModel(url)
}
}


-- 
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: Any way to combine for and if-let?

2015-07-07 Thread Quincey Morris
On Jul 7, 2015, at 16:58 , Rick Mann rm...@latencyzero.com wrote:
 
 Also, the enumerator is a NSDirectoryEnumerator. It returns AnyObject type, 
 so wouldn't there have to be an NSURL cast in there somewhere?


Try:

 for case let url as NSURL in enumerator

The way to figure these things out is to start with a switch statement, where 
the patterns are a bit more intuitive, or at least better documented:

 switch anyObject {
 case let url as NSURL:
 …
 }

and the case is what you drop into the “for … in enumerator” statement.



___

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

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

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

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

Re: Any way to combine for and if-let?

2015-07-07 Thread Quincey Morris
On Jul 7, 2015, at 17:28 , Greg Parker gpar...@apple.com wrote:
 
 for case let item as NSURL in

Yes, but you can’t honestly tell me you’re proud of that syntax, can 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

How to get Unicode's General Category of a character?

2015-07-07 Thread Gerriet M. Denkmann
Given a character (a Unicode code point, to be exact) like U+FF0B (FULLWIDTH 
PLUS SIGN), I want to know the General Category of this.
For this example it would be “Sm (aka. Math_Symbol or Symbol, Math).

I could download the current version of UnicodeData.txt and parse it.
But this looks not very efficient.

For punctuation one could use NSCharacterSet punctuationCharacterSet.

But for Math Symbols?

I did look at CFStringTransform, which can give the Character name via 
kCFStringTransformToUnicodeName.

But I cannot find anything for “General Category

NSRegularExpression can match for [\p{General_Category = Math_Symbol}]; not 
quite what I want, but better than nothing.


Any ideas?

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 get Unicode's General Category of a character?

2015-07-07 Thread Dmitry Markman
ICU’s

u_charType

and after that you can use

// http://www.fileformat.info/info/unicode/category/index.htm
std::tuplestd::string, std::string u_charTypeName(UCharCategory c) {
switch (c) {
/*case U_UNASSIGNED:*/
case U_GENERAL_OTHER_TYPES:
return std::make_tuple(Cn,Other, Not Assigned (no characters in 
the file have this property) );
case U_UPPERCASE_LETTER:
return std::make_tuple(Lu,Letter, Uppercase);
case U_LOWERCASE_LETTER:
return std::make_tuple(Ll,Letter, Lowercase);
case U_TITLECASE_LETTER:
return std::make_tuple(Lt,Letter, Titlecase);
case U_MODIFIER_LETTER:
return std::make_tuple(Lm,Letter, Modifier);
case U_OTHER_LETTER:
return std::make_tuple(Lo,Letter, Other);
case U_NON_SPACING_MARK:
return std::make_tuple(Mn,Mark, Nonspacing);
case U_ENCLOSING_MARK:
return std::make_tuple(Me,Mark, Enclosing);
case U_COMBINING_SPACING_MARK:
return std::make_tuple(Mc,Mark, Spacing Combining);
case U_DECIMAL_DIGIT_NUMBER:
return std::make_tuple(Nd,Number, Decimal Digit);
case U_LETTER_NUMBER:
return std::make_tuple(Nl,Number, Letter);
case U_OTHER_NUMBER:
return std::make_tuple(No,Number, Other);
case U_SPACE_SEPARATOR:
return std::make_tuple(Zs,Separator, Space);
case U_LINE_SEPARATOR:
return std::make_tuple(Zl,Separator, Line);
case U_PARAGRAPH_SEPARATOR:
return std::make_tuple(Zp,Separator, Paragraph);
case U_CONTROL_CHAR:
return std::make_tuple(Cc,Other, Control);
case U_FORMAT_CHAR:
return std::make_tuple(Cf,Other, Format);
case U_PRIVATE_USE_CHAR:
return std::make_tuple(Co,Other, Private Use);
case U_SURROGATE:
return std::make_tuple(Cs,Other, Surrogate);
case U_DASH_PUNCTUATION:
return std::make_tuple(Pd,Punctuation, Dash);
case U_START_PUNCTUATION:
return std::make_tuple(Ps,Punctuation, Open);
case U_END_PUNCTUATION:
return std::make_tuple(Pe,Punctuation, Close);
case U_CONNECTOR_PUNCTUATION:
return std::make_tuple(Pc,Punctuation, Connector);
case U_OTHER_PUNCTUATION:
return std::make_tuple(Po,Punctuation, Other);
case U_MATH_SYMBOL:
return std::make_tuple(Sm,Symbol, Math);
case U_CURRENCY_SYMBOL:
return std::make_tuple(Sc,Symbol, Currency);
case U_MODIFIER_SYMBOL:
return std::make_tuple(Sk,Symbol, Modifier);
case U_OTHER_SYMBOL:
return std::make_tuple(So,Symbol, Other);
case U_INITIAL_PUNCTUATION:
return std::make_tuple(Pi,Punctuation, Initial quote (may behave 
like Ps or Pe depending on usage));
case U_FINAL_PUNCTUATION:
return std::make_tuple(Pf,Punctuation, Final quote (may behave 
like Ps or Pe depending on usage));
default:
return std::make_tuple(,);
}
}




 On Jul 7, 2015, at 8:03 AM, Gerriet M. Denkmann gerr...@mdenkmann.de wrote:
 
 Given a character (a Unicode code point, to be exact) like U+FF0B (FULLWIDTH 
 PLUS SIGN), I want to know the General Category of this.
 For this example it would be “Sm (aka. Math_Symbol or Symbol, Math).
 
 I could download the current version of UnicodeData.txt and parse it.
 But this looks not very efficient.
 
 For punctuation one could use NSCharacterSet punctuationCharacterSet.
 
 But for Math Symbols?
 
 I did look at CFStringTransform, which can give the Character name via 
 kCFStringTransformToUnicodeName.
 
 But I cannot find anything for “General Category
 
 NSRegularExpression can match for [\p{General_Category = Math_Symbol}]; not 
 quite what I want, but better than nothing.
 
 
 Any ideas?
 
 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/dmarkman%40mac.com
 
 This email sent to dmark...@mac.com

Dmitry Markman


___

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-07 Thread Rick Aurbach
Ah, I see what you’re getting at. This is interesting.

Previously when I’ve wanted to implement things like this I’ve used 
Transformable attributes, which provide an automatic packing/unpacking feature 
using a packing/unpacking class that I specify in the data model. It is 
necessary to be careful how one handles making sure the object is marked dirty 
appropriately, but that’s not too hard.

In my case, I’m thinking of using this approach to map a data BLOB (stored as 
an NSDate object in CD) to a mutable dictionary. The dictionary keys would 
depend on which enumeration value is associated with the event.

Cheers,

Rick

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

On Jul 6, 2015, at 16:21 , Rick Aurbach 
r...@aurbach.commailto: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

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

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: Any way to combine for and if-let?

2015-07-07 Thread Rick Mann

 On Jul 7, 2015, at 17:30 , Roland King r...@rols.org wrote:
 
 1) If you’re sure it’s not nil, which for that particular case of an 
 enumerator from a filemanager I’d agree it’s not (can’t make one work in a 
 playground to test) then just force-unwrap it
 2) As concise as ‘for case let url as NSURL in eumerator’ is, I think the 
 original code was somewhat clearer for the next guy maintaining it

I couldn't figure out how to force-unwrap it in the for statement. If I can't 
do it there, I have to introduce another variable, which is just smelly. E.g.:

for item in enumerator!
{
let unwrappedItem = item as! NSURL
}

(or something like that)

-- 
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: Any way to combine for and if-let?

2015-07-07 Thread Rick Mann

 On Jul 7, 2015, at 17:51 , Greg Parker gpar...@apple.com wrote:
 
 The power of `case` outside `switch` was increased at some point. It's likely 
 that the documentation has not caught up. You should file a bug report.

I did. Thanks for the confirmation, though!

-- 
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: Any way to combine for and if-let?

2015-07-07 Thread Greg Parker

 On Jul 7, 2015, at 5:30 PM, Rick Mann rm...@latencyzero.com wrote:
 
 Thanks. I was looking at the Swift reference. The docs seem to be incorrect:
 
 https://developer.apple.com/library/prerelease/ios/documentation/Swift/Conceptual/Swift_Programming_Language/Patterns.html#//apple_ref/swift/grammar/pattern
 
 There are two type-casting patterns, the is pattern and the as pattern. Both 
 type-casting patterns appear only in switch statement case labels.

The power of `case` outside `switch` was increased at some point. It's likely 
that the documentation has not caught up. You should file a bug report.


-- 
Greg Parker gpar...@apple.com Runtime Wrangler



___

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

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

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

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

Re: How to get Unicode's General Category of a character?

2015-07-07 Thread Dmitry Markman
Hi Gerriet

first of all it’s unicode/uchar.h header (not utypes.h)

I think it would be the best to download ICU distribution from

http://site.icu-project.org/download/55#TOC-ICU4C-Download


download sources and build it

in order to build you have to do the following


download and unarchive icu4c-55_1-src.tgz

cd icu
mkdir build
export CXXFLAGS='--std=c++11 --stdlib=libc++ -DUCHAR_TYPE=char16_t'   (or add 
--enable-debug for debug)
cd build
../source/configure --enable-shared --enable-static 
—prefix=path_to_install_dir
make
make install

in include/unicode/platform.h immediately after lines
#   if (defined(__cplusplus)  __cplusplus = 201103L) || 
(defined(__STDC_VERSION__)  __STDC_VERSION__ = 201112L)
#   define U_HAVE_CHAR16_T 1
add the following
#   define UCHAR_TYPE  char16_t


try ICU if you are getting error U_MISSING_RESOURCE_ERROR, then

rebuild data from build/data directory: touch Makefile and just run make


Note: I tried to use homebrew, but I wasn’t able to build c++11 libraries that 
use char16_t type

instructions from above will let you do just that

in order to build your application use the following switches

LDFLAGS:  -Lpath_to_install_dir/lib
CPPFLAGS: -Ipath_to_install_dir/include

hope it will help

ask me off-list if you have any problem

cheers

 dm







 On Jul 7, 2015, at 9:10 AM, Gerriet M. Denkmann gerr...@mdenkmann.de wrote:
 
 
 On 7 Jul 2015, at 19:33, Dmitry Markman dmark...@mac.com wrote:
 
 ICU’s
 
 u_charType
 
 Looks exactly like what I need.
 But: are the headers and the library on my Mac?
 
 There is /usr/lib/libicucore.A.dylib which might contain u_charType, but I 
 cannot find any headers (e.g. utypes.h).
 
 Do I have to download the source from ICU?
 
 
 Kind regards,
 
 Gerriet.
 
 
 
 
 
 On Jul 7, 2015, at 8:03 AM, Gerriet M. Denkmann gerr...@mdenkmann.de 
 wrote:
 
 Given a character (a Unicode code point, to be exact) like U+FF0B 
 (FULLWIDTH PLUS SIGN), I want to know the General Category of this.
 For this example it would be “Sm (aka. Math_Symbol or Symbol, Math).
 
 I could download the current version of UnicodeData.txt and parse it.
 But this looks not very efficient.
 
 For punctuation one could use NSCharacterSet punctuationCharacterSet.
 
 But for Math Symbols?
 
 I did look at CFStringTransform, which can give the Character name via 
 kCFStringTransformToUnicodeName.
 
 But I cannot find anything for “General Category
 
 NSRegularExpression can match for [\p{General_Category = Math_Symbol}]; not 
 quite what I want, but better than nothing.
 
 
 Any ideas?
 
 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/dmarkman%40mac.com
 
 This email sent to dmark...@mac.com
 
 Dmitry Markman
 
 

Dmitry Markman


___

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 get Unicode's General Category of a character?

2015-07-07 Thread Gerriet M. Denkmann

 On 7 Jul 2015, at 19:33, Dmitry Markman dmark...@mac.com wrote:
 
 ICU’s
 
 u_charType

Looks exactly like what I need.
But: are the headers and the library on my Mac?

There is /usr/lib/libicucore.A.dylib which might contain u_charType, but I 
cannot find any headers (e.g. utypes.h).

Do I have to download the source from ICU?


Kind regards,

Gerriet.



 
 
 On Jul 7, 2015, at 8:03 AM, Gerriet M. Denkmann gerr...@mdenkmann.de wrote:
 
 Given a character (a Unicode code point, to be exact) like U+FF0B (FULLWIDTH 
 PLUS SIGN), I want to know the General Category of this.
 For this example it would be “Sm (aka. Math_Symbol or Symbol, Math).
 
 I could download the current version of UnicodeData.txt and parse it.
 But this looks not very efficient.
 
 For punctuation one could use NSCharacterSet punctuationCharacterSet.
 
 But for Math Symbols?
 
 I did look at CFStringTransform, which can give the Character name via 
 kCFStringTransformToUnicodeName.
 
 But I cannot find anything for “General Category
 
 NSRegularExpression can match for [\p{General_Category = Math_Symbol}]; not 
 quite what I want, but better than nothing.
 
 
 Any ideas?
 
 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/dmarkman%40mac.com
 
 This email sent to dmark...@mac.com
 
 Dmitry Markman
 


___

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-07 Thread Richard Charles

 On Jul 6, 2015, at 5:49 PM, Joel Norvell framewor...@yahoo.com wrote:
 
 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


Yes I have access to the field editor for the NSTextField. Directly setting the 
selection using the field editor however does not work.

- (BOOL)becomeFirstResponder
{
BOOL result = [super becomeFirstResponder];
if(result) {
NSText *editor = self.currentEditor;
assert(editor  Current editor is nil!);
assert(editor.isFieldEditor  Editor not a field editor!);
NSRange range = NSMakeRange(0, editor.string.length);
[editor setSelectedRange:range];
}
return result;
}

The above code does not work.

There is some sort of interaction between NSTextField (and or the field editor) 
and the runloop that has changed for the worse in OS X 10.10 Yosemite. The only 
code that works is to override becomeFirstResponder and then schedule the 
selectText: message with the runloop to execute after a non zero delay. I have 
not been able to get anything else to work.

A comment by Daniel Wabyick at the end of this stackoverflow question suggests 
that this was a problem in OS X 10.9 Mavericks but have been unable to 
duplicate that.

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

So in summary in OS X 10.10 selecting all the text of an NSTextField when the 
user clicks it has become difficult.

--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: Possible to defer initialization of let variable?

2015-07-07 Thread Greg Weston
 If you ask the wrong question, you get a wrong answer. :)
 
 Whether or not it was the wrong question is debatable.

Honestly I find that assertion suspect considering that you've moved the 
goalposts three times.
___

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: Predicate warning from text view

2015-07-07 Thread Shane Stanley
On 25 Oct 2014, at 10:23 am, Martin Wierschin mar...@nisus.com wrote:

 I have a subclass of a text view in my app. When I double-click on other 
 than a word (ie, a space or return), I get entries like these in the Console:
 
 _NSExtensionIsSafeExpressionForObjectWithSubquerySubstitutions: Expression 
 considered unsafe: SUBQUERY(extensionItems, $extensionItem, 
 $extensionItem.attachments.@count == 1 AND 
 SUBQUERY($extensionItem.attachments, $attachment, (NOT ANY 
 $attachment.registeredTypeIdentifiers UTI-CONFORMS-TO com.adobe.pdf) AND 
 (NOT ANY $attachment.registeredTypeIdentifiers UTI-CONFORMS-TO 
 public.image)).@count == 0).@count
 
 
 I observed this log statement during the Yosemite beta period, on a stock 
 system with no additional extensions/apps installed, aside from my own app 
 being tested on OS X 10.10. My app (which also uses an NSTextView subclass) 
 produced that log statement, but TextEdit also produced a very similar log:
 
 TextEdit[578]: 
 _NSExtensionIsSafeExpressionForObjectWithSubquerySubstitutions: Expression 
 considered unsafe: SUBQUERY($extensionItem.attachments, $attachment, ANY 
 $attachment.registeredTypeIdentifiers UTI-CONFORMS-TO public.image)
 
 
 I filed it as rdar://17541734 rdar://17541734 which was marked as a 
 duplicate of rdar://17432480 rdar://17432480 which is apparently closed 
 now. Perhaps the problem was reintroduced, or this has a different source? 
 
 In any case, I never observed any actual ill effects in my app whenever the 
 logging was triggered.

Just coming back to this...

I *think* that the number of these entries seems to have increased since I 
upgraded to 10.10.4  -- Console can be flooded with dozens at a time. But I've 
also found that they *stop* if turn off the Markup extension, and start back up 
when I turn it back on.

Can anyone else who is seeing the problem confirm that turning Markup solves 
the problem? nd aAny thoughts on how I might get Markup to stop poking in my 
window, especially as it can't actually do anything there?

-- 
Shane Stanley sstan...@myriad-com.com.au
www.macosxautomation.com/applescript/apps/

___

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-07 Thread Willeke
 Op 6 jul. 2015, om 18:15 heeft Richard Charles rcharles...@gmail.com het 
 volgende geschreven:
 
 Does anyone have any insight into what is going on?
 
The animation of the focus ring isn't finished. If the focus ring is switched 
off, the text is selected.

Safari's Address and Search field calls setSelectedRange: of currentEditor in 
mouseDown:

- Willeke
___

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