In Swift 4.0 Xcode 9.4.1 using the vDSP_zvmags function and passing an inout float array variable works however in Swift 4.2 Xcode 10.1 complains that one cannot pass an array parameter when a expecting a float type.
//Class variable
private var magnitudes: [Float]!
self.magnitudes = [Float](repeating: 0.0, count: self.halfSize)
vDSP_zvmags(&(self.complexBuffer!), 1, &self.magnitudes!, 1, UInt(self.halfSize))
Error message:
Cannot convert value of type '[Float]' to expected argument type 'Float'
&self.magnitudes! is underlined in red.
Can someone shed some light as to why it is acceptable in Swift 4.0 and not acceptable in Swift 4.2? The function does not appear to have changed between the 2 functions, I have checked in Apple's documentation and looked at the vDSP library doc.
If the class variable is initialized on declaration to empty float array the error disappears.
Related
Using malloc_zone_statistics , heap memory of iOS app in obj-c can be found as shown below.
#import <malloc/malloc.h>
malloc_statistics_t stats;
malloc_zone_statistics(NULL, &stats);
printf("%zu",stats.size_allocated);
How to use the same in swift? when I do the same in swift as :
var stat:malloc_statistics_t;
malloc_zone_statistics(nil, stat);
print(stat.size_allocated);
I get the error as - Cannot convert value of type 'malloc_statistics_t' to expected argument type 'UnsafeMutablePointer?'.
I'm working on ARKit and trying to initialize SCNMatrix but its throwing following error:
Code snippet:
if let frame = self.sceneView.session.currentFrame {
let mat = SCNMatrix4(frame.camera.transform)
return (dir, pos)
}
Error:
Cannot invoke initializer for type ‘SCNMatrix4’ with an argument list
of type ‘(matrix_float4x4)’ Overloads for ‘SCNMatrix4’ exist with
these partially matching parameter lists: (float4x4), (double4x4)
Does anyone face something similar kind of issue?
You're using an old Xcode beta. Swift bridging for SIMD matrix types changed in Xcode 9.0 beta 2. (As of this writing, beta 3 is current.)
With said changes, matrix_float_4x4 and float4x4 are the same type, so your code should work fine.
I was using this code.
var audioUnit:AudioUnit = AudioUnit()
But in Xcode 7.3 (Swift 2.2) I am getting this warning. Any idea why? And how can I get rid of that?
N.B. Is I use nil then my program crashes.
AudioUnit is a typealias of AudioComponentInstance which itself is a typealias of COpaquePointer. Initializing pointers will be removed with Swift 3.0, just set the variable to nil.
nil and AudioUnit() should do the same thing. If your program is crashing with nil, you probably have a bug somewhere else.
Im trying to create a CGPattern using callbacks however the following method signature is not of CGPatternDrawPatternCallback type and I can not determine what it should be
func patternDefinitionFunction(#info: UnsafeMutablePointer<Void>, c: CGContext?)
You can't do this in Swift 1.2 or earlier; you'd have to write this part of your code in Objective-C. To write a C function in Swift, you'll need to update to Swift 2.0 (available in the Xcode 7 beta currently).
I'm trying to use AHEasing in my Swift project. I've installed it via cocoapods and included this line in my bridging header:
#import <AHEasing/CAKeyframeAnimation+AHEasing.h>
I am able to access the function in CAKeyframeAnimation+AHEasing.h just fine, but when I try
var alphaAnimation = CAKeyframeAnimation.animationWithKeyPath("alpha", function: QuadraticEaseInOut, fromValue: 1.0, toValue: 0.0)
I get the error
Cannot invoke 'animationWithKeyPath' with an argument list of type '(String, function: (Double) -> Double, fromValue: Double, toValue: Double)'
After a little digging, I confirmed that QuadraticEaseInOut is indeed being converted to a (Double) -> Double closure, while the type for that parameter, AHEasingFunction, is being converted into a CFunctionPointer<((Double) -> Double)>.
Is there a way to convert between these 2 types? Has anyone successfully used AHEasing in Swift? Is there another work around that I'm not seeing?
I've heard reports from some people that this is a Swift 1.2 issue, that is no longer a problem in Swift 2.
Either way, I just worked around the problem by implementing the functionality that I needed from AHEasing entirely in Swift.