Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3975848
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T04:44:04+00:00 2026-05-20T04:44:04+00:00

Okay, I am a noob and want to get a array from my server

  • 0

Okay,

I am a noob and want to get a array from my server and insert it into a SQLite database table. My code is below. Please help!

- (void)getAlbums {

// Get Albums
NSString *userId;
userId = @"1";
NSString *post =[NSString stringWithFormat:@"userid=%@", userId];
NSString *hostStr = @"********************************************?";
hostStr = [hostStr stringByAppendingString:post];
NSData *dataURL =  [NSData dataWithContentsOfURL: [ NSURL URLWithString: hostStr ]];    
NSString *serverOutput = [[NSString alloc] initWithData:dataURL encoding: NSASCIIStringEncoding];

    //Create Array
NSArray *myWords = [serverOutput componentsSeparatedByString:@" "];

// Output server response
NSLog(serverOutput);

//Initialize the array.
NSMutableArray *listOfItems = [[NSMutableArray alloc] init];
listOfItems = [[NSArray arrayWithObjects: myWords, nil] retain];

NSString *test;
while (*test in listOfItems) {
    [sqlite executeNonQuery:@"INSERT INTO photo_albums VALUES (?, ?);", variableOne, variableTwo];
}

    }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T04:44:04+00:00Added an answer on May 20, 2026 at 4:44 am

    there is more than one issue in this code.

    NSMutableArray *listOfItems = [[NSMutableArray alloc] init]; 
    

    this will leak in the next line because you reassign another item to the variable. Change it into:
    NSArray *listOfItems;

    listOfItems = [[NSArray arrayWithObjects: myWords, nil] retain];
    

    this does not what you think it does. It will initialize an array with the array myWords as a “member”, it won’t add the objects from myWords.
    But why does this line exist anyway? myWords is already an array. And the retain which doesn’t get released would be another leak.

    NSString *test;
    
    while (*test in listOfItems) { 
    

    this is just wrong. use:

    for (test in listOfItems) {
        [sqlite executeNonQuery:@"INSERT INTO photo_albums VALUES (?, ?);", variableOne, variableTwo];
    

    where the f do you get variableOne and variableTwo from? And why do you loop through your listOfItems if you don’t use the NSString named test?

    }
    

    no problem with the closing bracket.

    Oh and serverOutput doesn’t get released too, so there is another leak. And I’m pretty sure that the encoding isn’t ascii.

    Start over with the iOS 101, learn the basics and ignore sqlite for the next 2 weeks.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Okay So what i am having trouble with is these lines of code below.
Okay... I'm getting kind of desperate trying to get this code to work with
Okay, I've looked all over the internet for a good solution to get PHP
Okay, so I'm making a table right now for Box Items. Now, a Box
Okay, so I'm doing my first foray into using the ADO.NET Entity Framework. My
okay, so I'm trying to get a directory of folders and sub folders, but
Okay, so I've got some C code to perform a mathematical operation which could,
Okay, This one is pretty simmilar to my last one, but I don't get
Okay, I'm creating a program from a single class, let's call it John class.
Okay, I'm NOT a Java noob, it just so happens that I've forgotten a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.