2014-07-14 1 views
3

에서 UIBezierPath 추가 인수 '반경'나는 스위프트에 목표 - C 라이브러리 (STKSpinnerView)을 채택하고 있었고, 난이 오류를 해결할 수 :스위프트 - 전화

func getRadius() -> CGFloat { 
    var r : CGRect = CGRectInset(self.bounds, self.wellThickness/2.0, self.wellThickness/2.0) 
    var w : CGFloat = r.size.width 
    var h : CGFloat = r.size.height 

    if w > h { 
     return h/2.0 
    }else{ 
     return w/2.0 
    } 
} 

override func layoutSubviews() { 
    super.layoutSubviews() 

    var bounds : CGRect = self.bounds 
    var wt : CGFloat = self.wellThickness 
    var outer : CGRect = CGRectInset(self.bounds, wt/2.0, wt/2.0) 
    var inner : CGRect = CGRectInset(self.bounds, wt, wt) 

    var innerPath : UIBezierPath = UIBezierPath(ovalInRect: inner) 
    var arcCenter = CGPointMake(CGRectGetMidX(outer), CGRectGetMidY(outer)) 
    var radius = self.getRadius() 
    var startAngle = -(CGFloat(M_PI_2)) 
    var endAngle = (2.0 * M_PI - M_PI_2) 
    // (Next line) ERROR: Extra argument 'radius' in call 
    var outerPath : UIBezierPath = UIBezierPath(arcCenter: arcCenter, radius: radius, startAngle: startAngle, endAngle: endAngle, clockwise: true) 

} 

내가 왜 '반경을 이해하지를 '애플처럼 방법을 사용하면 추가 인수입니다 ... 당신은 그것을 해결하는 방법을 알고 계십니까? 감사합니다.

+0

는 놀이터에서 나를 위해 잘 작동하는 것 같다. –

답변

11

오류 메시지는 오해의 소지가 있습니다. 실제 문제는 의 endAngle: 매개 변수의 유형이 CGFloat이고 Double 인수를 전달하는 것입니다. 값을 캐스팅하는 것은 명시 적으로 도움이 : CGFloatFloat로 정의되지 않은 Double로되어있는 32 비트 아키텍처 용으로 컴파일 할 때

var endAngle = CGFloat(2.0 * M_PI - M_PI_2) 

문제가 발생합니다.

https://github.com/ksm/SwiftInFlux 참조 :

What is happening here is that CGFloat is a typealias for either Float or Double depending on whether you're building for 32 or 64-bits. This is exactly how Objective-C works, but is problematic in Swift because Swift doesn't allow implicit conversions.

We're aware of this problem and consider it to be serious: we are evaluating several different solutions right now and will roll one out in a later beta. As you notice, you can cope with this today by casting to Double. This is inelegant but effective :-)

-- Chris Lattner

Sources: https://devforums.apple.com/message/998222#998222

+0

좋아요! Chris Lattner의 통찰력. 그의 우편을 놓친 나는 정말 귀하의 견적을 주셔서 감사합니다! – Klaas

+1

@FrankSchmitt : Xcode 6.1.1에서 다시 확인했으며 제안 된 변경 사항에 따라 코드가 컴파일됩니다. –

+0

@ MartinR 네가 맞아. CGPath 유형의 변수에 할당하는 중, 동일한 오류가 발생했습니다. 후행하는'.CGPath'를 추가하여 그것을 수정했습니다. –