Questions tagged [unsafe-unretained]
17 questions
7
votes
1 answer
Is there way to check a `unowned` (actually `unowned(safe)`) reference has been deinited?
Is there any way to check an unowned(safe) Swift reference for "availability"? So, I am looking for a hypothetical function like isReferenceAccessible in this example:
func someMethod() {
someAsyncOperation(parameters) { [unowned(safe) self] in
…

Valentin Shergin
- 7,166
- 2
- 50
- 53
3
votes
1 answer
Converting Project To ARC With Double Indirection Pointer Assign
I'm trying to convert a project to ARC. The project has a Directed Acyclic Word Graph, which basically means lots of double indirection pointers everywhere.
This is proving quite a challenge to convert to ARC, and one issue in particular has me…

Max MacLeod
- 26,115
- 13
- 104
- 132
3
votes
2 answers
How to manage unsafe_unretained ivars/properties?
I started objective-c and iOS a couple of weeks ago (worth bearing in mind), and I apologise in advance for the awful diagram!!
The above diagram shows the structure of my calls to a webservice. Thin arrows denote an object creating another…

dark_perfect
- 1,458
- 1
- 23
- 41
3
votes
3 answers
Should I use __unsafe_unretained for temp variables?
Let's say I want to create a temporary variable, e.g.:
To point to another long-living variable:
__unsafe_unretained UIView *tableHeaderView = self.tableView.tableHeaderView;
To point to an object I just created.
__unsafe_unretained UIView…

ma11hew28
- 121,420
- 116
- 450
- 651
3
votes
1 answer
What's the difference between takeUnretainedValue and takeRetainedValue?
What's the difference between takeUnretainedValue and takeRetainedValue? Based on Apple's documentation:
Both of these methods return the original, unwrapped type of the
object. You choose which method to use based on whether the API you
are…

Aнгел
- 1,361
- 3
- 17
- 32
3
votes
2 answers
malloc object lifetime with __unsafe_unretained typecast
I'm new to Objective-C and ARC, and have been searching and reading for hours without finding an answer. The code does what I want it to do, but I want to know that it doesn't rely on favorable conditions. Here's a simplified version of my…

Anders Sjöqvist
- 3,372
- 4
- 21
- 22
2
votes
2 answers
Is it really a good option to use ARC for IOS 4.0 where there is no weak property
I am working on a ARC based project. My project is targeted IOS 4.3. Since there is no weak pointer for the version < IOS 5.0, I have to use unsafe_unretained which may cause dangling pointers.
Now I am thinking, is it really, good option to use ARC…

Raj
- 1,119
- 1
- 15
- 32
1
vote
1 answer
Data withUnsafeBytes is deprecated
I got this code here from an app I am working on. I inherited this code when the BLE guy left the team. I am not good with low level stuff and Data stuff. I am UI/UX front end person, and now I do need to get my hands dirty. This code is now a bit…

Pascale Beaulac
- 889
- 10
- 28
1
vote
0 answers
Memory management of static consts in Objective-C
I was watching the F8-2016 Building iOS Tooling at Facebook Scale video, when I've noticed an interesting code part at 7:01.
Facebook defined a static constant in Objective-C this way:
static __unsafe_unretained NSString * const kAuthorKey =…

Infinite Possibilities
- 7,415
- 13
- 55
- 118
1
vote
3 answers
New behaviour for IBOutlet creation in Xcode 6
I remember that in Xcode 5 if you dragged a view from a storyboard to the code it would create a property with weak attribute. Now in Xcode 6 it uses unsafe_unretained as a default. What may be the cause of that change?

Tomasz Bąk
- 6,124
- 3
- 34
- 48
1
vote
3 answers
property for ivar that points to two-dimensional array of pointers to NSStrings
I want to create a class that contains a dynamic, two-dimensional c-array of pointers to NSStrings. I know I can simulate a two-dimensional array using an NSArray containing multiple NSArrays, but if possible I'd like to do this using a traditional…

StephenAshley.developer
- 1,054
- 1
- 9
- 14
1
vote
1 answer
Returning __unsafe_unretained pointer to released object in Objective C causes a crash
Problem:
I have an __unsafe_unretained id pointer that points to an already released object. So far so good, as long as I do not "use" the pointer at all (in particular, I do not call any method through the pointer). However, when I try to return…

Pang
- 9,564
- 146
- 81
- 122
0
votes
1 answer
dealing with autoreleased objects within dispatch_sync
What is the best solution to avoid bad access in this kind of situations ?
__block NSString* string;
dispatch_sync(dispatch_get_main_queue(), ^{
string = [NSString stringWithString:@"I'm autoreleased!"];
});
NSLog(@"My string is: %@",…

vtruant
- 273
- 1
- 12
0
votes
2 answers
why delegates should be unsafe_unretained and not weak?
I added ARC to an app I'm working on. Unfortunately, it crashes. I found that the automatic script which updates all apps to ARC gave __unsafe_unretained qualifier to all id< protocolName> type.
Why isn't it a weak type? I have deployed the app and…

yonivav
- 994
- 11
- 18
0
votes
2 answers
To support iOS 4.3, use "assign" instead of weak, but Interface Builder uses unsafe_unretained?
To support iOS 4.3 with ARC, I think the proper way is to use assign:
@property (assign, nonatomic) UIView *view;
@property (assign, nonatomic) MYNode *node;
Is that correct? I also see the following in Apple's doc for Transitioning to ARC:
For…

Jeremy L
- 3,770
- 6
- 41
- 62