0

I am having this issue with my code that I have tried hard to fix, but with no results. Here you can see the code I am talking about:

.m

    SLComposeViewController *mySLComposerSheet;

    mySLComposerSheet = [[SLComposeViewController alloc] init];
    mySLComposerSheet = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeFacebook];
    [mySLComposerSheet setInitialText:[NSString stringWithFormat:@"Jeg har gennemført %i trænningspas med \"7 minutter\", som du kan hente her: http://bit.ly/7minutter", number]];
    [self presentViewController:mySLComposerSheet animated:YES completion:nil];

.h

@property (nonatomic, strong) SLComposeViewController *mySLComposerSheet;

When I analyse the code, it gives me the following errors:

  • Value stored in 'mySLComposerSheet' is never read
  • Incorrect decrement of the reference count of an object that is not owned at this point by the caller

I really hope that one of you can help me by taking a quick look at my code. Thank you!

rmaddy
  • 314,917
  • 42
  • 532
  • 579

1 Answers1

1

You don't need the line:

mySLComposerSheet = [[SLComposeViewController alloc] init];

composeViewControllerForServiceType: creates an instance of SLComposeViewController, thus the object returned by the alloc init is never used. See Apple's docs for more info:

http://developer.apple.com/library/ios/#documentation/NetworkingInternet/Reference/SLComposeViewController_Class/Reference/Reference.html

stevekohls
  • 2,214
  • 23
  • 29
  • Okay thanks! And now I have to write: _mySLComposerSheet where I previously just was writing mySLComposerSheet right? – Mathias Mønsted Jul 03 '13 at 17:39
  • Assuming you are using Xcode 4.4 or above, you don't need the`SLComposeViewController *mySLComposerSheet;` line in your `.m` file. And yes, just use `_ mySLComposerSheet`. It will be created for you automatically. – stevekohls Jul 03 '13 at 17:44
  • Mathias, if this answer worked for you, select the checkmark next to the answer to accept it. Welcome to Stack Overflow! – stevekohls Jul 03 '13 at 18:18
  • Per my comment on your other question: http://stackoverflow.com/questions/17454754/xcode-potential-leak-of-an-object-stored-into-notification, use `self.mySLComposerSheet` instead of accessing the ivar directly. – stevekohls Jul 03 '13 at 21:19