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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T05:48:07+00:00 2026-06-18T05:48:07+00:00

I’m very new to Objective-C and need a little help. I have an array

  • 0

I’m very new to Objective-C and need a little help. I have an array of songs:

   {
    artist = "Bernard Herrmann";
    duration = "2:34";
    id = 5;
    title = "Torn Curtain: The Unused Score";
},
    {
    artist = "Miklos Razsa";
    duration = "3:47";
    id = 6;
    title = "Ivanhoe [Original]";
},
...etc.

And I’d like to iterate through the array, converting the durations(currently NSStrings) to something I can use to represent the actual elapsed time, then add them up so that I can get a count of total time to play the playlist. I’ve started working on the loop:

UPDATED:

- (NSInteger)convertDuration
{
    NSInteger totalSeconds=0;
    for(NSMutableArray *song in playlist){
        NSString *durationString = ;
        NSArray *breakMinSec = [durationString componentsSeparatedByString:@":"];
        NSInteger sec = [breakMinSec[1]integerValue];
        NSInteger min = [breakMinSec[0]integerValue];
        totalSeconds += ( sec + min * 60 );
        }
    return totalSeconds;
}

It looks like as of right now, durationString is pulling all of the durations in the first iteration. It won’t compile like this. How can I be sure only to get a single duration for each iteration?

  • 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-18T05:48:09+00:00Added an answer on June 18, 2026 at 5:48 am

    Here no need to convert it into NSTimeInterval or NSDate. You can simply add all durations to an array. Then break minutes and seconds, add all minutes and all seconds.

    Then

     totalSeconds%=60;
     totalMinutes+=totalSeconds/60;
    

    Edit: An idea how you can do (not compiler checked)

    //NSMutableArray *durationArray=[NSMutableArray new];
    NSInteger totalseconds=0;
    for(NSDictionary *song in songDict){
        NSString *durationString=song[@"duration"];
        NSArray *breakMinSec=[durationString componentsSepartedByString:@":"];
        NSInteger sec=[breakMinsec[1]integerValue];
        NSInteger min=[[breakMinSec[0]integerValue];
        //[durationArray addObject:@[sec+min*60]];
        totalseconds+=(sec+min*60);
    }
    

    This will store each songs time in seconds. then you can manupulate this value as per your need.

    EDIT:

    After seeing your edit:

    How can I be sure only to get a single duration for each iteration?

    You can send a value to your method that will return the duration for that specific song. Or as in my earlier answer, each duration was saved in index based array, you could have easily retrieved from there.

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

Sidebar

Related Questions

I have an array which has BIG numbers and small numbers in it. I
I have an MVC Razor view @{ ViewBag.Title = Index; var c = (char)146;
I have thousands of HTML files to process using Groovy/Java and I need to
Let's say I'm outputting a post title and in our database, it's Hello Y’all
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
I have a jquery bug and I've been looking for hours now, I can't
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I am confused How to use looping for Json response Array in another Array.

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.