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").
Related
I am trying to convert swift code in following
NSLayoutConstraint.Attribute.height
I am using SkeletonView which it throws me error while executing.
I was not able to find the new replacement syntax of that
Type 'NSLayoutConstraint' has no member 'Attribute'
It all depends on the version of Swift you are using.
NSLayoutConstraint.Attribute.height // Swift 4.2
NSLayoutAttribute.height // Swift 3.0+
NSLayoutAttributeHeight // Swift 2?
Your swift version might not applicable with that syntax which used in swift 4.2
I am sure that your current swift version is low than that.
So, replace that line of code with
NSlayoutAttribute.height which applicable for swift version 3+ but below 4.2
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 subclass PFObject exactly as described here.
Then I create a new instance of the subclassed object without data, but since Swift 1.2 I get an error (It did work perfectly before):
var test = Armor(withoutDataWithObjectId: "1234567890")
-> Xcode complains:
"Incorrect argument label in call (have 'withoutDataWithObjectId:',
expected: 'className:')"
Why className? It should get the class name from the class function parseClassName
And I can under no circumstances create a new object with objectId but no data (which I MUST have to fetch it from the local datastore)
This is super annoying as my app doesn't compile any longer.
Update to the newest Parse SDK, available here.
The issue is caused due to necessary adaptions in the Parse SDK after the Swift language update. This issue also occurs with the most recent update to Swift 2.2. The newest (as of today) Parse SDK release 1.13.0 already fixes this.
UPDATE
Parse iOS SDK 1.13.0 has a typo and the function PFUser(withoutDataWithObjectId:) is called PFUser(outDataWithObjectId:). So upgrading the Parse SDK alone does solve this. Until this is fixed a temporary workaround would be to extend PFObject with a convenience initializer. To do this add a new Swift file to your project and insert this:
import Parse
extension PFObject {
convenience init(withoutDataWithObjectId objectId: String?) {
self.init(outDataWithObjectId: objectId)
}
}
It may be a little late to answer this question.
I use swift 1.2, and v 1.7.5 Parse SDK, and it works totally fine.
however, make sure you have define objective-c bridging header in "build setting".
and try to run it, even though there may reports some error
I'm porting some objective-c code to Swift. I need to check a bitmask but I'm getting an error:
MCOMessageFlag is not convertible to Bool
How should I be accessing this from Swift.
self.message.flags = NSNumber(int: self.message.flags.intValue & ~MCOMessageFlag.Flagged)
I'm using the MailCore2 library.
Edit:
Here is the line of objective-c I'm porting:
[self.message setFlags:[NSNumber numberWithInt: self.message.flags.intValue & ~MCOMessageFlagFlagged]];
Edit:
RawOptionSetType no longer implements BooleanType by default, so standard bitmask checks (if opt & .Option {...) only work if you add BooleanType protocol conformance manually.
I'm guessing this is my issue.
You can use .rawValue to get the value you need:
MCOMessageFlag.Flagged.rawValue