Git Product home page Git Product logo

magictimerfw / magictimer Goto Github PK

View Code? Open in Web Editor NEW
162.0 2.0 18.0 126 KB

Welcome to the MagicTimer framework, your ultimate solution for handling timers in your iOS applications. This framework provides a powerful and flexible timer implementation with various features to meet your timer needs.

License: MIT License

Swift 94.74% Ruby 5.26%
timer countdown-timer countup-timer swift stopwatch countdown ios

magictimer's Introduction

MagicTimer

MagicTimer logo

Welcome to the MagicTimer framework, your ultimate solution for handling timers in your iOS applications. This framework provides a powerful and flexible timer implementation with various features to meet your timer needs.

Features

  • Easy-to-use: MagicTimer offers a simple and intuitive API that allows you to effortlessly manage timers in your iOS apps.
  • Timer Modes: Choose between two timer modes: Stopwatch and Countdown. Use the Stopwatch mode to measure elapsed time, or Countdown mode to count down from a specified time.
  • Event Handlers: Take advantage of event handlers to respond to timer state changes and elapsed time updates.
  • Background Time Calculation: Enable background time calculation to accurately track elapsed time even when the app is in the background.
  • Highly Configurable: Customize timer properties such as time interval, default value, and effective value to fine-tune your timer behavior.

Why Use MagicTimer?

  • Saves Development Time: With MagicTimer, you can quickly integrate timer functionality into your app without spending excessive time on implementation.
  • Flexible Timer Modes: Whether you need to measure elapsed time or create countdowns, MagicTimer has got you covered.
  • Smooth Background Time Calculation: Ensure accurate time tracking, even when your app goes into the background.
  • Simplified Event Handling: Leverage event handlers to handle timer state changes and elapsed time updates effortlessly.
  • Fully Customizable: Adjust timer properties to match your app's specific requirements.

Getting Started

To start using the MagicTimer framework in your iOS project, follow these simple steps:

  1. Install MagicTimer via Swift Package Manager or by manually adding the framework files to your project.
  2. Import the MagicTimer module into your source code files.
  3. Create an instance of MagicTimer and configure its properties as needed.
  4. Set up event handlers to respond to timer state changes and elapsed time updates.
  5. Start the timer using the start() method.
  6. Enjoy the power and convenience of MagicTimer in your app!

Code Example

import MagicTimer

// Create an instance of MagicTimer
let timer = MagicTimer()

// Configure the timer properties
timer.countMode = .stopWatch
timer.defultValue = 0
timer.effectiveValue = 1
timer.timeInterval = 1
timer.isActiveInBackground = true

// Set up event handlers
timer.lastStateDidChangeHandler = { state in
    print("Timer state changed: \(state)")
}

timer.elapsedTimeDidChangeHandler = { elapsedTime in
    print("Elapsed time updated: \(elapsedTime)")
}

// Start the timer
timer.start()

Note: For detailed usage instructions and API documentation, please refer to the MagicTimer Documentation file.

Requirements

  • iOS 11.0+
  • Swift 5.0+

Installation

Swift Package Manager

You can use Swift Package Manager to integrate MagicTimer into your Xcode project. Simply add the package dependency to your Package.swift file:

dependencies: [
    .package(url: "https://github.com/MagicTimerFW/MagicTimer", from: "2.0.1")
]

Manual Installation

If you prefer manual installation, you can download the MagicTimer framework from the GitHub repository. After downloading, add the necessary files to your Xcode project.

Warning

⚠️ MagicTimerView is no longer available. Create your own UIView and connect MagicTimer to it.

Contribute

We welcome contributions from the community to enhance the MagicTimer framework. If you encounter any issues or have ideas for improvements, please submit a pull request or open an issue on the GitHub repository.

License

MagicTimer is released under the MIT License. See the LICENSE file for more details.

This Markdown file provides an overview of the MagicTimer framework, highlights its features and benefits, guides developers on getting started, provides installation instructions, and encourages contributions. It also includes information on requirements, licensing, and ways to connect

magictimer's People

Contributors

mohammadrezaansari avatar sadeghgoo avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

magictimer's Issues

didStateChange Callback is Not Firing on Stop

Hi,

I am calling callback on viewdidload like that

  timer.defaultValue = 10
  timer.isActiveInBackground = true
  timer.mode = .countDown(fromSeconds: 10)
  timer.startCounting()

  timer.didStateChange = { (timer_state) -> Void in
                    print(timer_state)
                }
        

The callback works on start and prints state as fired but on stop the callback is not working and never firing.

Am I doing something wrong or it is a kind of a bug ?

thanks

Continue countdown timer after being paused

Hello!

Thanks for this library, it has helped me a lot! I have one problem. I have implemented a timer in my app and use 3 button to control this timer: Start, Stop and Pause. The problem is that when user presses Pause the timer pauses, but when the user presses Start, it doesn't continue running from where it was paused, because I don't know how to do that. Here is my code:

