How to check bitfields (SCNetworkReachabilityFlags in particular) for flags in Swift?
That error is actually complaining not about the arguments of your flags-check, but about the return value. An if
statement expects a boolean (or at least something conforming to Logical
), but the &
operator for two Int
values returns an Int
. You just need a comparison in your if
statement:
let flags = kSCNetworkReachabilityFlagsReachable
if 0 != flags & kSCNetworkReachabilityFlagsReachable {
println("flags contains kSCNetworkReachabilityFlagsReachable")
}
Since SCNetworkReachabilityFlags
and the constants are (strangely) of different types, you'll need to do some casting to make the comparison work:
let reachabilityFlags:SCNetworkReachabilityFlags = SCNetworkReachabilityFlags(kSCNetworkReachabilityFlagsReachable)
if 0 != reachabilityFlags & SCNetworkReachabilityFlags(kSCNetworkReachabilityFlagsReachable) {
println("reachabilityFlags contains kSCNetworkReachabilityFlagsReachable")
}
Wrapping libcups C library in Swift
IMHO the best way to work with such C libraries in Swift is to work with them in Objective-C. Nevertheless, the main issue seems to be that you are not writing back changes to userData, that's why you always get your initial value. You need to update it in your callback like this
let userDataPointer = user_data!.assumingMemoryBound(to: my_user_data_t.self)
var userData = userDataPointer.pointee
...
// make some changes to userData
userDataPointer.pointee = userData
return 1
Also there seems to be some differences between your C code and the Swift one, like checking flags with 'flags == CUPS_DEST_FLAGS_REMOVED' which, in general, is incorrect way to check flags, and comparing result of cupsEnumDests with 1 when in the original code you check that result is not 0.
Reachability framework is not working fine while detecting interface type when there is multiple network interface
This issue has been fixed. Posting it so that user's can get help. The main problem was that I was passing NULL in zeroAddress structure. After assigning my network interface address in the structure it passed all the cases and determined network interface type correctly.
Related Topics
Swift: Is Correct to Use Stored Properties as Computed Properties
Xcode 8/Swift 3 and Installing Apps on iPhone 4 Running iOS 7
Cannot Subscript a Value of [Anyobject]? with an Index of Type Int
How to Add a Lock Screen Widget (Requiring iOS 16) and Still Support iOS 15
How to Change Tabbar Icon Color in iOS
Uiactivityviewcontroller => Launchservices: Invalidationhandler Called
iOS Getting My Location Regularly and Setting Button to Get My Location - Google Map Not Working
Swift (Beta 3) "Nsdictionary? Does Not Conform to Protocol 'Equatable'"
How to Access All Images in a .Xcassets at Once
Swift 3: Transfer Utility Enumeratetoassignblocks Method Signature
CSS Flexible Box Layout on Ipad
Start Position of Table View Is Wrong in Simulator, and Is Not The Same in Storyboard
Resize All Subview in Scrollviewdidzoom
Is Calling Cellforrowatindexpath: Ever Practical
How to Schedule Mail Using Gmail API
Conforming to UItableviewdelegate and UItableviewdatasource in Swift