Reputation: 6033
In Obj-C I could use the preprocessor macro CMTIME_IS_VALID
for this.
In Swift, preprocessor macros don't exist, so I can't use this. Any other easy way to do this check? Of course, I could rewrite the definition of the macro below, but isn't there any better way to do this?
#define CMTIME_IS_VALID(time) ((Boolean)(((time).flags & kCMTimeFlags_Valid) != 0))
Upvotes: 6
Views: 2763
Reputation: 540055
You can define a custom extension with a read-only computed property isValid
:
extension CMTime {
var isValid : Bool { return (flags & .Valid) != nil }
}
which is then used as
let cm:CMTime = ...
if cm.isValid { ... }
Update: As of Swift 2 / Xcode 7, CMTIME_IS_VALID
is imported
into Swift as
func CMTIME_IS_VALID(time: CMTime) -> Bool
therefore a custom extension is not needed anymore.
If you want to define a isValid
property then the syntax in
Swift 2 would be
extension CMTime {
var isValid : Bool { return flags.contains(.Valid) }
}
Upvotes: 15