Should we point to an NSManagedObject entity with weak instead of strong pointer?
Posted
by
Jim Thio
on Stack Overflow
See other posts from Stack Overflow
or by Jim Thio
Published on 2012-11-06T04:50:05Z
Indexed on
2012/11/06
5:00 UTC
Read the original article
Hit count: 214
I think because NSManagedObject is managed by the managedObject context the pointer should be weak.
Yet it often goes back to 0 in my cases.
for (CategoryNearby * CN in sorted) {
//[arrayOfItems addObject:[NSString stringWithFormat:@"%@ - %d",CN.name,[CN.order intValue]]];
NearbyShortcutTVC * tvc=[[NearbyShortcutTVC alloc]init];
tvc.categoryNearby =CN;
// tvc.titleString=[NSString stringWithFormat:@"%@",CN.name];
// tvc.displayed=CN.displayed;
[arrayOfItemsLocal addObject:tvc];
//CN
PO(tvc);
PO(tvc.categoryNearby);
while (false);
}
self.arrayOfItems = arrayOfItemsLocal;
PO(self.categoriesNearbyInArrayOfItems);
[self.tableViewa reloadData];
...
Yet somewhere down the line:
tvc.categoryNearby
becomes nil.
I do not know how or when or where it become nil.
How do I debug this? Or should the reference be strong instead?
This is the interface of NearbyShortcutTVC by the way
@interface NearbyShortcutTVC : BGBaseTableViewCell{
}
@property (weak, nonatomic) CategoryNearby * categoryNearby;
@end
To make sure that we're talking about the same object I print all the memory addresses of the NSArray
They're both the exact same object. But somehow the categoryNearby property of the object is magically set to null somewhere.
self.categoriesNearbyInArrayOfItems: (
0x883bfe0,
0x8b6d420,
0x8b6f9f0,
0x8b71de0,
0xb073f90,
0xb061a10,
0xb06a880,
0x8b74940,
0x8b77110,
0x8b794e0,
0x8b7bf40,
0x8b7cef0,
0x8b7f4b0,
0x8b81a30,
0x88622d0,
0x8864e60,
0xb05c9a0
)
self.categoriesNearbyInArrayOfItems: (
0x883bfe0,
0x8b6d420,
0x8b6f9f0,
0x8b71de0,
0xb073f90,
0xb061a10,
0xb06a880,
0x8b74940,
0x8b77110,
0x8b794e0,
0x8b7bf40,
0x8b7cef0,
0x8b7f4b0,
0x8b81a30,
0x88622d0,
0x8864e60,
0xb05c9a0
)
© Stack Overflow or respective owner