<commit_before>//
//  CircularProgressView.swift
//  swiftyui4ios
//
//  Created by <NAME> on 7/28/15.
//  Copyright (c) 2015 fn(x) Software. All rights reserved.
//

import UIKit

@IBDesignable
public class CircularProgressView: UIView {
    
    private var progressLayer : CAShapeLayer?
    private var borderLayer : CAShapeLayer?
    
    public var progress : CGFloat = 0 {
        willSet(v) {
            if v > 1.0 || v < 0.0 {
                fatalError(String(format: "progress must be a value between 0 and 1, value was %lf", v))
            }
        }
        didSet {
            dispatch_async(dispatch_get_main_queue(), {
                self.updateProgress()
                
                if(self.progress == 0 || self.progress >= 1) {
                    self.hidden = true
                }
                else {
                    self.hidden = false
                }

            })
        }
    }

    private func updateProgress() {
        let center = CGPointMake(CGRectGetMidX(self.bounds), CGRectGetMidY(self.bounds))
        var radius = self.bounds.size.width
        if(self.bounds.size.height < radius) {
            radius = self.bounds.size.height
        }
        radius = radius / 2.0
        let arc = UIBezierPath()
        arc.moveToPoint(center)
        arc.addArcWithCenter(center, radius: radius, startAngle: 0.0, endAngle: self.progress * CGFloat(M_PI) * 2, clockwise: true)
        if progressLayer == nil {
            progressLayer = CAShapeLayer()
            self.layer.addSublayer(progressLayer)
        }
        arc.fill()
        progressLayer?.path = arc.CGPath
        progressLayer?.fillColor = self.tintColor.CGColor
    }
    
    override public func layoutSubviews() {
        super.layoutSubviews()
        if(borderLayer == nil) {
            //backgroundColor = UIColor.clearColor()
            let circle = UIBezierPath(ovalInRect: self.bounds)
            circle.stroke()
            borderLayer = CAShapeLayer()
            borderLayer?.fillColor = UIColor.clearColor().CGColor
            borderLayer?.strokeColor = tintColor.CGColor
            borderLayer?.lineWidth = 2.0
            borderLayer?.path = circle.CGPath
            self.layer.addSublayer(borderLayer!)
        }
    }

}
<commit_msg>Cleared a bunch of runtime warnings by moving drawing code to the drawRect method<commit_after>//
//  CircularProgressView.swift
//  swiftyui4ios
//
//  Created by <NAME> on 7/28/15.
//  Copyright (c) 2015 fn(x) Software. All rights reserved.
//

import UIKit

@IBDesignable
public class CircularProgressView: UIView {
    
    private var progressLayer : CAShapeLayer?
    private var borderLayer : CAShapeLayer?
    
    public required init(coder aDecoder: NSCoder) {
        super.init(coder: aDecoder)
        self.contentMode = .Redraw
        self.backgroundColor = UIColor.clearColor()
    }
    
    public override init(frame: CGRect) {
        super.init(frame: frame)
        self.contentMode = .Redraw
        self.backgroundColor = UIColor.clearColor()
    }
    
    public override func drawRect(rect: CGRect) {
        super.drawRect(rect)
        updateProgress()
    }
    
    public var progress : CGFloat = 0 {
        willSet(v) {
            if v > 1.0 || v < 0.0 {
                fatalError(String(format: "progress must be a value between 0 and 1, value was %lf", v))
            }
        }
        didSet {
            dispatch_async(dispatch_get_main_queue(), {
                //self.updateProgress()
                self.setNeedsDisplay()
                if(self.progress == 0 || self.progress >= 1) {
                    self.hidden = true
                }
                else {
                    self.hidden = false
                }

            })
        }
    }

    private func updateProgress() {
        let ctx = UIGraphicsGetCurrentContext()
        CGContextSaveGState(ctx)
        if(borderLayer == nil) {
            borderLayer = CAShapeLayer()
            //backgroundColor = UIColor.clearColor()
            let circle = UIBezierPath(ovalInRect: self.bounds)
            circle.stroke()
            borderLayer?.fillColor = UIColor.clearColor().CGColor
            borderLayer?.strokeColor = tintColor.CGColor
            borderLayer?.lineWidth = 2.0
            borderLayer?.path = circle.CGPath
            self.layer.addSublayer(borderLayer!)
        }

        
        let center = CGPointMake(CGRectGetMidX(self.bounds), CGRectGetMidY(self.bounds))
        var radius = self.bounds.size.width
        if(self.bounds.size.height < radius) {
            radius = self.bounds.size.height
        }
        radius = radius / 2.0
        let arc = UIBezierPath()
        arc.moveToPoint(center)
        arc.addArcWithCenter(center, radius: radius, startAngle: 0.0, endAngle: self.progress * CGFloat(M_PI) * 2, clockwise: true)
        if progressLayer == nil {
            progressLayer = CAShapeLayer()
            self.layer.addSublayer(progressLayer)
        }
        arc.fill()
        progressLayer?.path = arc.CGPath
        progressLayer?.fillColor = self.tintColor.CGColor
        CGContextRestoreGState(ctx)
    }
    /*
    override public func layoutSubviews() {
        super.layoutSubviews()
    }
    */

}

{'fraction_non_alphanumeric': 0.09752380952380953, 'fraction_numerical': 0.009904761904761904, 'mean_word_length': 1.796059637912673, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3866523', 'n_tokens_mistral': 1542, 'n_tokens_neox': 1480, 'n_words': 319}