Questions tagged [nspointerarray]

NSPointerArray is a mutable collection modeled after NSArray but it can also hold NULL values, which can be inserted or extracted (and which contribute to the object’s count).

NSPointerArray is a mutable collection modeled after NSArray but it can also hold NULL values, which can be inserted or extracted (and which contribute to the object’s count). Moreover, unlike traditional arrays, you can set the count of the array directly. In a garbage collected environment, if you specify a zeroing weak memory configuration, if an element is collected it is replaced by a NULL value.

The copying and archiving protocols are applicable only when a pointer array is configured for object uses.

The fast enumeration protocol (that is, use a pointer array in the for...in language construct—see “Fast Enumeration Makes It Easy to Enumerate a Collection” in Programming with Objective-C) will yield NULL values that are present in the array. It is defined for all types of pointers although the language syntax doesn’t directly support this.

Reference: https://developer.apple.com/library/mac/documentation/cocoa/reference/foundation/classes/NSPointerArray_Class/Introduction/Introduction.html

14 questions
229
votes
18 answers

How do I declare an array of weak references in Swift?

I'd like to store an array of weak references in Swift. The array itself should not be a weak reference - its elements should be. I think Cocoa NSPointerArray offers a non-typesafe version of this.
Bill
  • 44,502
  • 24
  • 122
  • 213
14
votes
3 answers

NSPointerArray weird compaction

I have a weak NSPointerArray with some NSObject that has been released. Before calling compact what I see is: (lldb) po [currentArray count] 1 (lldb) po [currentArray pointerAtIndex:0] (lldb) po [currentArray allObjects] <__NSArrayM…
Łukasz Sromek
  • 3,637
  • 3
  • 30
  • 43
4
votes
2 answers

With NSPointerArray, how to iterate over opaque pointers?

I recently discovering these classes like NSMapTable and NSPointerArray, which work like the traditional collections, but also let you store weak references or plain old C pointers. Unfortunately it looks like you can't use the for...in syntax to…
Rob N
  • 15,024
  • 17
  • 92
  • 165
2
votes
1 answer

How to add object to an NSPointerArray?

I want to store weak references in an NSPointerArray but I get an error: public var objectWithReloadFRC = NSPointerArray(options: NSPointerFunctionsWeakMemory) objectWithReloadFRC.addPointer(self) //self is an UIViewController subclass tried this…
János
  • 32,867
  • 38
  • 193
  • 353
2
votes
1 answer

NSMutableArray with [NSNull null] vs NSPointerArray

I am writing a chess program that stores all the pieces in an NSMutableArray with [NSNull null] representing empty spaces. I just found out about NSPointerArray and was wondering if I should switch over to that instead. Basically, what are the…
aeubanks
  • 1,261
  • 1
  • 12
  • 12
1
vote
1 answer

How to hand over values to a double-pointer and print the values out as if it would be an multidimensional array? (C)

I have following struct defined which I can not change: typedef struct _content { int length; char **lines; } content_t; I initialized it in the main function like that: struct _content cont; cont.length =…
D.J.A.
  • 75
  • 1
  • 7
1
vote
1 answer

How to grow 2d dynamically allocated string array in C++11 ?

So, I have been doing this question : Q. Write a program that lets users keep track of the last time they talked to each of their friends. Users should be able to add new friends (as many as they want!) and store the number of days ago that they…
0
votes
0 answers

Why I can't use printf() with variable 'i' as argument

` void DisplayFood(int*NumOfFood,int*Rno,char *Names[],int*Price,int*Quantity,char*mfg[],char*exp[]) { int i =0; for(i=0;i<*NumOfFood;i++) { printf("\n%-20d",Rno[i]); printf("%-20s\t",Names[i]); …
0
votes
1 answer

C Pointer to arrays

I am learning pointers in C. When I declare : char c1[] ="hello"; c1[0] = c1[1]; printf("%s\n", c1); It prints out eello But when I do the following: char * c2="hello"; c2[0] = c2[1]; printf("%s\n", c2); it compiles in C# but the program…
MAK1647
  • 11
  • 3
0
votes
1 answer

I encountered some thing weird code in Dynamic memory allocation for 2D arrays in C++? please explain me what is this?

code:- p = new int *[5]; where p is a pointer & declared as int **P; Please explain me that why there is a * in between new and [5].
MolyOxide
  • 59
  • 1
  • 1
  • 11
0
votes
1 answer

Weak object array in Swift

I would like to create an object array as a property of another class in Swift, such as: class person{ var livingInHouse : house name : String } class house{ var personArray : [person] } My constraints are: I would like to easily access the…
darksider
  • 3
  • 1
  • 2
0
votes
1 answer

NSPointerArray basics

I'm trying to get a hang of the NSPointerArray-class, and have a very specific question regarding table view cells. If I stored the pointer to a cell that is being pressed in a NSPointerArray, will I be able to trace it back to the original cell…
martin
  • 1,894
  • 4
  • 37
  • 69
0
votes
1 answer

Accessing objects using NSPointerArray?

I have an NSPointerArray and in one of my methods, I want to access the objects stored in that NSPointerArray (as I have to use one of the object's properties). I don't want to create a new NSArray with the allObjects method as that will be…
-1
votes
2 answers

how to find maximum value of UnsafeMutablePointer with bufferSize of data type UInt32 in swift?

I am new to swift and working on a project where i had to visualize audio waves! I am using EZAudio pod where to plot the waves on the screen a function UpdatePlot is used and in parameter a UnsafeMutablePoiter> is passed I want the maximum value…