1

So im trying to make an app for a school project in Swift. (im completely new to this language) The app should allow you to tilt your device, and by doing so making a square drop to the bottom of the screen. This is what ip using right now:

func gravityUpdated(){
        if let data = motionManager.deviceMotion {
            let gravity = data.gravity
            Zwaartekracht.gravityDirection = CGVectorMake(CGFloat(gravity.x), CGFloat(gravity.y))
        }

    }
   gravityUpdated()

When i run it on my iPhone 6, the build is successful, but then i get to see this: (sorry for long post):

    libswiftCore.dylib`function signature specialization <Arg[0] = Exploded, Arg[1] = Exploded, Arg[2] = Dead, Arg[3] = Dead> of Swift._fatalErrorMessage (Swift.StaticString, Swift.StaticString, Swift.StaticString, Swift.UInt) -> ():
    0x100171448 <+0>:   stp    x29, x30, [sp, #-16]!
    0x10017144c <+4>:   mov    x29, sp
    0x100171450 <+8>:   sub    sp, sp, #16
    0x100171454 <+12>:  and    w8, w2, #0x1
    0x100171458 <+16>:  tbnz   w8, #0, 0x100171478       ; <+48>
    0x10017145c <+20>:  tbnz   x1, #63, 0x100171568      ; <+288>
    0x100171460 <+24>:  add    x1, x0, x1
    0x100171464 <+28>:  mov    x2, x3
    0x100171468 <+32>:  mov    x3, x4
    0x10017146c <+36>:  mov    x4, x5
    0x100171470 <+40>:  bl     0x1001a1334               ; function signature specialization <Arg[0] = Exploded, Arg[1] = Exploded> of Swift.(_fatalErrorMessage (Swift.StaticString, Swift.StaticString, Swift.StaticString, Swift.UInt) -> ()).(closure #2)
->  0x100171474 <+44>:  brk    #0x1
    0x100171478 <+48>:  str    xzr, [sp, #8]
    0x10017147c <+52>:  cmp    x0, w0, uxtw
    0x100171480 <+56>:  b.ne   0x100171620               ; <+472>
    0x100171484 <+60>:  lsr    w8, w0, #11
    0x100171488 <+64>:  cmp    w8, #27
    0x10017148c <+68>:  b.ne   0x1001714b4               ; <+108>
    0x100171490 <+72>:  adr    x0, #584602               ; "fatal error"
    0x100171494 <+76>:  nop    
    0x100171498 <+80>:  adr    x3, #586600               ; "high- and low-surrogate code points are not valid Unicode scalar values"
    0x10017149c <+84>:  nop    
    0x1001714a0 <+88>:  movz   w1, #0xb
    0x1001714a4 <+92>:  orr    w2, wzr, #0x2
    0x1001714a8 <+96>:  movz   w4, #0x47
    0x1001714ac <+100>: orr    w5, wzr, #0x2
    0x1001714b0 <+104>: bl     0x100171448               ; <+0>
    0x1001714b4 <+108>: lsr    w10, w0, #16
    0x1001714b8 <+112>: cmp    w10, #16
    0x1001714bc <+116>: b.hi   0x1001714ec               ; <+164>
    0x1001714c0 <+120>: cmp    w0, #128
    0x1001714c4 <+124>: b.lo   0x100171510               ; <+200>
    0x1001714c8 <+128>: orr    w8, wzr, #0x80
    0x1001714cc <+132>: bfxil  x8, x0, #0, #6
    0x1001714d0 <+136>: cmp    w0, #2047
    0x1001714d4 <+140>: b.hi   0x10017158c               ; <+324>
    0x1001714d8 <+144>: movz   x11, #0
    0x1001714dc <+148>: movz   x10, #0
    0x1001714e0 <+152>: lsr    w9, w0, #6
    0x1001714e4 <+156>: orr    w9, w9, #0xffffffc0
    0x1001714e8 <+160>: b      0x1001715e8               ; <+416>
    0x1001714ec <+164>: adr    x0, #584510               ; "fatal error"
    0x1001714f0 <+168>: nop    
    0x1001714f4 <+172>: adr    x3, #586588               ; "value is outside of Unicode codespace"
    0x1001714f8 <+176>: nop    
    0x1001714fc <+180>: movz   w1, #0xb
    0x100171500 <+184>: orr    w2, wzr, #0x2
    0x100171504 <+188>: movz   w4, #0x25
    0x100171508 <+192>: orr    w5, wzr, #0x2
    0x10017150c <+196>: bl     0x100171448               ; <+0>
    0x100171510 <+200>: movz   x10, #0
    0x100171514 <+204>: movz   x9, #0
    0x100171518 <+208>: mov    x8, x0
    0x10017151c <+212>: orr    w11, wzr, #0x8
    0x100171520 <+216>: umulh  x11, x9, x11
    0x100171524 <+220>: cmp    xzr, x11
    0x100171528 <+224>: cset   w11, ne
    0x10017152c <+228>: tbnz   w11, #0, 0x100171620      ; <+472>
    0x100171530 <+232>: lsl    x11, x9, #3
    0x100171534 <+236>: cmp    x11, #63
    0x100171538 <+240>: b.hi   0x100171624               ; <+476>
    0x10017153c <+244>: and    x8, x8, #0xff
    0x100171540 <+248>: lsl    x8, x8, x11
    0x100171544 <+252>: orr    x8, x8, x10
    0x100171548 <+256>: str    x8, [sp, #8]
    0x10017154c <+260>: cmn    x9, #2
    0x100171550 <+264>: b.le   0x100171568               ; <+288>
    0x100171554 <+268>: add    x8, sp, #8
    0x100171558 <+272>: add    x8, x9, x8
    0x10017155c <+276>: add    x1, x8, #1
    0x100171560 <+280>: add    x0, sp, #8
    0x100171564 <+284>: b      0x100171464               ; <+28>
    0x100171568 <+288>: adr    x0, #584386               ; "fatal error"
    0x10017156c <+292>: nop    
    0x100171570 <+296>: adr    x3, #584656               ; "UnsafeBufferPointer with negative count"
    0x100171574 <+300>: nop    
    0x100171578 <+304>: movz   w1, #0xb
    0x10017157c <+308>: orr    w2, wzr, #0x2
    0x100171580 <+312>: movz   w4, #0x27
    0x100171584 <+316>: orr    w5, wzr, #0x2
    0x100171588 <+320>: bl     0x100171448               ; <+0>
    0x10017158c <+324>: orr    w9, wzr, #0xffffff80
    0x100171590 <+328>: bfxil  w9, w0, #6, #6
    0x100171594 <+332>: cbnz   w10, 0x1001715ac          ; <+356>
    0x100171598 <+336>: movz   x11, #0
    0x10017159c <+340>: movz   x12, #0
    0x1001715a0 <+344>: lsr    w10, w0, #12
    0x1001715a4 <+348>: orr    w10, w10, #0xffffffe0
    0x1001715a8 <+352>: b      0x1001715d0               ; <+392>
    0x1001715ac <+356>: lsr    w10, w0, #18
    0x1001715b0 <+360>: orr    w11, w10, #0xf0
    0x1001715b4 <+364>: cmp    w11, w11, uxtb
    0x1001715b8 <+368>: b.ne   0x100171620               ; <+472>
    0x1001715bc <+372>: orr    w10, wzr, #0xffffff80
    0x1001715c0 <+376>: bfxil  w10, w0, #12, #6
    0x1001715c4 <+380>: and    x12, x11, #0xff
    0x1001715c8 <+384>: str    x12, [sp, #8]
    0x1001715cc <+388>: orr    w11, wzr, #0x1
    0x1001715d0 <+392>: and    x10, x10, #0xff
    0x1001715d4 <+396>: lsl    x13, x11, #3
    0x1001715d8 <+400>: lsl    x10, x10, x13
    0x1001715dc <+404>: orr    x10, x10, x12
    0x1001715e0 <+408>: str    x10, [sp, #8]
    0x1001715e4 <+412>: add    x11, x11, #1
    0x1001715e8 <+416>: orr    w12, wzr, #0x8
    0x1001715ec <+420>: umulh  x12, x11, x12
    0x1001715f0 <+424>: cmp    xzr, x12
    0x1001715f4 <+428>: cset   w12, ne
    0x1001715f8 <+432>: tbnz   w12, #0, 0x100171620      ; <+472>
    0x1001715fc <+436>: lsl    x12, x11, #3
    0x100171600 <+440>: cmp    x12, #64
    0x100171604 <+444>: b.hs   0x100171624               ; <+476>
    0x100171608 <+448>: and    x9, x9, #0xff
    0x10017160c <+452>: lsl    x9, x9, x12
    0x100171610 <+456>: orr    x10, x9, x10
    0x100171614 <+460>: str    x10, [sp, #8]
    0x100171618 <+464>: add    x9, x11, #1
    0x10017161c <+468>: tbz    x9, #63, 0x10017151c      ; <+212>
    0x100171620 <+472>: brk    #0x1
    0x100171624 <+476>: adr    x0, #584198               ; "fatal error"
    0x100171628 <+480>: nop    
    0x10017162c <+484>: adr    x3, #584228               ; "shift amount is larger than type size in bits"
    0x100171630 <+488>: nop    
    0x100171634 <+492>: movz   w1, #0xb
    0x100171638 <+496>: orr    w2, wzr, #0x2
    0x10017163c <+500>: movz   w4, #0x2d
    0x100171640 <+504>: orr    w5, wzr, #0x2
    0x100171644 <+508>: bl     0x100171448               ; <+0>

on the bottom it also states: fatal error: unexpectedly found nil while unwrapping an Optional value (lldb)

i dont have a single clue how this can happen

anyone can help? thanks!

Krapton
  • 45
  • 1
  • 10
  • It means that something is `nil`. – NobodyNada Apr 16 '15 at 23:59
  • I know, but what variable is nil and why does it crash on that? – Krapton Apr 17 '15 at 11:03
  • We need more information to tell you that. – NobodyNada Apr 17 '15 at 15:55
  • 1
    In the debugger toolbar, there should be a button that says 0: _fatalErrorMessage or something. Click on it, and a stack trace will appear. Click on the topmost frame that is in your code. You will see exactly where the program crashes. Post the function it crashed in, and which line of the function was highlighted. Also, you can get rid of the disassembly of _fatalErrorMessage since it does not help us. – NobodyNada Apr 17 '15 at 15:59
  • This is a picture of my Xcode: [link](http://imgur.com/By4RDNC) – Krapton Apr 27 '15 at 16:59
  • Click on the thing that says "0 function signature specialization..." Then click on the topmost stack frame that is in __your code__. – NobodyNada Apr 27 '15 at 17:35
  • Im really sorry but im really not familiar with the debugging in xcode, here is a screenshot of where i got the code i think you requested [link](http://imgur.com/1rxxztj) and this is the full code on pastebin [link](http://pastebin.com/kCp3QSA9) (and i dont really know what you mean by 'in your code', again, really sorry for the noobness) – Krapton Apr 27 '15 at 19:25
  • I didn't request a disassembly of `_fatalErrorMessage`. In the top of the Xcode debugger, do you see the thing that says "0 function signature specialization of Swift._fatalErrorMessage (Swift.StaticString, Swift.StaticString, Swift.StaticString, Swift.UInt) -> ()"? Click on it. – NobodyNada Apr 27 '15 at 20:45
  • Then you will see a list of functions. Click on the topmost function that is one of your functions. – NobodyNada Apr 27 '15 at 20:45
  • okay so i clicked to top function in this dropdown menu ([link](http://imgur.com/Qg23PZl) and then this shows up [link](http://pastebin.com/j0Rq8fDA) btw thanks for helping me, i really appreciate it! – Krapton Apr 28 '15 at 16:24
  • Okay, what is the stack frame under that one? – NobodyNada Apr 28 '15 at 16:39
  • http://pastebin.com/MRtTyMhz here it is – Krapton Apr 28 '15 at 17:18

1 Answers1

0

Got it working by using this code:

func gravityUpdated(motion: CMDeviceMotion!, error: NSError!) {
    let grav : CMAcceleration = motion.gravity;

    let x = CGFloat(grav.x);
    let y = CGFloat(grav.y);
    var p = CGPointMake(x,y)



    // Have to correct for orientation.
    var orientation = UIApplication.sharedApplication().statusBarOrientation;

    if(orientation == UIInterfaceOrientation.LandscapeLeft) {
        var t = p.x
        p.x = 0 - p.y
        p.y = t
    } else if (orientation == UIInterfaceOrientation.LandscapeRight) {
        var t = p.x
        p.x = p.y
        p.y = 0 - t
    } else if (orientation == UIInterfaceOrientation.PortraitUpsideDown) {
        p.x *= -1
        p.y *= -1
    }

    var v = CGVectorMake(p.x, 0 - p.y);
    gravity.gravityDirection = v;
    animator.addBehavior(gravity)



}
Krapton
  • 45
  • 1
  • 10