Re: [swift-users] When does `Data.init?(capacity:)` fail?

2016-06-17 Thread Saagar Jha via swift-users
This  might be
relavant. Basically, Data’s init will fail if memory can’t be allocated for
it.


On Fri, Jun 17, 2016 at 11:38 AM Adrian Zubarev via swift-users <
swift-users@swift.org> wrote:

> Hello there, I’m trying to optimize my code and reduce copying from
> different buffers into a new one.
>
> I thought I just create a Data value with enough capacity and write
> directly into it. My problem is that Data.init?(capacity:) can fail, but
> why and when?
>
> Can someone explain this behavior to me?
>
> I’m sending data via TCP sockets and when recn function write directly
> into a Data struct.
>
>
>
> --
> Adrian Zubarev
> Sent with Airmail
>
> ___
> swift-users mailing list
> swift-users@swift.org
> https://lists.swift.org/mailman/listinfo/swift-users
>
-- 
-Saagar Jha
___
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users


Re: [swift-users] See documentation comment for discussion

2016-06-17 Thread Brent Royal-Gordon via swift-users
> I've previously used myString[0...1] to get the first character of a string.

I'm not sure how, because this has never worked in Swift. Strings use opaque 
indices which specifically prevent you from doing this, so you have never been 
able to subscript a string with integers or ranges of integers. It's done this 
way because indexing into a Unicode string intrinsically requires walking 
through the data structure and counting characters one at a time; the lack of 
integer indices is meant to force you to explicitly write `index(after:)` or 
`index(_:offsetBy:)` (formerly `successor()` or `advancedBy(_:)`) in your code 
to make this cost obvious.

> What documentation is this referring to? There's no right-click definition 
> available, nothing in Navigator, and Google fails to turn up anything.

The standard library includes definitions of these subscripts which are meant 
to direct you to documentation explaining why they're not supported, but these 
definitions don't show up in the generated interfaces. Presumably Xcode is 
removing all APIs marked "unavailable". The doc comment it's trying to direct 
you to is here 
:

  /// Subscripting strings with integers is not available.
  ///
  /// The concept of "the `i`th character in a string" has
  /// different interpretations in different libraries and system
  /// components.  The correct interpretation should be selected
  /// according to the use case and the APIs involved, so `String`
  /// cannot be subscripted with an integer.
  ///
  /// Swift provides several different ways to access the character
  /// data stored inside strings.
  ///
  /// - `String.utf8` is a collection of UTF-8 code units in the
  ///   string. Use this API when converting the string to UTF-8.
  ///   Most POSIX APIs process strings in terms of UTF-8 code units.
  ///
  /// - `String.utf16` is a collection of UTF-16 code units in
  ///   string.  Most Cocoa and Cocoa touch APIs process strings in
  ///   terms of UTF-16 code units.  For example, instances of
  ///   `NSRange` used with `NSAttributedString` and
  ///   `NSRegularExpression` store substring offsets and lengths in
  ///   terms of UTF-16 code units.
  ///
  /// - `String.unicodeScalars` is a collection of Unicode scalars.
  ///   Use this API when you are performing low-level manipulation
  ///   of character data.
  ///
  /// - `String.characters` is a collection of extended grapheme
  ///   clusters, which are an approximation of user-perceived
  ///   characters.
  ///
  /// Note that when processing strings that contain human-readable
  /// text, character-by-character processing should be avoided to
  /// the largest extent possible.  Use high-level locale-sensitive
  /// Unicode algorithms instead, for example,
  /// `String.localizedStandardCompare()`,
  /// `String.localizedLowercaseString`,
  /// `String.localizedStandardRangeOfString()` etc.


-- 
Brent Royal-Gordon
Architechies

___
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users


Re: [swift-users] CGContext endPage method ambiguous (two candidates) Swift 3/Xcode 8

2016-06-17 Thread Dave Reed via swift-users

