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 7008999
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T21:48:25+00:00 2026-05-27T21:48:25+00:00

I am trying to create a set of objects using NSMutableSet. The object is

  • 0

I am trying to create a set of objects using NSMutableSet. The object is a tag, each tag has an id and a name.

The tag class is defined like so:

#import "Tag.h"

@implementation Tag

@synthesize id, name;

+(id) populateTagObjectWithId:(NSString *)id andName:(NSString *)name
{
    Tag *myTag = [[self alloc] init];
    myTag.id = id;
    myTag.name = name;

    return myTag;
}
... remainder of code snipped out

Somewhere else in my application I use SQLite to fetch tags in the TAG table. I iterate using a while loop, for each iteration I build a tag object and then try to add it to the set. Code below:

... previous code snipped out...
NSMutableSet *thisTagSet;

while(sqlite3_step(tag_statement) == SQLITE_ROW)
{
    NSString *thisTagId     = [[NSString alloc] initWithUTF8String:(const char *) sqlite3_column_text(tag_statement, 0)];
    NSString *thisTagName   = [[NSString alloc] initWithUTF8String:(const char *) sqlite3_column_text(tag_statement, 1)];

    [thisTagSet addObject:[Tag populateTagObjectWithId:thisTagId andName:thisTagName]];

    ... rest of code snipped out...

So, as I mentioned, as I iterate through this while loop, i get the object and its id and name ARE populating (I have confirmed this by inspecting the debugger and also using NSLog). The thisTagSet NSMutableSet however remains empty even though I’m using the addObject method. Is there something I’m doing wrong here? I have also tried separating out the two steps like so:

Tag *thisTagObject = [Tag populateTagObjectWithId:thisTagId andName:thisTagName];
[thisTagSet addObject:thisTagObject];

Again, the same result. I successfully get a thisTagObject, but nothing in the thisTagSet…

  • 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-27T21:48:26+00:00Added an answer on May 27, 2026 at 9:48 pm

    After reading your code two things pop out:

    You’re not initializing your NSMutableSet, and you’re leaking your tags by returning a retained object in your class method.

    Edit: Added leak-fix code

    +(id)tagObjectWithId:(NSString *)id andName:(NSString *)name
    {
        Tag *myTag = [[self alloc] init];
        myTag.id = id;
        myTag.name = name;
    
        return [myTag autorelease];
    }
    

    2nd edit: The code above only applies as long as ARC is disabled. Otherwise it is not needed as ARC takes care of the memory management.

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

Sidebar

Related Questions

Basically, I'm trying to create an object of unique objects, a set. I had
I'm trying to create a set of custom objects of the class Point point.h
I'm trying to create a custom object that behaves properly in set operations. I've
I am trying to create a virtual directory and set it's permissions using IIS7
I am trying to serialize some Linq objects using this code. private byte[] GetSerializedObj(object
I'm trying to create an object in python which is composed of smaller objects.
I am trying to create a set of WCF web services for an existing
I'm trying to dynamically create a set of labels in my XUL Runner application.
I am trying to create a rather simple effect on a set of images.
I am trying to create a composite key that mimicks the set of PrimaryKeys

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.