Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Member 'index' cannot be used on value of protocol type 'collection'; use a generic constraint instead #1593

Closed
malaypatel11 opened this issue Oct 2, 2016 · 8 comments

Comments

@malaypatel11
Copy link

if colorString.hasPrefix("#")
{
var argb: [UInt] = [255, 0, 0, 0]
let colorString = colorString.unicodeScalars
var length = colorString.count
var index = colorString.startIndex
let endIndex = colorString.endIndex

        **index = <#T##Collection corresponding to `index`##Collection#>.index(index, offsetBy: 1)**
        length = length - 1

        if length == 3 || length == 6 || length == 8
        {
            var i = length == 8 ? 0 : 1
            while index < endIndex
            {
                var c = colorString[index]
                **index = <#T##Collection corresponding to `index`##Collection#>.index(index, offsetBy: 1)**

                var val = (c.value >= 0x61 && c.value <= 0x66) ? (c.value - 0x61 + 10) : c.value - 0x30
                argb[i] = UInt(val) * 16
                if length == 3
                {
                    argb[i] = argb[i] + UInt(val)
                }
                else
                {
                    c = colorString[index]
                    **index = <#T##Collection corresponding to `index`##Collection#>.index(index, offsetBy: 1)**

                    val = (c.value >= 0x61 && c.value <= 0x66) ? (c.value - 0x61 + 10) : c.value - 0x30
                    argb[i] = argb[i] + UInt(val)
                }

                i += 1
            }
        }
@liuxuan30
Copy link
Member

liuxuan30 commented Oct 8, 2016

No idea why asked here. closing. Stack Overflow is a better place to ask this

@malaypatel11
Copy link
Author

Because these error comes in your framework that's why I am asked here.

@liuxuan30
Copy link
Member

liuxuan30 commented Oct 10, 2016

I don't know what's the problem you are talking, either reproducing or where it crashes.
Need more details like how to reproduce or crash trace, not just pasting an error message and some code that we don't know where's the issue.

@malaypatel11
Copy link
Author

http://pasteboard.co/1knihIRyg.png
can you see above image so you can better idea.

@danielgindi
Copy link
Collaborator

It seems like an error that should have been raised in compile time. Strange.

@danielgindi danielgindi reopened this Oct 10, 2016
@danielgindi
Copy link
Collaborator

I see no crash there. And no complaint.
You are probably compiling with Xcode 7 or something like that.

@malaypatel11
Copy link
Author

Yes thats compile and build failed. I am using Xcode 8 and swift 3.0.

@liuxuan30
Copy link
Member

liuxuan30 commented Oct 11, 2016

Please download the code again, I never saw code like yours on my side:

        if colorString.hasPrefix("#")
        {
            var argb: [UInt] = [255, 0, 0, 0]
            let colorString = colorString.unicodeScalars
            var length = colorString.count
            var index = colorString.startIndex
            let endIndex = colorString.endIndex

            index = colorString.index(after: index) <===== watch this line
            length = length - 1

            if length == 3 || length == 6 || length == 8

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants