Re: [swift-evolution] [Pitch] Reducing the bridging magic in dynamic casts

2016-05-09 Thread Joe Groff via swift-evolution
> On May 9, 2016, at 2:28 PM, Adrian Zubarev via swift-evolution > wrote: > > >> Right, you'd need to do NSString(string) as AnyObject to explicitly bridge. > > Okay great I'm fine with that. :) > >> The @objc-ness of AnyObject is more or less an implementation

Re: [swift-evolution] [Pitch] Reducing the bridging magic in dynamic casts

2016-05-09 Thread Adrian Zubarev via swift-evolution
> Right, you'd need to do NSString(string) as AnyObject to explicitly bridge. Okay great I'm fine with that. :) > The @objc-ness of AnyObject is more or less an implementation detail. On > Darwin platforms at least, AnyObject still has the magic ability to dispatch > to all @objc methods,

Re: [swift-evolution] [Pitch] Reducing the bridging magic in dynamic casts

2016-05-09 Thread Charles Srstka via swift-evolution
> On May 6, 2016, at 2:04 AM, Adrian Zubarev via swift-evolution > wrote: > > The ugly NSError pattern could be rewritten and migrated to: > > do { >try something() > } catch let error { >handle(error `bridge` NSError) > } > > Is such a change complicated,

Re: [swift-evolution] [Pitch] Reducing the bridging magic in dynamic casts

2016-05-09 Thread Joe Groff via swift-evolution
> On May 6, 2016, at 12:04 AM, Adrian Zubarev via swift-evolution > wrote: > > Definitely a welcome change from me (+1). But this proposal makes me curious > about the impact on the `AnyObject` protocol? > > let string = "foo" > let nsString = string as AnyObject >

Re: [swift-evolution] [Pitch] Reducing the bridging magic in dynamic casts

2016-05-09 Thread Joe Groff via swift-evolution
> On May 6, 2016, at 7:24 PM, Jose Cheyo Jimenez wrote: > > Hi Joe, > > Would I still be able to cast an AnyObject to a String or Array etc? You would do so via constructors rather than using `as?`, something like String(bridging: object). -Joe > I am thinking about

Re: [swift-evolution] [Pitch] Reducing the bridging magic in dynamic casts

2016-05-06 Thread Jose Cheyo Jimenez via swift-evolution
Hi Joe, Would I still be able to cast an AnyObject to a String or Array etc? I am thinking about working with JSON files and using the Apple JSON Parser. Thanks > On May 3, 2016, at 4:50 PM, Joe Groff via swift-evolution > wrote: > > Thanks everyone for the

Re: [swift-evolution] [Pitch] Reducing the bridging magic in dynamic casts

2016-05-06 Thread Adrian Zubarev via swift-evolution
Definitely a welcome change from me (+1). But this proposal makes me curious about the impact on the `AnyObject` protocol? let string = "foo" let nsString = string as AnyObject nsString.dynamicType // _NSCFConstantString.Type NSString().dynamicType // __NSCFConstantString.Type // there are two

Re: [swift-evolution] [Pitch] Reducing the bridging magic in dynamic casts

2016-05-03 Thread Joe Groff via swift-evolution
Thanks everyone for the initial round of feedback. I've submitted a draft proposal: https://github.com/apple/swift-evolution/pull/289 https://github.com/jckarter/swift-evolution/blob/remove-bridging-conversion-dynamic-casts/proposals/-remove-bridging-from-dynamic-casts.md -Joe

Re: [swift-evolution] [Pitch] Reducing the bridging magic in dynamic casts

