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

  • SEARCH
  • Home
  • 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 8208295
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T09:17:29+00:00 2026-06-07T09:17:29+00:00

I know theres a better solution using arc4random (it’s on my to-try-out-function list), but

  • 0

I know theres a better solution using arc4random (it’s on my to-try-out-function list), but I wanted to try out using the rand() and stand(time(NULL)) function first. I’ve created a NSMutableArray and chuck it with 5 data. Testing out how many number it has was fine. But when I tried to use the button function to load the object it return me with object <sampleData: 0x9a2f0e0>

- (IBAction)generateNumber:(id)sender {

        srand(time(NULL));
    NSInteger number =rand()% ds.count ;
    label.text = [NSString stringWithFormat:@"object %@", [ds objectAtIndex:number] ];
    NSLog(@"%@",label.text);

 }

While I feel the main cause is the method itself, I’ve paste the rest of the code below just incase i made any error somewhere.

ViewController.h

#import <UIKit/UIKit.h>
#import "sampleData.h"
#import "sampleDataDAO.h"
@interface ViewController : UIViewController
@property (weak, nonatomic) IBOutlet UILabel *label;
@property (weak, nonatomic) IBOutlet UIButton *onHitMePressed;
- (IBAction)generateNumber:(id)sender;
@property(nonatomic, strong) sampleDataDAO *daoDS;
@property(nonatomic, strong) NSMutableArray *ds;
@end

ViewController.m

#import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController
@synthesize label;
@synthesize onHitMePressed;
@synthesize daoDS,ds;


- (void)viewDidLoad
{
    [super viewDidLoad];
    daoDS = [[sampleDataDAO alloc] init];
    self.ds = daoDS.PopulateDataSource;
    // Do any additional setup after loading the view, typically from a nib.
}

- (void)viewDidUnload
{
    [self setLabel:nil];
    [self setOnHitMePressed:nil];
    [super viewDidUnload];
    // Release any retained subviews of the main view.
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
}

- (IBAction)generateNumber:(id)sender {

    srand(time(NULL));
NSInteger number =rand()% ds.count ;
label.text = [NSString stringWithFormat:@"object %@", [ds objectAtIndex:number] ];
NSLog(@"%@",label.text);

}
@end

sampleData.h

#import <Foundation/Foundation.h>

@interface sampleData : NSObject
@property (strong,nonatomic) NSString * object;
@end

sampleData.m

#import "sampleData.h"

@implementation sampleData
@synthesize object;
@end

sampleDataDAO.h

#import <Foundation/Foundation.h>
#import "sampleData.h"
@interface sampleDataDAO : NSObject
@property(strong,nonatomic)NSMutableArray*someDataArray;

-(NSMutableArray *)PopulateDataSource;
@end

sampleDataDAO.m

#import "sampleDataDAO.h"

@implementation sampleDataDAO
@synthesize someDataArray;

-(NSMutableArray *)PopulateDataSource
{
    someDataArray = [[NSMutableArray alloc]init];

    sampleData * myData = [[sampleData alloc]init];
    myData.object= @"object 1";
    [someDataArray addObject:myData];
    myData=nil;



   myData = [[sampleData alloc] init];
    myData.object= @"object 2";
    [someDataArray addObject:myData];
    myData=nil;

    myData = [[sampleData alloc] init];
    myData.object= @"object 3";
    [someDataArray addObject:myData];
    myData=nil;

    myData = [[sampleData alloc] init];
    myData.object= @"object 4";
    [someDataArray addObject:myData];
    myData=nil;

    myData = [[sampleData alloc] init];
    myData.object= @"object 5";
    [someDataArray addObject:myData];
    myData=nil;



    return someDataArray;
}


@end
  • 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-06-07T09:17:30+00:00Added an answer on June 7, 2026 at 9:17 am

    what i guess is going on is that nslog function cant print the data inside your sample data class because its not a standard class. not standard classes must implement the “description” method. What you get when you print out your class is the pointer to it, because nslog has no way of knowing how to print out the data in your class.

    if what you want to print on that label/nslog is the nsstring inside your class “sampledata” you should access the property.

    this can be done in the following way:

    SampleData *instanceOfSampleData = (SampleData*)[ds objectAtIndex:number];
    
    label.text = [NSString stringWithFormat:@"object %@", instanceOfSampleData.object];
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am starting using logback and I want to know if there are better
I'm really new to Castle Windsor IoC container. I wanted to know if theres
Disclaimer: I know there are better ways to track email open rates, which are
I want to know if there is a better way (than what I'm currently
I want to know that is there any better method to do : var
I successfully installed the menu-block module and I read on http://www.palantir.net/blog/better-know-module-menu-block-part-i that there is
Does anyone know if theres a jquery autocomplete library that works similar to the
I know there is a lot on this topic but I can't get any
I am using this function to get a cookie and write its value on
I have a Collection as Vector<HashMap<String, String>> Actually I am using this as list

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.