Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Basically you got all your memory management wrong.</p> <p>First of all, allocating an object and putting it to a local variable will make the object disappear after the method ends. So after the end of your</p> <pre><code>- (void)viewDidLoad </code></pre> <p>method your </p> <pre><code>KBDataInitializer *data = ... </code></pre> <p>is already out of scope again. Together with it, the </p> <pre><code>@property (strong, nonatomic) NSManagedObjectContext *dataContext; </code></pre> <p>is gone.</p> <p>Second, the songs are </p> <pre><code>@interface KBSong : NSManagedObject </code></pre> <p>which makes them dependent on their NSManagedObjectContext.</p> <p>These are the basics, the short way to fix your current problem is:</p> <p>KBHomeController.h:</p> <pre><code>#import &lt;UIKit/UIKit.h&gt; @class KBDataInitializer; @interface KBHomeController : UIViewController&lt;UITableViewDataSource,UITableViewDelegate&gt; { NSArray *songs; } @property (nonatomic, strong) KBDataInitializer *data; @end </code></pre> <p>KBHomeController.m:</p> <pre><code>- (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view from its nib. self.data = [[KBDataInitializer alloc]init]; //Use for import updated new Songs [self.data importData]; songs = [self.data getAllSongs]; ... } </code></pre> <p>But this only helps with your current problem. To understand what you did wrong, read <a href="https://developer.apple.com/library/mac/documentation/Cocoa/Conceptual/MemoryMgmt/Articles/MemoryMgmt.html" rel="nofollow">https://developer.apple.com/library/mac/documentation/Cocoa/Conceptual/MemoryMgmt/Articles/MemoryMgmt.html</a> . And <a href="http://www.raywenderlich.com/2657/memory-management-tutorial-for-ios" rel="nofollow">http://www.raywenderlich.com/2657/memory-management-tutorial-for-ios</a> . And <a href="http://www.raywenderlich.com/5677/beginning-arc-in-ios-5-part-1" rel="nofollow">http://www.raywenderlich.com/5677/beginning-arc-in-ios-5-part-1</a> . Plus their follow ups. All of it. And also try to understand it.</p> <p>Also please note I would use a <a href="https://developer.apple.com/library/ios/documentation/CoreData/Reference/NSFetchedResultsController_Class/Reference/Reference.html" rel="nofollow">NSFetchedResultsController</a> for that task. </p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload