Cannot assign value of type UnsafeMutablePointer ObjCBool in Swift

YichenBman

I'm unfamiliar with Objective C.

I'm using a private framework and need to be able to change one of the properties from within my Swift code.

The property is declared in Objective C this way:

@property (nonatomic, assign) BOOL *isSSNField;

in swift I am trying to change the value of the property this way:

myClass.isSSNField = true

I am getting this error

Cannot assign a value of type 'Bool' to a value of type 'UnsafeMutablePointer<ObjcBool>'

I'm not sure where to go from here, or why I'm getting this error at all

matt

I've never seen anything like the situation you describe, and personally I'm tempted to say the situation doesn't exist; I have never seen a BOOL* property or ivar in Objective-C in my life (and I'm darned old, believe me). However, if you insist: I haven't tested this, but I think you could say something like this:

var ok = UnsafeMutablePointer<ObjCBool>.alloc(1)
ok[0] = false // or true
let val = ok
myClass.isSSNField = val

However, although I think that will compile, I'm rather unclear on what the implications of doing it would be. It could cause the universe to collapse to a black hole, so be careful.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Swift: Cannot convert value of type 'UnsafeMutablePointer' to expected argument type 'UnsafeMutablePointer'

Cannot invoke 'enumerateObjects' with an argument list of type '((AnyObject!, NSInteger, UnsafeMutablePointer<ObjCBool>) -> ())'

error: cannot convert value of type 'ObjCBool' to expected argument type 'Bool' on Swift 4.1.2 and Kitura on Ubuntu 16.04

Cannot assign value type mismatch swift

Swift Cannot Assign to immutable value of type NSData

Cannot assign a value of type 'AnyObject?' to a value of type 'String!' - Swift with Parse

Swift: Cannot assign a value of type 'Any' to a value of type 'AnyObject?'

Swift: Cannot assign a value of type 'int' to a value of type 'int?' Error

Cannot assign value of type 'String.Type' to type 'String?' - Swift

Swift & Firebase Cannot assign value of type 'AuthDataResult?' to type 'User?

Swift 4: Cannot assign value of type '(_) -> Void' to type '(() -> ())?'

Swift: "Cannot assign value of type 'Item!' to type 'Item!"

swift error "cannot assign value of type 'interface controller' to type HKWorkoutSessionDelegate'

swift Cannot assign value of type 'Int' to type 'String'

Cannot assign value of type 'Date?' to type 'String?' Swift 3

Cannot assign value of type '[ResultItem]?' to type 'String?' Swift 5

Error in swift playground: Cannot assign value of type 'Int' to type '[Int]'

Cannot assign a value of type 'PFObject' to a value of 'PFObject!', Swift, Xcode

Cannot convert value of type 'SecCertificate' to expected argument type 'UnsafeMutablePointer<UnsafeRawPointer?>!'

Swift cannot assign immutable value of type [CLLocationCoordinate2D]

swift Cannot convert value of type 'in_addr_t' (aka 'UInt32') to expected argument type 'UnsafeMutablePointer<in_addr_t>!'

assign array in swift machine learning Cannot assign value of type '[[String]]' to type 'String?'

Convert String type array to Float type array in swift Cannot assign value of type 'String' to subscript of type 'Double'

UnsafeMutablePointer to expected argument type UnsafeMutablePointer<_> in Swift 3

Cannot assign value of generic type

Swift2 to Swift3 error - Cannot assign value of type 'NSDictionary?' to type 'AddressModel'

In Swift fileExistsAtPath(_ path: String, isDirectory isDirectory: UnsafeMutablePointer<ObjCBool>) -> Bool accepts single parameter only

Swift UI + Cannot assign value of type 'JsonResponse' to type 'JsonResponse.Type'

Cannot invoke initializer for type 'UnsafeMutablePointer'