1

Iam trying to to add a view to UIGravityBehavior (which I created graphicall by cmd+drag it to my code and creating an Outlet) but my app crashes , although when I create the same view in code and add it to my UIGravityBehavior it works perfectly ! ?? I am working with the new Swift language and this is my simple code

animator = UIDynamicAnimator(referenceView: view)
gravity = UIGravityBehavior(items: [welcomeView])
animator.addBehavior(gravity)

welcomeView is an Outlet : @IBOutlet weak var frontView: UIView!

whats the problem ??? thx

user3703910
  • 624
  • 1
  • 5
  • 25

1 Answers1

0

Most likely one of your IBOutlets is nil because you didn't attach it. When you then try to access it, it'll crash. Make sure you've actually made all your connections in IB.

If your IBOutlet is linked it'll have a little filled-in circle beside it.

Unlinked IBOutlet: Unlinked IBOutlet

Linked IBOutlet: Linked IBOutlet

Rob Napier
  • 286,113
  • 34
  • 456
  • 610
  • I attached it I pressed cmd+drag the view to the code , other other than this I didin't do nothing , is that enough ??? – user3703910 Sep 15 '14 at 15:49
  • I assume you mean you Control-dragged (which is how you link things). I've added how you can validate that it's actually linked. You can also Control-click in IB to inspect linkages. – Rob Napier Sep 15 '14 at 16:23
  • I validated it and shows the gray dot (filled) , Iam not new to IOS but Iam new to swift , I made the same things in objective c version and it runs without any problem !! , maybe its a bug in xcode ?? – user3703910 Sep 15 '14 at 16:50
  • Unlikely in this case. It's much more likely here that you have a `nil` where you don't expect one. Look for that. – Rob Napier Sep 15 '14 at 17:46