NSMutableArray problem

I have a problem with NSMutableArray. I have many variations of "CFSocketRef" in my program. I want to store this in NSMutableArray, but I cannot. Can you help me? Thanks and sorry for my english XP

My code:

CFSocketRef     socketAccept;
NSMutableArray  *arrayIP = [[NSMutableArray alloc] init];



self.socketAccept = CFSocketCreateWithNative(NULL,
                                  fd, 
                                  kCFSocketDataCallBack,
                                  AcceptDataCallback, 
                                  &context);

[arrayIP    addObject:(id)self.socketAccept];

      

+2


a source to share


2 answers


You can put CFSocketRef

in NSMutableArray

by wrapping it inside NSValue

:

CFSocketRef socketAccept;
NSMutableArray *arrayIP = [[NSMutableArray alloc] init];
socketAccept = ...
NSValue *val = [NSValue valueWithPointer:socketAccept];
[arrayIP addObject:val];

      



Use pointerValue

to get the value:

CFSocketRef socketAccept = (CFSocketRef) [val pointerValue];

      

+3


a source


Insert CFSocketRef

in NSValue

using method valueWithPointer:

, then insert NSValue

in array.



0


a source







All Articles