• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Swift 2.0 difficulty
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Swift 2.0 difficulty


  • Subject: Swift 2.0 difficulty
  • From: Michael de Haan  <email@hidden>
  • Date: Sun, 28 Jun 2015 23:37:50 -0700

Hi All
I am looking at Swift 2.0. The compiler has converted the code below to the “latest” Swift syntax. This causes the error shown. I have spent a few days trying to get this to compile. What is confusing to me, is that the code, listed last (func removeAnElemen…..)  does compile ( all in Playground) and there 'anyGenerator' seems to tolerate some logic in the body of “anyGenerator”.
Any insight will be much appreciated.



// This is OLD Swift
// Generators and sequences
var currentValue = 1
let newGenerator = GeneratorOf<Int> {
    let previousValue = currentValue
    currentValue = currentValue * 2
    if (previousValue > 20) { return nil }
    return previousValue
}
let generatedArray = Array(newGenerator)




// This is Swift 2.0
// Generators and sequences
var currentValue = 1
let newGenerator = anyGenerator {  // Error: Cannot find an overload for ‘anyGenerator’ that accepts an argument list of type ‘(()-> _)
    let previousValue = currentValue
    currentValue = currentValue * 2
    if (previousValue > 20) { return nil }
    return previousValue
}
let generatedArray = Array(newGenerator)


This does compile:

func removeAnElement<T>(array: [T]) -> AnyGenerator<[T]> {
    var i = 0
    return anyGenerator {
        if i < array.count {
            var result = array.self
            result.removeAtIndex(i)
            i++
            return result
        }
        return nil
    }
}
Array(removeAnElement([1,2,3]))
_______________________________________________

Cocoa-dev mailing list (email@hidden)

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:

This email sent to email@hidden


  • Follow-Ups:
    • Re: Swift 2.0 difficulty
      • From: Roland King <email@hidden>
  • Prev by Date: NSUserDefaults allocation size and CALayer memory usage
  • Next by Date: Re: Swift 2.0 difficulty
  • Previous by thread: Re: NSUserDefaults allocation size and CALayer memory usage
  • Next by thread: Re: Swift 2.0 difficulty
  • Index(es):
    • Date
    • Thread