`import UIKit
import MagicTimer

class TimerVC: UIViewController {

var currentTaskDefaultTime = 10.0


@IBOutlet weak var timer: MagicTimerView!

@IBOutlet weak var startButton: UIButton!

@IBOutlet weak var pauseButton: UIButton!

@IBOutlet weak var stopButton: UIButton!

@IBAction func pressedStartButton(_ sender: Any) {
    startButton.isHidden = true
    pauseButton.isHidden = false
    stopButton.isHidden = false
    
    timer.mode = .countDown(fromSeconds: currentTaskDefaultTime)
    timer.isActiveInBackground = true
    timer.startCounting()
    
    
    
}

@IBAction func pressedPauseButton(_ sender: Any) {
    timer.stopCounting()
    startButton.isHidden = false
    completeTaskButton.isHidden = true
}

@IBAction func pressedStopButton(_ sender: Any) {
    timer.resetToDefault()
    startButton.isHidden = false
    pauseButton.isHidden = true
    stopButton.isHidden = true
}



override func viewDidLoad() {
    super.viewDidLoad()
    
    timer.font = UIFont(name: "Comfortaa-Semibold", size: 50)
    
    //hides by default the buttons
    pauseButton.isHidden = true
    stopButton.isHidden = true
}

}
`

Please help me

Sincerely yours
Nurlan

Exception when iOS app running on M1 Mac

2021-04-15 17:51:36.250058+0500 KickSharing[41952:669837] MagicTimer: initialized
2021-04-15 17:51:36.253818+0500 KickSharing[41952:669837] *** Assertion failure in -[MagicTimer.MGStandardTimerFormatter setAllowedUnits:], NSDateComponentsFormatter.m:806
2021-04-15 17:51:36.260599+0500 KickSharing[41952:669837] [General] Invalid parameter not satisfying: allowedUnits == 0 || !(allowedUnits & ~(NSCalendarUnitYear | NSCalendarUnitMonth | NSCalendarUnitWeekOfMonth | NSCalendarUnitDay | NSCalendarUnitHour | NSCalendarUnitMinute | NSCalendarUnitSecond))

can using pod

I think you need update the REAMDE this line:

  pod 'MagicTimer', :git => 'https://github.com/MagicTimerFW/MagicTimer'

Cannot Add Package via SPM in Xcode 15 Beta 3

Hi! Thanks for the work you've put in to maintaining this library, I know it's going to save me a ton of time.

Summary

  • Cannot add version of MagicTimer via Swift Package Manager
  • Error SPM: Failed to resolve dependencies Dependencies could not be resolved because package 'magictimer' is required using a stable-version but 'magictimer' depends on an unstable-version package 'magictimercore' and root depends on 'magictimer' 2.0.1.. <3.0.0.

Environment

  • Xcode Version 15.0 beta 3 (15A5195k)
  • Build target iOS 17+

.countDown(fromSeconds: 60) doesnt work at all for 1.0.6 version.

Here is my code:

        timer.countMode = .countDown(fromSeconds: 60)
        timer.defultValue = 0
        timer.effectiveValue = 1
        timer.timeInterval = 1
        timer.isActiveInBackground = true
        print(">>>>>int: \(interval)")
        timer.lastStateDidChangeHandler = { state in
            print(">>>>>>>state")
            print(state)
        }
        timer.elapsedTimeDidChangeHandler = { [weak self] elapsedTime in
            print(">>>>>>>statetime")
            print(elapsedTime)
            if elapsedTime == 0 {
                self?.onComplete?()
            }
        }
//        timer.resetToDefault()
        timer.start()

It prints 59.0 every second. Why? Doesnt change anything.

Custom text formatter

Is there any way currently to provide a custom formatter to for the displayed text?

24 Hours to above issue

when i pass time 24 hour to above then other value(time) pass

when i pass below 24 hours then it work proper

About countdown

There is an error in the countdown time return, and it does not stop when the time reaches completion。

func start() {
        timer.countMode = .countDown(fromSeconds: 60)
        timer.defultValue = 0
        timer.effectiveValue = 1
        timer.timeInterval = 1
        timer.isActiveInBackground = true

        // Set up event handlers
        timer.lastStateDidChangeHandler = { state in
            print("Timer state changed: \(state)")
        }

        timer.elapsedTimeDidChangeHandler = { elapsedTime in
            print("Elapsed time updated: \(elapsedTime)")
        }

        // Start the timer
        timer.start()
    }

[!] Unable to find a specification for `MagicTimer`

While using pod 'MagicTimer' I'm getting the following error

**[!] Unable to find a specification for MagicTimer

You have either:

  • out-of-date source repos which you can update with pod repo update or with pod install --repo-update.
  • mistyped the name or version.
  • not added the source repo that hosts the Podspec to your Podfile.

Note: as of CocoaPods 1.0, pod repo update does not happen on pod install by default.**

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.