Creating initialized NSArray

Hi,

I need an NSArray containing CGColorRefs for CAGradientLayer. I create it like this. The INSTANCE fields are of type UIColor:

NSArray.arrayWithObjects<CGColorRef>(IosRed.INSTANCE.CGColor(), IosShadowBlack.INSTANCE.CGColor(), null)

The strange thing is that the first color is not picked up by the gradient. The layer uses a fully transparent color instead of the first color.

When I inspect the contents of the array with the following code:

    val first = SHADOW_GRADIENT_COLORS.get(0)
    println("First: ${if (first is CGColorRef) CoreGraphics.CGColorGetAlpha(first) else "Not a color: ${first?.javaClass?.simpleName}"}")
    val second = SHADOW_GRADIENT_COLORS.get(1)
    println("Second: ${if (second is CGColorRef) CoreGraphics.CGColorGetAlpha(second) else "Not a color: ${second?.javaClass?.simpleName}"}")

I get the following output:

First: 1.0
Second: Not a color: NSObject

So the first object is actually a CGColorRef, but CAGradientLayer cannot use it and defaults to a fully transparent color. The second object is not a CGColorRef, but CAGradientLayer does use the color that I want for it.

What am I doing wrong? How do I create the array correctly so the first color is correctly picked up?

Regards, Johan

Hi,

which version of MOE are you using? Could you please try MOE 1.3.0-beta-2 if you are using an older version?

Could you share a complete test project, so it is easier for us to reproduce the problem?

Best Regards,
Gergely

I use the latest: 1.3.0-beta-2.

Yes, I can. I will let you know where to find it once I have it.

Regards, Johan

Here is a project reproducing the issue: https://github.com/jstuyts/moe-nsarray-initialization-issue

Thanks, we were able to reproduce it, we are working on a fix for the next beta:

https://github.com/multi-os-engine/multi-os-engine/issues/93#

1 Like