• 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
Re: Swift Generics Error When Enforcing Protocol Conformance...
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Swift Generics Error When Enforcing Protocol Conformance...


  • Subject: Re: Swift Generics Error When Enforcing Protocol Conformance...
  • From: "Peters, Brandon" <email@hidden>
  • Date: Thu, 24 Dec 2015 21:22:42 +0000
  • Thread-topic: Swift Generics Error When Enforcing Protocol Conformance...

Quincey,

That part works, but now I get an error on a line of code where multiplication takes place. This error occurred after the change for suggested:

func linconv<T: FloatingPointType>(signal_A signal_A: [T], signal_B: [T]) -> [T]? {

    // guard
    guard signal_A.isEmpty == false && signal_B.isEmpty == false else {
        return nil
    }

    // reverse at least one of the arrays
    //let signal_A_reversed = Array(signal_A.reverse())

    // size of new array
    let N = signal_A.count + signal_B.count - 1

    // new array for result
    var resultSignal = [T](count: N, repeatedValue: T(0))

    for n in 0..<N {

        for j in 0...n {

            if j < signal_B.count && (n - j) < signal_A.count {

                resultSignal[n] += (signal_B[j] * signal_A[n - j]) // error here, cannot use binary operator ‘*'
            }
        }
    }

    return resultSignal

}

My head is starting to spin. Again, I do not see this one being any different from the integer type version.

> On Dec 24, 2015, at 2:55 PM, Peters, Brandon <email@hidden> wrote:
>
> Quincey,
>
> I must have missed something small earlier. Tried it again and it works. Thank you...
>
> On Dec 24, 2015, at 12:28 PM, Quincey Morris <email@hidden<mailto:email@hidden>> wrote:
>
> On Dec 24, 2015, at 04:55 , Peters, Brandon <email@hidden<mailto:email@hidden>> wrote:
>
> I am using Xcode 7.2. What version of Xcode are you running? Unless I am missing something, the version you typed into playground is not working for me in code editor when I press run.
>
> Also 7.2. Here is exactly what I have in the playground, and it correctly shows the result as nil:
>
> func linconv<T: FloatingPointType>(signal_A signal_A: [T], signal_B: [T]) -> [T]? {
>
> var arr = [T](count: 4, repeatedValue: T(0))
>
> return nil
> }
>
> func linconv<T: IntegerType>(signal_A signal_A: [T], signal_B: [T]) -> [T]? {
>
> var arr = [T](count: 4, repeatedValue: 0)
>
> return nil
> }
>
> linconv (signal_A: [10.0], signal_B: [20.0])
>
>
> _______________________________________________
>
> 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


_______________________________________________

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 Generics Error When Enforcing Protocol Conformance...
      • From: Quincey Morris <email@hidden>
References: 
 >Swift Generics Error When Enforcing Protocol Conformance... (From: "Peters, Brandon" <email@hidden>)
 >Re: Swift Generics Error When Enforcing Protocol Conformance... (From: Quincey Morris <email@hidden>)
 >Re: Swift Generics Error When Enforcing Protocol Conformance... (From: "Peters, Brandon" <email@hidden>)
 >Re: Swift Generics Error When Enforcing Protocol Conformance... (From: Quincey Morris <email@hidden>)
 >Re: Swift Generics Error When Enforcing Protocol Conformance... (From: "Peters, Brandon" <email@hidden>)

  • Prev by Date: Re: Swift Generics Error When Enforcing Protocol Conformance...
  • Next by Date: Re: Swift Generics Error When Enforcing Protocol Conformance...
  • Previous by thread: Re: Swift Generics Error When Enforcing Protocol Conformance...
  • Next by thread: Re: Swift Generics Error When Enforcing Protocol Conformance...
  • Index(es):
    • Date
    • Thread