2016-05-03 Thread Charles Srstka via swift-evolution
Here’s another argument in favor of the pitch: Take an array: let array = ["Foo", "Bar”] We can convert this to an NSArray via the bridge: let nsArray = array as NSArray We can also convert this to a CFArray: let cfArray = array as CFArray Now, let’s convert them back. let nsUntypedArray =

Re: [swift-evolution] [Pitch] Reducing the bridging magic in dynamic casts

2016-05-03 Thread J.D. Healy via swift-evolution
Confused about getAsNSString from bullet point 5, used again in bullet point 8 — the function wont compile for me: > Check whether a value is _ObjectiveCBridgeable to a class, or conversely, > that an object is _ObjectiveCBridgeable to a value type, and perform the > bridging conversion if so: >

Re: [swift-evolution] [Pitch] Reducing the bridging magic in dynamic casts

2016-05-03 Thread Joe Groff via swift-evolution
> On May 3, 2016, at 8:48 AM, J.D. Healy wrote: > > Confused about getAsNSString from bullet point 5, used again in bullet point > 8 — the function wont compile for me: There's a typo. getAsNSString needs to return an optional, `NSString?`, because the cast produces nil if

Re: [swift-evolution] [Pitch] Reducing the bridging magic in dynamic casts

2016-05-02 Thread T.J. Usiyan via swift-evolution
+1 to this. `as` is a hairy beast. On Mon, May 2, 2016 at 8:45 PM, Charles Srstka via swift-evolution < swift-evolution@swift.org> wrote: > On May 2, 2016, at 4:48 PM, Erica Sadun via swift-evolution < > swift-evolution@swift.org> wrote: > > > On May 2, 2016, at 3:45 PM, Chris Lattner via

Re: [swift-evolution] [Pitch] Reducing the bridging magic in dynamic casts

2016-05-02 Thread Charles Srstka via swift-evolution
> On May 2, 2016, at 4:48 PM, Erica Sadun via swift-evolution > wrote: > >> On May 2, 2016, at 3:45 PM, Chris Lattner via swift-evolution >> > wrote: >>> NSError bridging can also be extracted from the

Re: [swift-evolution] [Pitch] Reducing the bridging magic in dynamic casts

2016-05-02 Thread Charles Srstka via swift-evolution
> On May 2, 2016, at 5:53 PM, Joe Groff via swift-evolution > wrote: > > I can't think of any problems that would block us from doing that today. It'd > be pretty easy to write an ErrorProtocol extension that just forwards > NSError's interface via bridging, and I

Re: [swift-evolution] [Pitch] Reducing the bridging magic in dynamic casts

2016-05-02 Thread Joe Groff via swift-evolution
> On May 2, 2016, at 3:50 PM, Chris Lattner wrote: > > >> On May 2, 2016, at 3:43 PM, Joe Groff wrote: >> >> >>> On May 2, 2016, at 2:45 PM, Chris Lattner wrote: >>> >>> On Apr 29, 2016, at 3:00 PM, Joe Groff via swift-evolution

Re: [swift-evolution] [Pitch] Reducing the bridging magic in dynamic casts

2016-05-02 Thread Chris Lattner via swift-evolution
> On May 2, 2016, at 3:43 PM, Joe Groff wrote: > > >> On May 2, 2016, at 2:45 PM, Chris Lattner wrote: >> >> On Apr 29, 2016, at 3:00 PM, Joe Groff via swift-evolution >> wrote: >>> I’d like to propose the following changes:

Re: [swift-evolution] [Pitch] Reducing the bridging magic in dynamic casts

2016-05-02 Thread David Hart via swift-evolution
I got the reference, made me laugh :) > On 03 May 2016, at 00:21, Erica Sadun via swift-evolution > wrote: > > >> On May 2, 2016, at 4:15 PM, Chris Lattner > > wrote: >> >>> >>> On May 2, 2016, at 2:48 PM, Erica

Re: [swift-evolution] [Pitch] Reducing the bridging magic in dynamic casts

2016-05-02 Thread Erica Sadun via swift-evolution
> On May 2, 2016, at 4:15 PM, Chris Lattner wrote: > >> >> On May 2, 2016, at 2:48 PM, Erica Sadun > > wrote: >> >> >>> On May 2, 2016, at 3:45 PM, Chris Lattner via swift-evolution >>>

Re: [swift-evolution] [Pitch] Reducing the bridging magic in dynamic casts

2016-05-02 Thread Chris Lattner via swift-evolution
> On May 2, 2016, at 2:48 PM, Erica Sadun wrote: > > >> On May 2, 2016, at 3:45 PM, Chris Lattner via swift-evolution >> > wrote: >>> NSError bridging can also be extracted from the runtime, and the same >>>

[swift-evolution] [Pitch] Reducing the bridging magic in dynamic casts

2016-04-29 Thread Joe Groff via swift-evolution
When we introduced Swift, we wanted to provide value types for common containers, with the safety and state isolation benefits they provide, while still working well with the reference-oriented world of Cocoa. To that end, we invested a lot of work into bridging between Swift’s value semantics