(__bridge__transfer NSData*) returns _NSCFArray instead of NSData - nsdata

I have some code I am using for keychain management. The SecItemCopyMatching method returns the result in (CFTypeRef *) type called foundDict, which is passed as a reference to the SecItemCopyMatching method. Then I am using (__bridge_transfer NSData*) to bridge from the CFTypeRef* to an NSData* (into "result" variable).
So I was expecting that the result variable will of course be of type NSData, because I declared it so, and used the bridge to convert CFTypeRef* to NSData*.
But when I want to convert the NSData into a string using the NSString method: initWithBytes:length:encoding, I get a runtime error that tells me
"[__NSCFArray bytes]: unrecognized selector set to instance.."
When I looked in the debugger in Xcode , I can see why it is complaining because the "result" variable was converted from NSData to __NSCFArray after the "bridge" statement. And since __NSCFArray is an array type it does not support a method called "bytes" and thus the runtime complains
So, I don't understand why internally this conversion is happening from NSData to __NSCFArray
And most importantly, how is the proper way to convert the results returned by the "SecItemCopyMatching" which is of type CFTypeRef to NSData. The funny thing is that i am following the exact same code suggested by Apple in its keychain wrapper example at KeychainWrapper Sample code
Any thoughts?
I am attaching an image of the debugger:

Related

Im trying to convert a wxVector<m_Product*> element to a wxArrayString without any result (Exception thrown at...)

The thing is, im trying to transform the data of a class that is the name of the products. That name is into a std::string format and it should be easy to just make a simple for to put it in a wxArrayString right? but the thing is that the vector where is stored the information its like "corrupted" or "private" i'd like to say.
By the way i tried this function made by me:
BUT i do get this message when i try to use that function
ERROR:
Any idea why is this happening? i mean in the previous line i used de m_GlobalProductVector to print its size to the console...

Why does dispatch_queue_create give an EXC_BAD_ACCESS error in Swift?

I am porting some code from C++ to Swift that used Grand Central Dispatch, and I am finding a curious error with dispatch_queue_create seemingly not working at all.
For instance, in my C++ base class header, I would declare
dispatch_queue_t m_WorkQ;
and in the initializer, put
m_ResultQ = dispatch_queue_create("com.myapp.mHitsUpdateQueue", 0);
... and everything was glorious.
I've tried this in Swift, in my class, declaring this at class level:
var resultQueue: dispatch_queue_t
... and in the initalizer, I have (among others) the line
resultQueue = dispatch_queue_create("com.myapp.mHitsUpdateQueue", 0)
... and it compiles and starts up fine, but gives me an immediate runtime error of EXC_BAD_ACCESS (code=1, address = 0x37) on the above line
To determine if it's anything else I've done, I created a command line tool application consisting only of the following code:
import Foundation
var thisQueue = dispatch_queue_create("com.myApp.mHitsUpdateQueue", 0)
println(thisQueue.description)
... and sure enough, I get the above error right on the "thisQueue" assignment line. So I'm pretty sure there's something really obvious about Swift and GCD queue creation that I'm missing.
Can anyone please help me out here?
The second argument of dispatch_queue_create() has the type
dispatch_queue_attr_t, which is declared as
typealias dispatch_queue_attr_t = NSObject
You have to pass DISPATCH_QUEUE_SERIAL or nil for a serial queue
(or DISPATCH_QUEUE_CONCURRENT for a concurrent queue):
var thisQueue = dispatch_queue_create("com.myApp.mHitsUpdateQueue", DISPATCH_QUEUE_SERIAL)
In C(++), 0 can be passed instead of a NULL pointer.
The Swift compiler, however, wraps the integer 0 into an NSNumber object
so that it can be passed to the function expecting an NSObject
parameter. That causes the runtime exception because NSNumber is
not a valid attribute. So passing 0 or nil is
significantly different in Swift.

Storing c++ structs/objects in NSData

I am developing an iOS with OpenCV.
OpenCV is an Open Source Image Library and works with C++.
I want to store some data from the Library in an NSData object.
Is it possible to convert a c++ struct to NSData without losing the object?
- (void)addMat:(cv::Mat)mat andImageName:(NSString *)name {
self.myMat = [NSData dataWithBytes:&mat length:sizeof(mat)];
self.imageName = name;
}
Now I'm using the code above.
But this NSData only stores the pointers not the actual data.
When I try to get the object back I
pointer being freed was not allocated
* set a breakpoint in malloc_error_break to debug
My data should be stored in a SqLite Database.
Do you have an idea to convert everything ?
I tried to convert every single property. This worked for some properties quite well and for others it didn't work.
I hope you could help me.
Thank you.
Greetings,
Alexander Heinrich
You may write bytes from objects inside data, but it doesn't store object. For example object can have pointers at other objects and they can become invalid after some time, but yours NSData copy will not know about that.
You should turn on Objective-C++ and work direct with C++ structures/classes.

Setting input parameter for a method

I have an object called X with a method GET_BANK, like in the picture below:
I want to call the function GET_BANK and I am trying to set the input parameter BLZ with a certain value.
I don't quite understand the data structure that is presented here and how I can access it.
At this point my code looks like this (simple version):
data: testobj type ref to ZCO_BLZSERVICE_PORT_TYPE .
data: input type ZGET_BANK .
input-BLZ = '10070000'.
I think the error that I am getting "The data object "INPUT" does not have a component called "BLZ"." is not relevant as I obviously have no idea on how to set the BLZ parameter.
Edit: Getting to BLZ can be done by chaining multiple parameters / objects:
input-PARAMETERS-BLZ = '10070000'.
As far as I can see, your input data should refer to TYPE ZGET_BANK_TYPE. Try double-clicking the field with that content in the screen you showed to see whether it leads to a structure with a component named BLZ.

Passing an arraylist as a struct property from a webservice

I have a web service that sends a struct to a client program.
I need to pass an arraylist of string values as one of the properties of this struct, but by the time it gets to the client program its type is 'object'. Once it gets back to the client program, how can I convert this Object datatype back into the arraylist?
Unless you're stuck at .NET 1.1, don't use ArrayList. Try returning a List<YourStruct> instead.
The problem was the way I was attempting to explicitly create an arraylist and then setting it equal to the returned property from the struct; here's the correct way to do it - some weird VB implicit thingy. (sorry, never drank the VB kool-aid)
Dim ReturnedArrList As New ArrayList(structReturned.arrReturnedArrayList)