Swift: get more detailed error information like function parameter

I am using Xcode 6.3.1 and Swift.

When a function with several parameters gets some error in the type of the parameter, it is difficult to understand which argument is incorrect.

For example, CGBitmapContextCreate()this code:

let colorSpace:CGColorSpace = CGColorSpaceCreateDeviceRGB()
let bitmapInfo = CGBitmapInfo(CGImageAlphaInfo.PremultipliedLast.rawValue)
let context = CGBitmapContextCreate(nil, UInt(size.width), UInt(size.height), 8, 0, colorSpace, bitmapInfo)

will result in an error:

MyFile.swift:23:19: Cannot invoke 'CGBitmapContextCreate' with an argument list of type '(nil, UInt, UInt, Int, Int, CGColorSpace, CGBitmapInfo)'

Comparing the document and the argument list, I can find that these are the 2nd and 3rd arguments, which should be Int.

Is there a way to make the compiler smarter about this?

+4
source share
2 answers

The problem is probably that the online documentation you are looking for CGBitmapContextCreateis incorrect based on the definition that you actually refer to when compiling.

UInt32, CGBitmapInfo CGBitmapInfo. . . "see definition", , .

CGImageAlphaInfo.PremultipliedLast.rawValue, UInt32.

:

let colorSpace:CGColorSpace = CGColorSpaceCreateDeviceRGB()
let bitmapInfo = CGImageAlphaInfo.PremultipliedLast.rawValue
let context = CGBitmapContextCreate(nil, UInt(size.width), UInt(size.height), 8, 0, colorSpace, bitmapInfo)

, . , - , .

PS: , , , .

+2

!

    let width = CGImageGetWidth(image)
    let height = CGImageGetHeight(image)
    let colorSpace = CGColorSpaceCreateDeviceRGB()
    let bytesPerRow = 4 * width;
    let bitsPerComponent :Int = 8
    let pixels = UnsafeMutablePointer<UInt8>(malloc(width*height*4))
    var context = CGBitmapContextCreate(pixels, width, height, bitsPerComponent, bytesPerRow, colorSpace, CGBitmapInfo())
0

All Articles