TruniTr
TruniTr

Reputation: 366

swift compile error due to class extension

I have been working on a project and everything seemed to work fine. I have added the following class extension:

extension CGFloat {
static func random() -> CGFloat {
    return CGFloat(Float(arc4random()) / Float(UInt32.max))
}
static func random(#min: CGFloat, max: CGFloat) -> CGFloat {
    assert(min < max)
    return CGFloat.random() * (max - min) + min
}
}

And I suddenly got 21 errors. The screen shot is below. enter image description here

Anyone knows how to solve this?

EDIT:

I managed to solve the problem, which apparently was that I should import UIKit above everything else. Now I still have a problem, that the app runs fine on a simulator but does not work on real device. It says that there is segmentation fault: 11, and that it cant build obj-c module UIKit.

Upvotes: 0

Views: 178

Answers (2)

TruniTr
TruniTr

Reputation: 366

Ok I managed to solve it: All I needed to do was to reduce my deployment target from 8.3 to 8. No idea why this is the case though.

Upvotes: 0

Mikael Hellman
Mikael Hellman

Reputation: 2724

In the case adding UIKit started making things work. Could it be as simple as adding...

import Foundation

on the top would make it work?

Upvotes: 1

Related Questions