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.
Related
I have this line in my code:
let argsort = (scores as NSDictionary?)?.keysSortedByValue(using: Selector("compare:"))
but XCode gives me a Use '#selector' instead of explicitly constructing a 'Selector' warning. However, the proposed fix:
let argsort = (scores as NSDictionary?)?.keysSortedByValue(using: #selector(NSTextLocation.compare(_:)))
requires iOS version 15.0, and therefore does not work for me (I am targetting iOS 13.0).
How can I either silence this warning or find a way out of this? Thanks
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.
For whatever reason my application crashes everytime it decodes my Bool value. It didn't crash before I updated to Swift 3. I have no idea what I'm doing wrong. If I take out the Bool value my application runs fine without crashing.
This has been changed for Swift 3. There are associated decode...() functions for various different types.
The correct syntax is now:
let myBool = aDecoder.decodeBool(forKey: PropertyKey.completedKey)
I have an error (yellow warning) on my model on line:
var managedObjectContext = NSManagedObjectContext()
'init()' was deprecated in iOS 9.0: Use -initWithConcurrencyType: instead
What is causing this? How can I fix this issue?
Change it to:
var managedObjectContext = NSManagedObjectContext(concurrencyType: .MainQueueConcurrencyType)
You can download Apple's document to see more details.
NSConfinementConcurrencyType
Specifies that the context will use the thread confinement pattern.
Available in iOS 3.0 and later.
Deprecated in iOS 9.0.
Or Command+Click "NSManagedObjectContext" direct to NSManagedObjectContext.h:
#available(iOS, introduced=3.0, deprecated=9.0, message="Use another NSManagedObjectContextConcurrencyType")
case ConfinementConcurrencyType
#available(iOS, introduced=3.0, deprecated=9.0, message="Use -initWithConcurrencyType: instead")
public convenience init()
So it seems NSManagedObjectContext() use "ConfinementConcurrencyType" to init.When Apple deprecated "ConfinementConcurrencyType" in iOS 9.0,for the sake of coherence,Apple did not change the behavior of init() method.
So you'd better use another NSManagedObjectContextConcurrencyTypes( PrivateQueueConcurrencyType, MainQueueConcurrencyType) with another init method:
init(concurrencyType: NSManagedObjectContextConcurrencyType)
Apple changed how core data works. Don't use init(), use initWithConcurrencyType instead as required/recommended.
The underlying reason is related to thread safety and asynchronous access to core data objects.
In general, when Apple tells you that something is deprecated, you will always get a message like
'init()' was deprecated in iOS 9.0: Use -initWithConcurrencyType: instead
And clearly, what you need to do is follow the very strong hint that you were given: Don't use init. Read up what initWithConcurrencyType: does, figure out what is the right way for you to call it, and replace your init call with a call to initWithConcurrencyType:
Take this as an answer to the general question, because really, you should be able to figure this out yourself.
What is equivalent of setByAddingObject: in Swift. I have an NSSet property from Objective-C in Swift. But since Apple released Xcode 6.3 I have an error in this place:
Example:
NSSet *set;
object.set = object.set.setByAddingObject("text/html")
It produces error:
'Set<NSObject>' does not have a member named 'setByAddingObject'
Any idea, how to fix this? insert method doesn't work also.
Swift 1.2 added its own Set type, which is bridged over to Swift from Objective-C in a similar fashion to NSArray/Array and NSString/String. Try object.set.insert("text/html").