Questions tagged [weak]

128 questions
1
vote
1 answer

Is it bad practice to use the weak attribute to write test code in c?

Is it good practice to use the weak attribute in production code so that for test code one can override functions?
floquet22
  • 323
  • 2
  • 15
1
vote
0 answers

my LogFunc macro captures self and might cause retain cycles

I use a simple macro in my code, I find it very convenient and useful #define LogFunc NSLog(@"%p %s",self,__func__); It gives me the self pointer address and the called function. @implementation MyGreatClass -(void)foo { LogFunc } -(void)bar…
Jakob
  • 1,126
  • 3
  • 16
  • 38
1
vote
3 answers

Objective-C: work with weak references

I have a few classes: Book, Publisher, Author and Genre. So here is the main class Book.h: #import "Publisher.h" #import "Author.h" #import "Genre.h" @interface Book : NSObject @property (nonatomic, strong) NSString *bookName; @property…
Oracle
  • 13
  • 5
1
vote
1 answer

iOS : instance variable in block

My Object have some instance variable , like this: @interface MyObject : NSObject { @private NSDictionary * resultDictionary ; } this is the method : - (void) doSomething { __weak typeof(self) weakSelf = self ; [TaskAction…
user5465320
  • 719
  • 2
  • 7
  • 15
1
vote
0 answers

Can I call a C++ extern "C" function in a cpp from another cpp?

I'm working with a C++ class which I CANNOT modify that declares an extern "C" function from within a cpp file (not a .h). How do I call that function from another cpp file? To further complicate matters, the function is declared with the "weak"…
BuvinJ
  • 10,221
  • 5
  • 83
  • 96
1
vote
1 answer

weak Learners based on distributions : Decision stump

I need to boost the decision stump weak classifier. So for every iteration, I'll have to train the weak classifier based on certain weights. I will then update the weights after every iteration. So far I have understood. But the unclear part to me…
user 3317704
  • 925
  • 2
  • 10
  • 21
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

nil __weak self - Why it's happend?

I want to use weak self in blocks, but in block this weakSelf become nil Just created, before block (try to use different variants) - looks like all ok But later in block - each variant nil Whats done wrong? Can anyone explain? EDIT SPHVideoPlayer…
hbk
  • 10,908
  • 11
  • 91
  • 124
1
vote
1 answer

NSTimer is retaind and NSButton action is not retained

My question is why [myButton addTarget:self action:@selector(myAction) forControlEvents:UIControlEventTouchUpInside]; it is not retain and mytimer = [NSTimer scheduledTimerWithTimeInterval:1.0f target:self …
Sishu
  • 1,510
  • 1
  • 21
  • 48
1
vote
2 answers

__weak example in ARC code

I'm trying to understand how does __weak works in ARC code. Here is my example: NSString *string = @"Hi!"; //1 __weak NSString *secondString = string; //2 string = @"Hello world!"; //3 NSLog(@"STR: %@", secondString); //4 I expect that NSLog…
Maria
  • 755
  • 1
  • 11
  • 29
1
vote
1 answer

Is Xamarin UITableView Source weak or strong?

Can this cause a memory leak in C# Xamarin or not? i.e. can MyViewController be released or does it have a circular reference, preventing it? In MyViewController: this.TableView.Source = new ViewSource(this); public class ViewSource :…
Bbx
  • 3,184
  • 3
  • 22
  • 33
1
vote
3 answers

Custom delegate issue

I'm working with a custom delegate and protocol functionality. I implemented my class like follows: @protocol MyDelegate @required - (void)update; @end @interface MyHandlerClass : NSObject { id delegate; } @property…
Midhun MP
  • 103,496
  • 31
  • 153
  • 200
1
vote
3 answers

ARC IBOutlet storage type iOS limitations

I'm aware that with Xcode now, it is recommended to use ARC, however I've read a bit about it not being compatible with iOS 4.x, at least when using __weak. When I create an IBOutlet it gives the choice of weak or strong as the storage type, does…
Dayn Goodbrand
  • 611
  • 7
  • 16
1
vote
2 answers

How to use the "weak" in ARC?

I use: @property(nonatomic, weak) IBOutlet UIView *videoView; there is a warning: Property 'videoView' requires method 'videoView' to be defined - use @synthesize, @dynamic or provide a method implementation in this class implementation Then I…
Aevit
  • 21
  • 5
0
votes
0 answers

Weak function gets executed when its file is linked first

I have 2 files: strong.cc #include void foo(){ printf("Strong is here\n"); } weak.cc #include void __attribute__((weak)) foo(); void foo(){ printf("Weak is here\n"); } and then my main.cc #include extern void…
1 2 3
8 9