On Nov 22, 2016, at 16:17 , Charles Jenkins <cejw...@gmail.com> wrote: > > I have this line of code: > > let gradient = CGGradient( colorsSpace: CGColorSpaceCreateDeviceRGB(), > colors: [ clearWhite.cgColor, clearWhite.cgColor, > clearWhite.blendedColorWithFraction(0.5, ofColor: white).cgColor, > white.cgColor ], locations: [0, 0.57, 0.93, 1]) > > The array of colors is no longer legal in Swift 3. I get an error > message—“Contextual type CFArray cannot be used with an array > literal”—which I think is saying I must pass a CFArray.
The immediate problem is that the error message is spurious. Method “blendedColorWithFraction(:ofColor:)” has been renamed in Swift 3 to “blendedColor(withFraction:of:)”, so your array cannot be constructed as the desired type "[GCColor]". The secondary problem is that “blendedColor(withFraction:of:)” returns an optional, so you need a “!” operator after it. The third problem is that you need “as CGArray”. There would have been a fix-it for this, if the first two problems had been fixed. The following code compiles in a (macOS) playground: > import AppKit > > let clearWhite = NSColor.white // or whatever > let white = NSColor.white // or whatever > > let colors = [ clearWhite.cgColor, clearWhite.cgColor, > clearWhite.blended(withFraction: 0.5, of: white)!.cgColor, > white.cgColor ] > > let gradient = CGGradient( colorsSpace: CGColorSpaceCreateDeviceRGB(), > colors: colors as CFArray, locations: [0, 0.57, > 0.93, 1]) I would expect the iOS version is the same, if that’s what you need. For puzzling problems like this, I suggest “unrolling” the parameters like the above, specifying explicit type annotations if you’re not sure what types are being inferred. _______________________________________________ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) 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: https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com