UA-17470720-3

Jump to content


Photo
- - - - -

Best way to make a lite version of an app made with SC?

data-definitions core-data

  • Please log in to reply
5 replies to this topic

#1 fabiensen

fabiensen

    Jr. Member

  • STV 4.0 Std
  • PipPip
  • 23 posts
Reputation: 5
Good

Posted 06 June 2015 - 04:00 AM

Hi,

 

nowadays we all know that almost no app is selling if there is only a paid version or, at least, it takes a much longer time to get noticed.

 

I am here to ask, which is the best way on a working app made with SC to generate a lite version of it? When I say lite, I mean that, in the main entity you can add up to a certain number of records. 

So, it would be as in the Task app, you could add up to 5 tasks in the lite version. 

 

I imagined that there should be a check when the + button is tapped. I discovered there exists a didTapAddButtonItem action, but I found no sample in the forum nor in the documentation. 

But even if I used that, how could I block the model to reach the detail view if 5 tasks are already in the DB. Sure I can count them by querying the DB, not a problem, but I can not figure how to block the flow of the app and finally show an alert (in order to say that you can add up to 5 tasks). 

 

So, being very common for us developers, to go out with a lite and a full version, does anyone know how to get the lite one in a few steps?

 

Thank you very much

Fabio



#2 wizgod

wizgod

    I'm what you guys call a User

  • STV 5.0 Pro
  • PipPipPipPipPipPipPip
  • 575 posts
  • LocationThe Grid
Reputation: 149
Popular

Posted 06 June 2015 - 08:47 AM

Greetings Program!

Have a look at this thread; Tarek's solution should do the trick for you:

http://sensiblecocoa...-button/?p=7571

Wg

Edited by wizgod, 06 June 2015 - 08:50 AM.

  • Tarek likes this

P.S. I love Swift... talk Swift.. Never too old school to learn yet another programming language. LOL! ;-)


#3 fabiensen

fabiensen

    Jr. Member

  • STV 4.0 Std
  • PipPip
  • 23 posts
Reputation: 5
Good

Posted 07 June 2015 - 01:15 AM

Hi,

 

thanks for your tip, really kind from you. I got the following code and actually I can count the records of an entity and set up a condition. However, the event is never dispatched... I have read the entire post, but I am guessing why the event is just never dispatched, when there exists in the documentation. The table has actually only one section and it is of SCArayOfObjectsSection type... :(

 

Ok, code follows, hoping that except for the event never dispatched could be useful for someone else! :)

 

- (void)didTapAddButton

{

    /* Your conditional code here */

    

    NSManagedObjectContext *managedObjectContext = [(AppDelegate *)[UIApplication sharedApplication].delegate managedObjectContext];

    

    NSFetchRequest *request = [[NSFetchRequest alloc] init];

    [request setEntity: [NSEntityDescription entityForName:@"Website" inManagedObjectContext: managedObjectContext]];

    

    NSError *error = nil;

    NSUInteger count = [managedObjectContext countForFetchRequest: request error: &error];

    

    

    

    if(count==0)

    {

        // Assuming SCArrayOfObjectsSection is the first section

        SCArrayOfObjectsSection *myObjectsSection = (SCArrayOfObjectsSection *)[self.tableViewModel sectionAtIndex:0];

        [myObjectsSection dispatchEventAddNewItem];

        

        NSLog(@"ok!");

        

    }

    else

    {

        NSLog(@"buy the full version!");

    }

}

 

- (void)viewDidLoad {

    

    //self.addButton.target = self;

    //self.addButton.action = @selector(didTapAddButton);

    

    UIBarButtonItem *btn = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:@selector(didTapAddButton)];

    self.navigationItem.rightBarButtonItem = btn;



#4 wizgod

wizgod

    I'm what you guys call a User

  • STV 5.0 Pro
  • PipPipPipPipPipPipPip
  • 575 posts
  • LocationThe Grid
Reputation: 149
Popular

Posted 07 June 2015 - 02:18 PM

Are you saying the dispatchEventAddNewItem isn't firing with the code or you're good to go? :D

 

I implemented your code in the CoreDataApp and it's working as you designed  (after switching out "Website" for "TaskEntity" :) ).

 

Wg


P.S. I love Swift... talk Swift.. Never too old school to learn yet another programming language. LOL! ;-)


#5 fabiensen

fabiensen

    Jr. Member

  • STV 4.0 Std
  • PipPip
  • 23 posts
Reputation: 5
Good

Posted 08 June 2015 - 12:26 AM

Hi wizgod!

 

unfortunately, although it may seem that it works :) ... no, it just does not work. The event is never dispatched... 

The thing is that I can not debug why this happen... obviously I can see the NSlogs there, but then no new item is created... :(

 

I try to fix it or get a workaround, by reading the docs. 

 

Thanks by now, I will let you know!

Fabio



#6 wizgod

wizgod

    I'm what you guys call a User

  • STV 5.0 Pro
  • PipPipPipPipPipPipPip
  • 575 posts
  • LocationThe Grid
Reputation: 149
Popular

Posted 08 June 2015 - 06:22 AM

Odd that it doesn't save for you...

 

Use this for the MasterViewController.m in the CoreDataApp and check that you at least able to have it working, dispatching and committing the changes. This way you know it works and you can debug your own app with that in mind.

 

//
//  MasterViewController.m
//  CoreDataApp
//
//  Created by Tarek Sakr on 11/2/14.
//  Copyright (c) 2014 Sensible Cocoa. All rights reserved.
//

#import "MasterViewController.h"
#import "AppDelegate.h"

@interface MasterViewController ()

@end

@implementation MasterViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.

    //self.addButton.target = self;
    //self.addButton.action = @selector(didTapAddButton);
    
    UIBarButtonItem *btn = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:@selector(didTapAddButton)];
    
    self.navigationItem.rightBarButtonItem = btn;
}

- (void)didTapAddButton

{
    /* Your conditional code here */
    NSManagedObjectContext *managedObjectContext = [(AppDelegate *)[UIApplication sharedApplication].delegate managedObjectContext];

    NSFetchRequest *request = [[NSFetchRequest alloc] init];
    
    [request setEntity: [NSEntityDescription entityForName:@"TaskEntity" inManagedObjectContext: managedObjectContext]];

    NSError *error = nil;
    
    NSUInteger count = [managedObjectContext countForFetchRequest: request error: &error];

    if(count==0)
    {
        // Assuming SCArrayOfObjectsSection is the first section
        SCArrayOfObjectsSection *myObjectsSection = (SCArrayOfObjectsSection *)[self.tableViewModel sectionAtIndex:0];
        
        [myObjectsSection dispatchEventAddNewItem];

        NSLog(@"ok!");
    }
    else
    {
        NSLog(@"buy the full version!");
    }
}

@end

 

Wg


P.S. I love Swift... talk Swift.. Never too old school to learn yet another programming language. LOL! ;-)






Also tagged with one or more of these keywords: data-definitions, core-data

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users