Jack
Jack

Reputation: 1076

Does anyone know what is wrong with this code?

I'm going to jump straight to the point. My App has crashed and I have no clue what's wrong with it. I thing that is most likely incorrect is the part with the screen size but I don't really think so. Here are my screen size variables:

let screenSize: CGRect = UIScreen.mainScreen().bounds
let screenWidth = screenSize.width - CGFloat(screenSize.width)
let screenHeight = screenSize.height - CGFloat(screenSize.height)

They are being used here, in my tick from my NSTimer:

func tick()
{
    let color = Int(arc4random_uniform(3))
    if(color == 1)
    {
        let newDrop:Drop = Drop(dropType: DropType.blue, xPos: Int(arc4random_uniform(UInt32(screenWidth - 5))))
            
            drops.append(newDrop)
    } else if(color == 2)
    {
        let newDrop:Drop = Drop(dropType: DropType.red, xPos: Int(arc4random_uniform(UInt32(screenHeight - 5))))
        
        drops.append(newDrop)
    }
    drawDrops(drops)
}

The drawDrops function is:

func drawDrops(drops:[Drop])
{
    for(var i = 0; i < drops.count; i++)
    {
        print("Hello, World!")
        let button:UIButton = UIButton()
        if(drops[i].dropType == DropType.red)
        {
            button.setImage(UIImage(named: "RedDrop.png"), forState: UIControlState.Normal)
            button.addTarget(self, action: Selector("redPressed:"), forControlEvents: UIControlEvents.TouchUpInside)
        } else if(drops[i].dropType == DropType.blue)
        {
            button.setImage(UIImage(named: "BlueDrop.png"), forState: UIControlState.Normal)
            button.addTarget(self, action: Selector("bluePressed:"), forControlEvents: UIControlEvents.TouchUpInside)
        }
        button.frame = CGRectMake(CGFloat(drops[i].xPos), 10, 20, 20)
        self.view.addSubview(button)
    }
}

Does anyone have any ideas? I'm getting this error that I've never even heard of and have no idea what to do or change:

2016-02-03 18:55:26.679 #Project Name#[19295:1104595] Unknown class Mai

in Interface Builder file. (lldb)

Thanks!

-Jack

EDIT: I figured out the part with the 'Mai' but now I'm getting a crash with just 'llbd.' The console literally doesn't say anything else:

enter image description here

I'm pretty sure it's something in the tick() function because it takes a second to crash when it enters the view controller and my NSTimer is set to 1 second...

(Not sure if this helps or has to do with anything but it has this line selected as EXC_BAD_INSTRUCTION:

let newDrop:Drop = Drop(dropType: DropType.red, xPos: Int(arc4random_uniform(UInt32(screenHeight - 5))))

)

Answer?

Don't know why this worked but I pulled out the arc4random from he Drop object and made it into its own variable. I don't know why this worked but in happy. :-)

Upvotes: 0

Views: 82

Answers (1)

Jarrod Robins
Jarrod Robins

Reputation: 2498

Your crash refers to Interface Builder. I suspect you've got a view with a custom class that no longer exists (or you've mis-typed it - I don't know what 'Mai' is).

Find which view it is and fix the issue in the 'Identity Inspector'. Going by the error message, it sounds like it doesn't have anything to do with the code you posted.

enter image description here

Upvotes: 2

Related Questions