WHERE TO INIT a CLASS

Discussion in 'iOS Programming' started by joak, Mar 19, 2014.

  1. joak macrumors newbie

    Joined:
    Mar 7, 2014
    #1
    Hello

    I have one generic class to work with Database(sqlite), this class has some methods to create tables, open database, insert records, delete records etc .... if I import this class to work with other(class B), where I have to init Database class to work with his methods in all methods of class B ?
     
  2. ianray macrumors 6502

    Joined:
    Jun 22, 2010
    Location:
    @
  3. joak thread starter macrumors newbie

    Joined:
    Mar 7, 2014
  4. ianray macrumors 6502

    Joined:
    Jun 22, 2010
    Location:
    @
  5. joak thread starter macrumors newbie

    Joined:
    Mar 7, 2014
    #5
    ClassB.h
    Code:
    @ property (strong,nonatomic) NSObject *basedatos;
    
    ClassB.m
    Code:
    - (id) init
    {
        self = [super init];
        if (self)
        {
            self.basedatos = [[JFBaseDatos alloc] init];
        }
        return self;
    }
    
    how can I call in another classB's metods the class basedatos?
    Code:
    [self.basedatos dropTables:self.arrayTableNames];
    
     
  6. ArtOfWarfare macrumors 604

    ArtOfWarfare

    Joined:
    Nov 26, 2007
    #6
    That all looks fine to me. What's not working? How should it work and what's it doing instead?
     
  7. dantastic macrumors 6502

    dantastic

    Joined:
    Jan 21, 2011
    #7
    The compiler will give out about that.
    dropTables: is not a method belonging to NSObject.

    try

    Code:
    @property (nonatomic, strong) JFBaseDatos *baseDatos;
    
    instead
     
  8. joak thread starter macrumors newbie

    Joined:
    Mar 7, 2014
    #8
    Dantastic ... I asked how it's correct to instance an object because when I have used the methods of JFBaseDatos some works bad.

    The class JFBaseDatos, has a method to create tables, the database file it's created and I can review the structure all tables and it's fine ... but, when I want to insert records, I can't because I have gotten a message that a "id_torneo" column dosen't exist ... but yes..... it's exists .. I can see it in the database file.
     
  9. joak thread starter macrumors newbie

    Joined:
    Mar 7, 2014
    #9
    I found the error, the syntax create table it's bad.
     

    Attached Files:

Share This Page