Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Simple sqlite example in Cocoa Mac Desktop application

Can anyone give me a simple sqlite example in Cocoa Mac? I want to use it in my Mac desktop application. I don't know how to use sqllite in a mac application.

like image 267
ShinuShajahan Avatar asked Jan 20 '23 01:01

ShinuShajahan


2 Answers

FMDB is a Cocoa wrapper for SQLite that's pretty commonly used. See fmdb.m for some examples.

like image 147
Nicholas Riley Avatar answered Jan 29 '23 04:01

Nicholas Riley


Passing strings to distant PHP file from Mac application. This is how you can do it.

// form text fields and values
    NSArray *formfields = [NSArray arrayWithObjects:@"email", @"password", @"confirm_password", nil];
    NSArray *formvalues = [NSArray arrayWithObjects:[nameField stringValue], [passwordField stringValue],[confirmField stringValue], nil];
    NSDictionary *textParams = [NSDictionary dictionaryWithObjects:formvalues forKeys:formfields];



// submit the form
[self doPostWithText:textParams];




- (void) doPostWithText:(NSDictionary *)textParams
{
    NSString *urlString = @"Your Remote PHP Url goes here!";
    NSMutableURLRequest *request = [[[NSMutableURLRequest alloc] init] autorelease];
    [request setURL:[NSURL URLWithString:urlString]];
    [request setHTTPMethod:@"POST"];

    NSMutableData *body = [NSMutableData data];

    NSString *boundary = [NSString stringWithString:@"---------------------------14737809831466499882746641449"];
    NSString *contentType = [NSString stringWithFormat:@"multipart/form-data; boundary=%@", boundary];
    [request addValue:contentType forHTTPHeaderField:@"Content-Type"];

    // add the text form fields
    for (id key in textParams) {
        [body appendData:[[NSString stringWithFormat:@"--%@\r\n", boundary] dataUsingEncoding:NSUTF8StringEncoding]];
        //[body appendData:[[NSString stringWithFormat:@"Content-Disposition: form-data; name=\"%@\"\r\n\r\n", key] dataUsingEncoding:NSUTF8StringEncoding]];
        [body appendData:[[NSString stringWithString:[textParams objectForKey:key]] dataUsingEncoding:NSUTF8StringEncoding]];
        [body appendData:[[NSString stringWithString:@"\r\n"] dataUsingEncoding:NSUTF8StringEncoding]];
    }

    // close form
    [body appendData:[[NSString stringWithFormat:@"--%@--\r\n", boundary] dataUsingEncoding:NSUTF8StringEncoding]];

    // set request body
    [request setHTTPBody:body];

    //return and test
    NSData *returnData = [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:nil];
    NSString *returnString = [[NSString alloc] initWithData:returnData encoding:NSUTF8StringEncoding];

    NSLog(@"%@", returnString);
}

like image 32
ShinuShajahan Avatar answered Jan 29 '23 03:01

ShinuShajahan