> On Jun 17, 2016, at 12:28 PM, Joe Groff  wrote:
> 
> 
>> On Jun 16, 2016, at 1:49 PM, Dave Reed via swift-users 
>>  wrote:
>> 
>> I've got a project I had been working on using Swift2.2 and decided to 
>> migrate to Swift3 (using Xcode 8 beta) before the project gets any bigger. I 
>> successfully migrated everything except I have a CGContext for writing to a 
>> PDF and calls the endPage() method. For that the compiler responds with 
>> "ambiguous use of endPage()" and claims to find two candidates for it.
>> 
>> Is there a work around for this?
> 
> This came up in the WWDC labs this week too. One possible workaround is to 
> wrap the original CGPDFContextEndPage function in your bridging header, then 
> call the wrapper function from Swift.
> 
> -Joe
> 

I’ve never mixed Objective-C/C and Swift in the same project but I think I find 
some documentation online for doing this. Unfortunately, my call to endPage is 
in a framework and it appears frameworks cannot use bridging headers (got the 
error "using bridging headers with framework targets is unsupported”).

I guess I’ll have to wait for this to be fixed before I can use that part of 
the app again. Not a major crisis since I’m still a few months away from it 
being done (which is why I made the change to Swift 3 now). Hopefully it will 
get fixed reasonably soon since I suspect it’s some sort of minor typo.

Thanks,
Dave

___
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users


Re: [swift-users] #selector with Swift 3?

2016-06-17 Thread Brent Royal-Gordon via swift-users
> Tried that too, it causes another error:
> 
>/Developer/SwiftNEC 3/SwiftNEC/CardViews.swift:139:28: Expected ':' after 
> 'case'

Huh, that's really strange. This syntax, which should be equivalent, causes a 
compiler crash:

case (#selector(showRescale))?:

So does the slightly-more-shorthanded version:

case .some(#selector(showRescale)):

I'd file another bug about this, this time in the Swift open-source bug tracker 
at .

-- 
Brent Royal-Gordon
Architechies

___
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users


Re: [swift-users] Swift 3.0 and Xcode 7.3.x

2016-06-17 Thread Patrice Kouame via swift-users
Ouch!  Good point.  
I forgot that even the toolchain “snapshots” from the Swift team aren’t 
official Apple releases.
Hope my Xcode 8 on El Capitan issues get fixed soon.

> On Jun 17, 2016, at 6:10 PM, Saagar Jha via swift-users 
>  wrote:
> 
> You won't be able to submit to the App Store with any alternative tool chain 
> (such as Swift 3). 
> On Fri, Jun 17, 2016 at 10:59 Patrice Kouame via swift-users 
> > wrote:
> Hi Jordan - thanks for the quick reply (especially in the middle of WWDC!) 
> 
> I suspected as much with 7.3.x (unfortunately), but I’ve heard of folks 
> running a 3.0 toolchain (from swift.org ) with 7.3.x.  
> Besides an unsupported playground, what other types of side effects can I 
> expect? Just trying to prepare for my worst case scenario where Xcode 8 
> remains flaky on El Capitan for a while.  
> 
> BTW: My Xcode 8 beta on 10.11.5 crashes repeatedly, very reproducible see my 
> posts https://forums.developer.apple.com/thread/49000 
>  
> and my open bug radar report # 26849825 “Xcode 8 beta IDE crashes 
> consistently”.  I hope Apple can take a look at this.  This is my first beta 
> that crashed out of the box. I hope this can get some traction.  I’m surely 
> not the only one.
> 
> regards,
> Patrice
> 
>> On Jun 17, 2016, at 1:14 PM, Jordan Rose via swift-users 
>> > wrote:
>> 
>> Hi, Patrice. Unfortunately it’s unlikely that we’ll have a Swift 3.0 for 
>> Xcode 7.x, because it depends on the macOS 10.12 and iOS 10 SDKs. That said, 
>> we (Apple) would definitely like to hear about issues running Xcode 8 on El 
>> Capitan; if you haven’t already, please file a bug report at 
>> bugreport.apple.com !
>> 
>> Best,
>> Jordan
>> 
>>> On Jun 16, 2016, at 17:31, Patrice Kouame via swift-users 
>>> > wrote:
>>> 
>>> Swift 3.0 for Mac is currently being distributed with Xcode 8 beta.
>>> 
>>> Will a swift 3.0 toolchain for Xcode 7.3.x ever happen?
>>> 
>>> Currently having issues with the beta on El Capitan and my machine
>>> is (apparently) no longer a candidate for future MacOs versions, notably 
>>> Sierra.
>>> 
>>> Thanks in advance.
>>> ___
>>> swift-users mailing list
>>> swift-users@swift.org 
>>> https://lists.swift.org/mailman/listinfo/swift-users 
>>> 
>> 
>> ___
>> swift-users mailing list
>> swift-users@swift.org 
>> https://lists.swift.org/mailman/listinfo/swift-users 
>> 
> 
> ___
> swift-users mailing list
> swift-users@swift.org 
> https://lists.swift.org/mailman/listinfo/swift-users 
> 
> -- 
> -Saagar Jha
> ___
> swift-users mailing list
> swift-users@swift.org
> https://lists.swift.org/mailman/listinfo/swift-users

___
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users


Re: [swift-users] Swift 3.0 and Xcode 7.3.x

2016-06-17 Thread Saagar Jha via swift-users
You won't be able to submit to the App Store with any alternative tool
chain (such as Swift 3).
On Fri, Jun 17, 2016 at 10:59 Patrice Kouame via swift-users <
swift-users@swift.org> wrote:

> Hi Jordan - thanks for the quick reply (especially in the middle of WWDC!)
>
> I suspected as much with 7.3.x (unfortunately), but I’ve heard of folks
> running a 3.0 toolchain (from swift.org) with 7.3.x.  Besides an
> unsupported playground, what other types of side effects can I expect? Just
> trying to prepare for my worst case scenario where Xcode 8 remains flaky on
> El Capitan for a while.
>
> BTW: My Xcode 8 beta on 10.11.5 crashes repeatedly, very reproducible see
> my posts https://forums.developer.apple.com/thread/49000
> and my open bug radar report # 26849825 “Xcode 8 beta IDE crashes
> consistently”.  I hope Apple can take a look at this.  This is my first
> beta that crashed out of the box. I hope this can get some traction.  I’m
> surely not the only one.
>
> regards,
> Patrice
>
> On Jun 17, 2016, at 1:14 PM, Jordan Rose via swift-users <
> swift-users@swift.org> wrote:
>
> Hi, Patrice. Unfortunately it’s unlikely that we’ll have a Swift 3.0 for
> Xcode 7.x, because it depends on the macOS 10.12 and iOS 10 SDKs. That
> said, we (Apple) would definitely like to hear about issues running Xcode 8
> on El Capitan; if you haven’t already, please file a bug report at
> bugreport.apple.com!
>
> Best,
> Jordan
>
> On Jun 16, 2016, at 17:31, Patrice Kouame via swift-users <
> swift-users@swift.org> wrote:
>
> Swift 3.0 for Mac is currently being distributed with Xcode 8 beta.
>
> Will a swift 3.0 toolchain for Xcode 7.3.x ever happen?
>
> Currently having issues with the beta on El Capitan and my machine
> is (apparently) no longer a candidate for future MacOs versions, notably
> Sierra.
>
> Thanks in advance.
> ___
> swift-users mailing list
> swift-users@swift.org
> https://lists.swift.org/mailman/listinfo/swift-users
>
>
> ___
> swift-users mailing list
> swift-users@swift.org
> https://lists.swift.org/mailman/listinfo/swift-users
>
>
> ___
> swift-users mailing list
> swift-users@swift.org
> https://lists.swift.org/mailman/listinfo/swift-users
>
-- 
-Saagar Jha
___
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users


Re: [swift-users] #selector with Swift 3?

2016-06-17 Thread Maury Markowitz via swift-users
> On Jun 17, 2016, at 1:31 PM, Brent Royal-Gordon  
> wrote:
> tl;dr: Write this instead:
> 
>   case #selector(showRescale)?:

Tried that too, it causes another error:

/Developer/SwiftNEC 3/SwiftNEC/CardViews.swift:139:28: Expected ':' after 
'case'

Here are the formats I have tried; all fail with various errors:

case #selector(showRescale):
case #selector(showRescale)?:
case #selector(showRescale)? :
case #selector(showRescale)!:
case #selector(showRescale)! :
case #selector!(showRescale):
case #selector!(showRescale) :

This format, however, did work:

case Optional.some(#selector(showRescale)):

Optional.some? Urk.
___
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users


[swift-users] See documentation comment for discussion

2016-06-17 Thread Maury Markowitz via swift-users
I've previously used myString[0...1] to get the first character of a string. I 
assume that is now myString[0..<2]? In any event, the error states:

'subscript' is unavailable: cannot subscript String with a 
CountableClosedRange, see the documentation comment for discussion

What documentation is this referring to? There's no right-click definition 
available, nothing in Navigator, and Google fails to turn up anything. I 
suspect its referring to the changelist or maybe github checkin notes?
___
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users


Re: [swift-users] AnySequence and type erasure

2016-06-17 Thread Svein Halvor Halvorsen via swift-users
Ok. Good to hear that I'm not too far off :)

Can you provide me with an example of a sequence type or two that has some
map or other function that would benefit from an optimized wrapper? Or:
under what circumstances would the stdlib implementation outperform mine?
I'm completely new to this all, and I'm trying to understand. Could some
random access collection type parallelize a filter? If you want I guarantee
correct ordering, under what circumstances does some sequence type work
better than mere iteration?


fre. 17. jun. 2016 kl. 15.49 skrev Dmitri Gribenko :

> On Fri, Jun 17, 2016 at 1:39 AM, Svein Halvor Halvorsen via
> swift-users  wrote:
> > I'm sure people here know about the problem that AnySequence,
> AnyGenerator,
> > etc solves.
> > In Swift, a protocol can have an associated type, which is kinda like
> > generics, but you cannot declare a variable like this:
> >
> > let sequence: SequenceType
> >
> > If you want a sequence, any sequence, over ints you need to wrap the
> > protocol in a new concrete, generic type, AnySequence that itself
> > implements the protocol SequenceType, and where the associated type
> Element
> > is equal to the generic type T.
> >
> > The standard library does this. And, like many others, I have tried to
> > implement this for my self, to try to better understand the problem, and
> I
> > expected that I would end up with a design very similar to what the
> standard
> > library does. However, I have not seen the need for the complex boxing
> > mechanism. I'm probably misunderstanding something, though.
> >
> > Can someone please look at this code, and give me constructive feedback?
> Is
> > this a novel and working solution, or am I missing something?:
>
> Hi,
>
> Your design should work, but it won't provide optimal performance.
> Sequence has a lot of requirements that can be customized by the
> conforming type (e.g., map()).  We need to forward those to the
> original type to get the best performance.
>
> While you can create a closure for each of the forwarded methods,
> let's say n in total, it is n times more wasteful compared to using
> just a single reference like the standard library does.
>
> Dmitri
>
> --
> main(i,j){for(i=2;;i++){for(j=2;j (j){printf("%d\n",i);}}} /*Dmitri Gribenko */
>
___
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users


Re: [swift-users] #selector with Swift 3?

2016-06-17 Thread Marco S Hyman via swift-users
> On Fri, Jun 17, 2016 at 9:33 PM, Maury Markowitz via swift-users 
>  wrote:
> I was asked to try out the latest betas of Cocoa to check if a SceneKit bug I 
> reported has been fixed. As part of this I decided to try an update to Swift 
> 3. I've run into a number of minor issues, but one has me frustrated. In my 
> menu validate method, I have:
> 
> switch menuItem.action {
> case #selector!(showRescale) :
> 
> This worked fine in 2.2, but now it complains that it expects a ( after 
> #selector. Removing the ! fixes that problem, but now returns an error that 
> there's a missing !, which it inserts to cause the original error again. I 
> also tried placing it after the ()'s, and now it complains that it's 
> expecting the :
> 
> Does anyone know the proper Swift 3 syntax for this?

This code snippet works for me in a menu validation function...

guard let action = anItem?.action else { return false }
switch action {
case #selector(showOpenPanel(_:)):
return true
case #selector(save(_:)):
return modified
case #selector(openPreferencesWindow(_:)):
return true
default:
print("default for item \(anItem)")
}
return false

I used the guard let... to get around the fact that action selectors are now 
optionals.
___
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users


Re: [swift-users] #selector with Swift 3?

2016-06-17 Thread Brent Royal-Gordon via swift-users
> I was asked to try out the latest betas of Cocoa to check if a SceneKit bug I 
> reported has been fixed. As part of this I decided to try an update to Swift 
> 3. I've run into a number of minor issues, but one has me frustrated. In my 
> menu validate method, I have:
> 
>   switch menuItem.action {
>   case #selector!(showRescale) :
> 
> This worked fine in 2.2, but now it complains that it expects a ( after 
> #selector. Removing the ! fixes that problem, but now returns an error that 
> there's a missing !, which it inserts to cause the original error again. I 
> also tried placing it after the ()'s, and now it complains that it's 
> expecting the :
> 
> Does anyone know the proper Swift 3 syntax for this?

tl;dr: Write this instead:

case #selector(showRescale)?:

The explanation:

In Swift 2, Selectors could *always* be nil, even when they weren't optional. 
The same was true of UnsafePointer and a few other types, and it wasn't great. 
So in Swift 3, we've changed these types so they now can only be nil if they're 
optional.

Because of this change, the type of `NSMenuItem.action` changed from `Selector` 
to `Selector?`. That means the patterns in your `switch` statement need to look 
like:

case Optional.some(#selector(showRescale)):

Which you can specify in a pattern match (like a case statement) using the 
convenient trailing-question-mark syntax I showed above:

case #selector(showRescale)?:

The Swift 3 migrator should have generated this code, so you've probably 
encountered a bug. It would help them if you could create a small example 
project and file a bug report at . (The migrator 
is closed source.)

Hope this helps,
-- 
Brent Royal-Gordon
Architechies

___
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users


Re: [swift-users] Redeclaration of guard variable is ignored at top-level

2016-06-17 Thread Martin R via swift-users
Filed as https://bugs.swift.org/browse/SR-1804.

2016-06-17 7:17 GMT-07:00 Mark Lacey :
>
> On Jun 16, 2016, at 10:18 PM, Martin R via swift-users
>  wrote:
>
> Hi,
>
> I wonder why the Swift compiler does not complain about the
> redeclaration of `number` after the guard-statement in top-level code:
>
>// main.swift
>import Swift
>
>guard let number = Int("1234") else { fatalError() }
>print(number) // Output: 1234
>let number = 5678
>print(number) // Output: 1234
>
> It looks as if the statement `let number = 5678` is completely ignored.
>
> However, doing the same inside a function causes a compiler error:
>
>func foo() {
>guard let number = Int("1234") else { fatalError() }
>print(number)
>let number = 5678 //  error: definition conflicts with previous value
>}
>
> Tested with
> - Xcode 7.3.1, "Default" and "Snapshot 2016-06-06 (a)" toolchain
> - Xcode 8 beta.
>
> Am I overlooking something or is that a bug?
>
>
> Hi Martin,
>
> Yes, this looks like a bug. Can you open a report at bugs.swift.org?
>
> Mark
>
>
> Martin
> ___
> swift-users mailing list
> swift-users@swift.org
> https://lists.swift.org/mailman/listinfo/swift-users
>
>
___
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users


[swift-users] Swift 3.0 and Xcode 7.3.x

2016-06-17 Thread Patrice Kouame via swift-users
Swift 3.0 for Mac is currently being distributed with Xcode 8 beta.

Will a swift 3.0 toolchain for Xcode 7.3.x ever happen?

Currently having issues with the beta on El Capitan and my machine
is (apparently) no longer a candidate for future MacOs versions, notably Sierra.

Thanks in advance.
___
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users


Re: [swift-users] CGContext endPage method ambiguous (two candidates) Swift 3/Xcode 8

2016-06-17 Thread Joe Groff via swift-users

> On Jun 16, 2016, at 1:49 PM, Dave Reed via swift-users 
>  wrote:
> 
> I've got a project I had been working on using Swift2.2 and decided to 
> migrate to Swift3 (using Xcode 8 beta) before the project gets any bigger. I 
> successfully migrated everything except I have a CGContext for writing to a 
> PDF and calls the endPage() method. For that the compiler responds with 
> "ambiguous use of endPage()" and claims to find two candidates for it.
> 
> Is there a work around for this?

This came up in the WWDC labs this week too. One possible workaround is to wrap 
the original CGPDFContextEndPage function in your bridging header, then call 
the wrapper function from Swift.

-Joe

> I submitted it via bugreport.apple.com (# 26815976) but is there a better 
> place to report this?
> 
> Also, while the app won't be ready to release until after iOS 10 is released, 
> I would like to start TestFlight beta testing it before that. After doing the 
> conversion, I remembered that you can't submit builds with beta versions of 
> Xcode to the AppStore. Does this also apply to TestFlight betas? I hope not 
> given that Apple is strongly encouraging everyone to convert their code to 
> Swift 3, but I suspect that is the policy.
> 
> Thanks,
> Dave Reed
> 
> 
> ___
> swift-users mailing list
> swift-users@swift.org
> https://lists.swift.org/mailman/listinfo/swift-users

___
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users


Re: [swift-users] #selector with Swift 3?

2016-06-17 Thread zh ao via swift-users
Can you give more information on the function showRescale, is it function
showRescale() or showRescale(a:foo)?
Or have you tried case let x where x == #selector(showRescale):

Zhaoxin

On Fri, Jun 17, 2016 at 9:33 PM, Maury Markowitz via swift-users <
swift-users@swift.org> wrote:

> I was asked to try out the latest betas of Cocoa to check if a SceneKit
> bug I reported has been fixed. As part of this I decided to try an update
> to Swift 3. I've run into a number of minor issues, but one has me
> frustrated. In my menu validate method, I have:
>
> switch menuItem.action {
> case #selector!(showRescale) :
>
> This worked fine in 2.2, but now it complains that it expects a ( after
> #selector. Removing the ! fixes that problem, but now returns an error that
> there's a missing !, which it inserts to cause the original error again. I
> also tried placing it after the ()'s, and now it complains that it's
> expecting the :
>
> Does anyone know the proper Swift 3 syntax for this?
> ___
> swift-users mailing list
> swift-users@swift.org
> https://lists.swift.org/mailman/listinfo/swift-users
>
___
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users


Re: [swift-users] Redeclaration of guard variable is ignored at top-level

2016-06-17 Thread Mark Lacey via swift-users

> On Jun 16, 2016, at 10:18 PM, Martin R via swift-users 
>  wrote:
> 
> Hi,
> 
> I wonder why the Swift compiler does not complain about the
> redeclaration of `number` after the guard-statement in top-level code:
> 
>// main.swift
>import Swift
> 
>guard let number = Int("1234") else { fatalError() }
>print(number) // Output: 1234
>let number = 5678
>print(number) // Output: 1234
> 
> It looks as if the statement `let number = 5678` is completely ignored.
> 
> However, doing the same inside a function causes a compiler error:
> 
>func foo() {
>guard let number = Int("1234") else { fatalError() }
>print(number)
>let number = 5678 //  error: definition conflicts with previous value
>}
> 
> Tested with
> - Xcode 7.3.1, "Default" and "Snapshot 2016-06-06 (a)" toolchain
> - Xcode 8 beta.
> 
> Am I overlooking something or is that a bug?

Hi Martin,

Yes, this looks like a bug. Can you open a report at bugs.swift.org 
?

Mark

> 
> Martin
> ___
> swift-users mailing list
> swift-users@swift.org
> https://lists.swift.org/mailman/listinfo/swift-users

___
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users


Re: [swift-users] AnySequence and type erasure

2016-06-17 Thread Dmitri Gribenko via swift-users
On Fri, Jun 17, 2016 at 1:39 AM, Svein Halvor Halvorsen via
swift-users  wrote:
> I'm sure people here know about the problem that AnySequence, AnyGenerator,
> etc solves.
> In Swift, a protocol can have an associated type, which is kinda like
> generics, but you cannot declare a variable like this:
>
> let sequence: SequenceType
>
> If you want a sequence, any sequence, over ints you need to wrap the
> protocol in a new concrete, generic type, AnySequence that itself
> implements the protocol SequenceType, and where the associated type Element
> is equal to the generic type T.
>
> The standard library does this. And, like many others, I have tried to
> implement this for my self, to try to better understand the problem, and I
> expected that I would end up with a design very similar to what the standard
> library does. However, I have not seen the need for the complex boxing
> mechanism. I'm probably misunderstanding something, though.
>
> Can someone please look at this code, and give me constructive feedback? Is
> this a novel and working solution, or am I missing something?:

Hi,

Your design should work, but it won't provide optimal performance.
Sequence has a lot of requirements that can be customized by the
conforming type (e.g., map()).  We need to forward those to the
original type to get the best performance.

While you can create a closure for each of the forwarded methods,
let's say n in total, it is n times more wasteful compared to using
just a single reference like the standard library does.

Dmitri

-- 
main(i,j){for(i=2;;i++){for(j=2;j*/
___
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users


[swift-users] #selector with Swift 3?

2016-06-17 Thread Maury Markowitz via swift-users
I was asked to try out the latest betas of Cocoa to check if a SceneKit bug I 
reported has been fixed. As part of this I decided to try an update to Swift 3. 
I've run into a number of minor issues, but one has me frustrated. In my menu 
validate method, I have:

switch menuItem.action {
case #selector!(showRescale) :

This worked fine in 2.2, but now it complains that it expects a ( after 
#selector. Removing the ! fixes that problem, but now returns an error that 
there's a missing !, which it inserts to cause the original error again. I also 
tried placing it after the ()'s, and now it complains that it's expecting the :

Does anyone know the proper Swift 3 syntax for this?
___
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users


Re: [swift-users] SequenceType vs. CollectionType

2016-06-17 Thread Brent Royal-Gordon via swift-users
> Well you could do it, but you’d need to build up a non-consuming sequence as 
> you go so it wouldn’t be a transparent wrapper.

You could, but the original post said:

>> I'm not imagining an implementation that does any buffering

-- 
Brent Royal-Gordon
Architechies

___
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users


Re: [swift-users] Swift Meetup

2016-06-17 Thread Emo Abadjiev via swift-users
Anyone can help?

Thanks,
E.

On 15 June 2016 at 13:34, Emo Abadjiev  wrote:

> Hello,
>
> We are organising Swift meetup  in
> Sofia and interested to find out more about:
>
>- can we use the Swift logo? Where we can get a vector image, if yes.
>- is there a good place to register as a new community
>
>
> Thanks,
> Emo Abadjiev
>
>
>
___
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users