Why app crashes if year is less than 1948 or more than 2086? - ios

My Xcode app crashes if the user inputs a year below 1948 or for example more than the year 2086 and was wondering if anyone had this issue before and how to resolve?
The user selects their date of birth and the app displays data such as the number of seconds between today's date and their date of birth.
I am new to Xcode (Xcode 8) so still learning. Thanks in advance
#IBAction func clickScreenBtn(_ sender: Any) {
let birthDay = UserDefaults.standard.object(forKey: "birthday") as! Date
var component = NSCalendar.current.dateComponents([.day], from: birthDay, to: Date())
type = type + 1
switch type {
case 0:
unitLabel.text = "Days"
timeLabel.text = ""
timeLabel.text = timeLabel.text?.appendingFormat("%d", component.day!)
break
case 4:
type = 0
unitLabel.text = "Days"
timeLabel.text = ""
timeLabel.text = timeLabel.text?.appendingFormat("%d", component.day!)
break
case 1:
component = NSCalendar.current.dateComponents([.hour], from: birthDay, to: Date())
unitLabel.text = "Hours"
timeLabel.text = ""
timeLabel.text = timeLabel.text?.appendingFormat("%d", component.hour!)
break
case 2:
component = NSCalendar.current.dateComponents([.minute], from: birthDay, to: Date())
unitLabel.text = "Minutes"
timeLabel.text = ""
timeLabel.text = timeLabel.text?.appendingFormat("%d", component.minute!)
break
case 3:
component = NSCalendar.current.dateComponents([.second], from: birthDay, to: Date())
unitLabel.text = "Seconds"
timeLabel.text = ""
timeLabel.text = timeLabel.text?.appendingFormat("%d", component.second!)
break
default:
break
}
}
Error:
0x108142301 <+9425>: callq 0x1082a95c4 ; symbol stub for: Foundation.Calendar.dateComponents (Swift.Set<Foundation.Calendar.Component>, from : Foundation.Date, to : Foundation.Date) -> Foundation.DateComponents
0x108142306 <+9430>: movq -0x710(%rbp), %rdi
0x10814230d <+9437>: movq %rax, -0x730(%rbp)
0x108142314 <+9444>: callq 0x10813d8a0 ; swift_rt_swift_release
0x108142319 <+9449>: movq -0x730(%rbp), %rax
0x108142320 <+9456>: movq %rax, -0x8(%rbp)
0x108142324 <+9460>: movq -0x218(%rbp), %rdi
0x10814232b <+9467>: callq 0x10813d8a0 ; swift_rt_swift_release
0x108142330 <+9472>: movq 0x1e3081(%rip), %rax ; (void *)0x000000010e87f068: swift_isaMask
0x108142337 <+9479>: movq -0x168(%rbp), %rdx
0x10814233e <+9486>: movq (%rdx), %rdi
0x108142341 <+9489>: andq (%rax), %rdi
0x108142344 <+9492>: movq %rdi, -0x738(%rbp)
0x10814234b <+9499>: movq %rdx, %rdi
0x10814234e <+9502>: movq -0x738(%rbp), %rax
0x108142355 <+9509>: callq *0x80(%rax)
0x10814235b <+9515>: movq %rax, -0x70(%rbp)
0x10814235f <+9519>: movq -0x230(%rbp), %rax
0x108142366 <+9526>: movsd -0x1d8(%rbp), %xmm0 ; xmm0 = mem[0],zero
0x10814236e <+9534>: movd %xmm0, %rax
0x108142373 <+9539>: cmpq $0x0, -0x70(%rbp)
0x108142378 <+9544>: jne 0x108142409 ; <+9689> at MainViewController.swift
0x10814237e <+9550>: movq -0x230(%rbp), %rax
0x108142385 <+9557>: movsd -0x1d8(%rbp), %xmm0 ; xmm0 = mem[0],zero
0x10814238d <+9565>: movd %xmm0, %rax
0x108142392 <+9570>: movq -0x230(%rbp), %rax
0x108142399 <+9577>: movsd -0x1d8(%rbp), %xmm0 ; xmm0 = mem[0],zero
0x1081423a1 <+9585>: movd %xmm0, %rax
0x1081423a6 <+9590>: movq -0x230(%rbp), %rax
0x1081423ad <+9597>: movsd -0x1d8(%rbp), %xmm0 ; xmm0 = mem[0],zero
0x1081423b5 <+9605>: movd %xmm0, %rax
0x1081423ba <+9610>: leaq 0x1b13f9(%rip), %rdi ; "fatal error"
0x1081423c1 <+9617>: movl $0xb, %eax
0x1081423c6 <+9622>: movl %eax, %esi
0x1081423c8 <+9624>: movl $0x2, %eax
0x1081423cd <+9629>: leaq 0x1b13ac(%rip), %rcx ; "unexpectedly found nil while unwrapping an Optional value"
0x1081423d4 <+9636>: movl $0x39, %edx
0x1081423d9 <+9641>: movl %edx, %r8d
0x1081423dc <+9644>: xorl %edx, %edx
0x1081423de <+9646>: movl %edx, -0x73c(%rbp)
0x1081423e4 <+9652>: movl %eax, %edx
0x1081423e6 <+9654>: movl %eax, %r9d
0x1081423e9 <+9657>: movl $0x0, (%rsp)
0x1081423f0 <+9664>: callq 0x1082a95f4 ; symbol stub for: function signature specialization <preserving fragile attribute, Arg[2] = Dead, Arg[3] = Dead> of Swift._fatalErrorMessage (Swift.StaticString, Swift.StaticString, file : Swift.StaticString, line : Swift.UInt, flags : Swift.UInt32) -> Swift.Never
0x1081423f5 <+9669>: movq -0x230(%rbp), %rcx
0x1081423fc <+9676>: movsd -0x1d8(%rbp), %xmm0 ; xmm0 = mem[0],zero
0x108142404 <+9684>: movd %xmm0, %rcx
0x108142409 <+9689>: leaq -0x70(%rbp), %rax
0x10814240d <+9693>: movq -0x70(%rbp), %rcx
0x108142411 <+9697>: movq %rcx, %rdi
0x108142414 <+9700>: movq %rax, -0x748(%rbp)
0x10814241b <+9707>: movq %rcx, -0x750(%rbp)
0x108142422 <+9714>: callq 0x1082a9858 ; symbol stub for: objc_retain
0x108142427 <+9719>: leaq 0x1b1398(%rip), %rdi ; "Seconds"

If you get rid of all the !s and replace them with some actual error checking, you should be able to find out where the error is occurring rather quickly. For example, this version will log whatever is going wrong to the console:
#IBAction func clickScreenBtn(_ sender: Any) {
guard let birthDay = UserDefaults.standard.object(forKey: "birthday") as? Date else {
print("Couldn't get birthday")
return
}
let currentDate = Date()
guard let day = Calendar.current.dateComponents([.day], from: birthDay, to: currentDate).day else {
print("Couldn't get day")
return
}
type = type + 1
switch type {
case 0:
unitLabel.text = "Days"
timeLabel.text = "\(day)"
case 4:
type = 0
unitLabel.text = "Days"
timeLabel.text = "\(day)"
case 1:
guard let hour = Calendar.current.dateComponents([.hour], from: birthDay, to: currentDate).hour else {
print("Couldn't get hour")
return
}
unitLabel.text = "Hours"
timeLabel.text = "\(hour)"
case 2:
guard let minute = Calendar.current.dateComponents([.minute], from: birthDay, to: currentDate).minute else {
print("Couldn't get minute")
return
}
unitLabel.text = "Minutes"
timeLabel.text = "\(minute)"
case 3:
guard let second = Calendar.current.dateComponents([.second], from: birthDay, to: currentDate).second else {
print("Couldn't get second")
return
}
unitLabel.text = "Seconds"
timeLabel.text = "\(second)"
default:
break
}
}
Once you know where the issue is actually occurring, it should be much easier to fix it.

Related

In Swift, why is "let _ = this" faster then "this != nil"?

So my question is why is let _ = this faster then this != nil?
Example:
This is:
let this : Bool? = true //
let start = DispatchTime.now()
for _ in 0...100000000 {
guard this != nil else { continue }
}
let end = DispatchTime.now()
let nanoTime = end.uptimeNanoseconds - start.uptimeNanoseconds
let timeInterval = Double(nanoTime)
print("Time \(timeInterval)")
// Time 5426559135.0
// Time 5428084767.0
// Time 5327325459.0
Slower than:
let this : Bool? = true //
let start = DispatchTime.now()
for _ in 0...100000000 {
guard let _ = this else { continue }
}
let end = DispatchTime.now()
let nanoTime = end.uptimeNanoseconds - start.uptimeNanoseconds
let timeInterval = Double(nanoTime)
print("Time \(timeInterval)")
// Time 257045414.0
// Time 261933863.0
// Time 263465919.0
Following Jonathan's response I checked the actual disassembled instructions.
Here is the result:
For the code:
let this : Bool? = nil
this != nil
we get:
0x100001290 <+0>: pushq %rbp
0x100001291 <+1>: movq %rsp, %rbp
0x100001294 <+4>: subq $0x30, %rsp
0x100001298 <+8>: leaq 0x2c7259(%rip), %rdx ; type metadata for Swift.Bool
0x10000129f <+15>: leaq 0x2b66ca(%rip), %rcx ; protocol witness table for Swift.Bool : Swift.Equatable in Swift
0x1000012a6 <+22>: leaq -0x18(%rbp), %rax
0x1000012aa <+26>: leaq -0x8(%rbp), %r8
0x1000012ae <+30>: movb $0x2, 0x2f940b(%rip)
0x1000012b5 <+37>: movb 0x2f9404(%rip), %r9b ; test2.this : Swift.Optional<Swift.Bool>
0x1000012bc <+44>: movb %r9b, -0x8(%rbp)
0x1000012c0 <+48>: movb $0x2, -0x10(%rbp)
0x1000012c4 <+52>: movb -0x10(%rbp), %r9b
0x1000012c8 <+56>: movb %r9b, -0x18(%rbp)
0x1000012cc <+60>: movl %edi, -0x1c(%rbp)
0x1000012cf <+63>: movq %r8, %rdi
0x1000012d2 <+66>: movq %rsi, -0x28(%rbp)
0x1000012d6 <+70>: movq %rax, %rsi
0x1000012d9 <+73>: callq 0x10004df10 ; Swift.!= infix <A where A: Swift.Equatable> (Swift.Optional<A>, Swift.Optional<A>) -> Swift.Bool
0x1000012de <+78>: xorl %r10d, %r10d
0x1000012e1 <+81>: movb %al, -0x29(%rbp)
0x1000012e4 <+84>: movl %r10d, %eax
0x1000012e7 <+87>: addq $0x30, %rsp
0x1000012eb <+91>: popq %rbp
0x1000012ec <+92>: retq
and for:
let this : Bool? = nil
let _ = this
there is:
0x1000012d0 <+0>: pushq %rbp
0x1000012d1 <+1>: movq %rsp, %rbp
0x1000012d4 <+4>: xorl %eax, %eax
0x1000012d6 <+6>: movb $0x2, 0x2f93e3(%rip)
0x1000012dd <+13>: movl %edi, -0x4(%rbp)
0x1000012e0 <+16>: movq %rsi, -0x10(%rbp)
0x1000012e4 <+20>: popq %rbp
0x1000012e5 <+21>: retq
Also, thank you Code Different for pointing to the Optimisation level.
Changing the value from [-Onone] to [-O -whole-module-optimisation] will cause a change for the generated asm in the following way:
The
let this : Bool? = nil
let _ = this
has
0x100001490 <+0>: pushq %rbp
0x100001491 <+1>: movq %rsp, %rbp
0x100001494 <+4>: movb $0x2, 0x3d9595(%rip) ; gCRAnnotations + 63
0x10000149b <+11>: xorl %eax, %eax
0x10000149d <+13>: popq %rbp
0x10000149e <+14>: retq
and the
let this : Bool? = nil
this != nil
to
0x100001490 <+0>: pushq %rbp
0x100001491 <+1>: movq %rsp, %rbp
0x100001494 <+4>: movb $0x2, 0x3d9595(%rip) ; gCRAnnotations + 63
0x10000149b <+11>: xorl %eax, %eax
0x10000149d <+13>: popq %rbp
0x10000149e <+14>: retq
So the resulted instructions are actually the same and the time to execute them should be pretty close.
I would check out this post. They both result in the same underlying assembly instructions. My guess is that they both take such a small amount of time to compile that the time difference you're noticing could be due to other miscellaneous outliers affecting performance.

Simulator crashes when launching in xcode and the issue is in view.controller.init

I've been teaching myself Swift and only a few days in. I've honestly done very little to the code and not sure what is going on. I cannot find a similar thread on stackoverflow with the same issue.
This is all I have written so far in the ViewController.swift:
import UIKit
class ViewController: UIViewController {
#IBOutlet weak var calcNum: UILabel!
var middleOfTyping = false
#IBAction func numButton(sender: UIButton) {
let digit = sender.currentTitle!
if middleOfTyping {
calcNum.text = calcNum.text! + digit
} else {
calcNum.text = digit
}
}
}
When I try launching the simulator, the simulator crashes and gives me this code within Thread 1 - 0 ViewController.init :
Calculator Take 2`Calculator_Take_2.ViewController.init (Calculator_Take_2.ViewController.Type)(coder : __ObjC.NSCoder) -> Swift.Optional<Calculator_Take_2.ViewController>:
0x10b542b00 <+0>: pushq %rbp
0x10b542b01 <+1>: movq %rsp, %rbp
0x10b542b04 <+4>: subq $0x70, %rsp
0x10b542b08 <+8>: movq %rdi, -0x10(%rbp)
0x10b542b0c <+12>: movq %rsi, -0x8(%rbp)
-> 0x10b542b10 <+16>: movq $0x0, -0x18(%rbp)
0x10b542b18 <+24>: movq -0x18(%rbp), %rax
0x10b542b1c <+28>: movq 0x363d(%rip), %rcx ; direct field offset for Calculator_Take_2.ViewController.calcNum
0x10b542b23 <+35>: movq %rsi, %rdx
0x10b542b26 <+38>: addq %rcx, %rdx
0x10b542b29 <+41>: movq %rdi, -0x30(%rbp)
0x10b542b2d <+45>: movq %rdx, %rdi
0x10b542b30 <+48>: movq %rsi, -0x38(%rbp)
0x10b542b34 <+52>: movq %rax, %rsi
0x10b542b37 <+55>: movq %rax, -0x40(%rbp)
0x10b542b3b <+59>: callq 0x10b5436f8 ; symbol stub for: swift_unknownWeakInit
0x10b542b40 <+64>: movq -0x40(%rbp), %rdi
0x10b542b44 <+68>: callq 0x10b5436e0 ; symbol stub for: swift_unknownRelease
0x10b542b49 <+73>: movq 0x3618(%rip), %rax ; direct field offset for Calculator_Take_2.ViewController.middleOfTyping
0x10b542b50 <+80>: movq -0x38(%rbp), %rcx
0x10b542b54 <+84>: movb $0x0, (%rcx,%rax)
0x10b542b58 <+88>: movq $0x0, -0x8(%rbp)
0x10b542b60 <+96>: movq %rcx, -0x48(%rbp)
0x10b542b64 <+100>: callq 0x10b542620 ; type metadata accessor for Calculator_Take_2.ViewController
0x10b542b69 <+105>: leaq -0x28(%rbp), %rdi
0x10b542b6d <+109>: movq -0x48(%rbp), %rcx
0x10b542b71 <+113>: movq %rcx, -0x28(%rbp)
0x10b542b75 <+117>: movq %rax, -0x20(%rbp)
0x10b542b79 <+121>: movq 0x3448(%rip), %rsi ; "initWithCoder:"
0x10b542b80 <+128>: movq -0x30(%rbp), %rax
0x10b542b84 <+132>: movq %rax, %rdx
0x10b542b87 <+135>: callq 0x10b543692 ; symbol stub for: objc_msgSendSuper2
0x10b542b8c <+140>: cmpq $0x0, %rax
0x10b542b92 <+146>: sete %r8b
0x10b542b96 <+150>: xorb $0x1, %r8b
0x10b542b9a <+154>: testb $0x1, %r8b
0x10b542b9e <+158>: movq %rax, -0x50(%rbp)
0x10b542ba2 <+162>: jne 0x10b542ba6 ; <+166> at ViewController.swift
0x10b542ba4 <+164>: jmp 0x10b542bda ; <+218> at ViewController.swift
0x10b542ba6 <+166>: movq -0x50(%rbp), %rax
0x10b542baa <+170>: movq %rax, -0x8(%rbp)
0x10b542bae <+174>: movq %rax, %rdi
0x10b542bb1 <+177>: movq %rax, -0x58(%rbp)
0x10b542bb5 <+181>: callq 0x10b54369e ; symbol stub for: objc_retain
0x10b542bba <+186>: movq -0x30(%rbp), %rdi
0x10b542bbe <+190>: movq %rax, -0x60(%rbp)
0x10b542bc2 <+194>: callq 0x10b543698 ; symbol stub for: objc_release
0x10b542bc7 <+199>: movq -0x58(%rbp), %rdi
0x10b542bcb <+203>: callq 0x10b543698 ; symbol stub for: objc_release
0x10b542bd0 <+208>: movq -0x58(%rbp), %rax
0x10b542bd4 <+212>: movq %rax, -0x68(%rbp)
0x10b542bd8 <+216>: jmp 0x10b542bf4 ; <+244> at ViewController.swift
0x10b542bda <+218>: movq -0x30(%rbp), %rdi
0x10b542bde <+222>: callq 0x10b543698 ; symbol stub for: objc_release
0x10b542be3 <+227>: xorl %eax, %eax
0x10b542be5 <+229>: movl %eax, %edi
0x10b542be7 <+231>: callq 0x10b543698 ; symbol stub for: objc_release
0x10b542bec <+236>: xorl %eax, %eax
0x10b542bee <+238>: movl %eax, %edi
0x10b542bf0 <+240>: movq %rdi, -0x68(%rbp)
0x10b542bf4 <+244>: movq -0x68(%rbp), %rax
0x10b542bf8 <+248>: addq $0x70, %rsp
0x10b542bfc <+252>: popq %rbp
0x10b542bfd <+253>: retq
xcode claims that the breakpoint is at "0x10b542b10 <+16>: movq $0x0, -0x18(%rbp)". I am not sure what any of this means nor how to fix it.
I tried to "undo" all the code I changed in my Main.storyboard, but even when I do that, the code that once worked does not work anymore either and produces the same error, so I am wondering if it is an issue with xCode itself (restarting does not help either).
Any help would be greatly appreciated! Thank you so much!
Did you connect the #IBOutlet weak var calcNum to your label on the view. I.e. is the circle next to it filled? If not connect them, by dragging a line from the circle to the label.

Trying to load local PDF file in UIWebView crashing

This seems like such a simple piece of code that keeps crashing on me. It's able to find the file and I see it in the logs, but it crashes every time at the webview.loadRequest request line:
let kHelpFile = "DB_Help_Doc"
webView.delegate = self
webView.scalesPageToFit = true
self.view.addSubview(webView)
Scripts.log("WebViewVC >> URL is \(kHelpFile)")
if let url = NSBundle.mainBundle().URLForResource(kHelpFile, withExtension: "pdf") {
Scripts.log("BUNDLE FOUND")
Scripts.log("URL = \(url)")
Scripts.log("PATH = \(url.path)")
req = NSURLRequest(URL: NSURL(fileURLWithPath: url.path!))
self.webView.loadRequest(req)
}
else {
Scripts.log("BUNDLE NOT FOUND")
}
This is the exception
libc++abi.dylib`__cxa_throw:
-> 0x10e077c6b <+0>: pushq %rbp
0x10e077c6c <+1>: movq %rsp, %rbp
0x10e077c6f <+4>: pushq %r15
0x10e077c71 <+6>: pushq %r14
0x10e077c73 <+8>: pushq %r12
0x10e077c75 <+10>: pushq %rbx
0x10e077c76 <+11>: movq %rdx, %r14
0x10e077c79 <+14>: movq %rsi, %r15
0x10e077c7c <+17>: movq %rdi, %rbx
0x10e077c7f <+20>: callq 0x10e07787d ; __cxa_get_globals
0x10e077c84 <+25>: movq %rax, %r12
0x10e077c87 <+28>: callq 0x10e078220 ; std::get_unexpected()
0x10e077c8c <+33>: movq %rax, -0x60(%rbx)
0x10e077c90 <+37>: callq 0x10e078258 ; std::get_terminate()
0x10e077c95 <+42>: movq %rax, -0x58(%rbx)
0x10e077c99 <+46>: movq %r15, -0x70(%rbx)
0x10e077c9d <+50>: movq %r14, -0x68(%rbx)
0x10e077ca1 <+54>: leaq -0x20(%rbx), %r14
0x10e077ca5 <+58>: movabsq $0x434c4e47432b2b00, %rax
0x10e077caf <+68>: movq %rax, -0x20(%rbx)
0x10e077cb3 <+72>: movq $0x1, -0x78(%rbx)
0x10e077cbb <+80>: incl 0x8(%r12)
0x10e077cc0 <+85>: leaq 0x1d(%rip), %rax ; __cxxabiv1::exception_cleanup_func(_Unwind_Reason_Code, _Unwind_Exception*)
0x10e077cc7 <+92>: movq %rax, -0x18(%rbx)
0x10e077ccb <+96>: movq %r14, %rdi
0x10e077cce <+99>: callq 0x10e07ab3c ; symbol stub for: _Unwind_RaiseException
0x10e077cd3 <+104>: movq %r14, %rdi
0x10e077cd6 <+107>: callq 0x10e077d08 ; __cxa_begin_catch
0x10e077cdb <+112>: movq -0x58(%rbx), %rdi
0x10e077cdf <+116>: callq 0x10e078266 ; std::__terminate(void (*)())

ios facebook login crash on cancel button

Steps to reproduce the bug:
Login with facebook
enter credentials
Click on cancel button
Relevant code snippets from your implementation:
~~~
NSLog(#"Your code goes here");
var manager = FBSDKLoginManager();
manager.loginBehavior = FBSDKLoginBehavior.Web
manager.logInWithReadPermissions(
["public_profile","email" ],
handler: {
(result: FBSDKLoginManagerLoginResult!, error: NSError!) -> Void in
if ((error) != nil)
{
// Process error
println("error\(error)")
}
else if result.isCancelled {
// Handle cancellations
println("isCancelled\(result.isCancelled)")
}
else {
// If you ask for multiple permissions at once, you
// should check if specific permissions missing
if result.grantedPermissions.contains("email")
{
self.returnUserData()
}
}
})
~~~
SDK version: v4.5.1
When i am debugging i am getting below error
+[FBSDKInternalUtility unregisterTransientObject:]:
0x103ad7cb2 <+0>: pushq %rbp
0x103ad7cb3 <+1>: movq %rsp, %rbp
0x103ad7cb6 <+4>: pushq %r15
0x103ad7cb8 <+6>: pushq %r14
0x103ad7cba <+8>: pushq %r13
0x103ad7cbc <+10>: pushq %r12
0x103ad7cbe <+12>: pushq %rbx
0x103ad7cbf <+13>: pushq %rax
0x103ad7cc0 <+14>: movq %rdx, %rdi
0x103ad7cc3 <+17>: callq *0x207d57(%rip) ; (void *)0x0000000105e6e930: objc_retain
0x103ad7cc9 <+23>: movq %rax, %r14
0x103ad7ccc <+26>: movq 0x5375cd(%rip), %rdi ; _transientObjects
0x103ad7cd3 <+33>: movq 0x2f99ae(%rip), %rsi ; "objectForKey:"
0x103ad7cda <+40>: movq 0x207d2f(%rip), %r13 ; (void *)0x0000000105e71000: objc_msgSend
0x103ad7ce1 <+47>: movq %r14, %rdx
0x103ad7ce4 <+50>: callq *%r13
0x103ad7ce7 <+53>: movq %rax, %rdi
0x103ad7cea <+56>: callq 0x103c2e7e0 ; symbol stub for: objc_retainAutoreleasedReturnValue
0x103ad7cef <+61>: movq %rax, %rbx
0x103ad7cf2 <+64>: movq 0x2f9a3f(%rip), %rsi ; "unsignedIntegerValue"
0x103ad7cf9 <+71>: movq %rbx, %rdi
0x103ad7cfc <+74>: callq *%r13
0x103ad7cff <+77>: movq %rax, %r15
0x103ad7d02 <+80>: movq %rbx, %rdi
0x103ad7d05 <+83>: callq *0x207d0d(%rip) ; (void *)0x0000000105e6e9b0: objc_release
0x103ad7d0b <+89>: testq %r15, %r15
0x103ad7d0e <+92>: je 0x103ad7d74 ; <+194> at FBSDKInternalUtility.m:456
0x103ad7d10 <+94>: cmpq $0x1, %r15
0x103ad7d14 <+98>: jne 0x103ad7d2f ; <+125> at FBSDKInternalUtility.m:454
0x103ad7d16 <+100>: movq 0x537583(%rip), %rdi ; _transientObjects
0x103ad7d1d <+107>: movq 0x2f9184(%rip), %rsi ; "removeObjectForKey:"
0x103ad7d24 <+114>: movq %r14, %rdx
0x103ad7d27 <+117>: callq *0x207ce3(%rip) ; (void *)0x0000000105e71000: objc_msgSend
0x103ad7d2d <+123>: jmp 0x103ad7d74 ; <+194> at FBSDKInternalUtility.m:456
0x103ad7d2f <+125>: movq 0x53756a(%rip), %r12 ; _transientObjects
0x103ad7d36 <+132>: movq 0x302fa3(%rip), %rdi ; (void *)0x0000000105d0cb88: NSNumber
0x103ad7d3d <+139>: decq %r15
0x103ad7d40 <+142>: movq 0x2f92d9(%rip), %rsi ; "numberWithUnsignedLong:"
0x103ad7d47 <+149>: movq %r15, %rdx
0x103ad7d4a <+152>: callq *%r13
0x103ad7d4d <+155>: movq %rax, %rdi
0x103ad7d50 <+158>: callq 0x103c2e7e0 ; symbol stub for: objc_retainAutoreleasedReturnValue
0x103ad7d55 <+163>: movq %rax, %rbx
0x103ad7d58 <+166>: movq 0x2f99e1(%rip), %rsi ; "setObject:forKey:"
0x103ad7d5f <+173>: movq %r12, %rdi
0x103ad7d62 <+176>: movq %rbx, %rdx
0x103ad7d65 <+179>: movq %r14, %rcx
0x103ad7d68 <+182>: callq *%r13
0x103ad7d6b <+185>: movq %rbx, %rdi
0x103ad7d6e <+188>: callq *0x207ca4(%rip) ; (void *)0x0000000105e6e9b0: objc_release
0x103ad7d74 <+194>: movq %r14, %rdi
0x103ad7d77 <+197>: addq $0x8, %rsp
0x103ad7d7b <+201>: popq %rbx
0x103ad7d7c <+202>: popq %r12
0x103ad7d7e <+204>: popq %r13
0x103ad7d80 <+206>: popq %r14
0x103ad7d82 <+208>: popq %r15
0x103ad7d84 <+210>: popq %rbp
0x103ad7d85 <+211>: jmpq *0x207c8d(%rip) ; (void *)0x0000000105e6e9b0: objc_release
I've also witnessed this crash today. In the exactly same place, i.e. [FBSDKInternalUtility unregisterTransientObject:] and after executing exactly the same steps (FB login -> enter credentials -> Cancel button -> crash).
Seems to affect not only iOS Facebook SDK v4.5.1 but also v4.6 and v4.1.0.
#IBAction func btnFBLoginPressed(sender: AnyObject) {
let fbLoginManager : FBSDKLoginManager = FBSDKLoginManager()
fbLoginManager.logInWithPublishPermissions(["publish_actions"], fromViewController: self, handler: { (result, error) -> Void in
if (error == nil){ //--> From here I prevent that error
if result.isCancelled {
print("button is cancelled")
} else {
let fbloginresult : FBSDKLoginManagerLoginResult = result
if(fbloginresult.grantedPermissions.contains("publish_actions")){
self.getFBUserData()
}
}
}
})
}
func getFBUserData(){
if((FBSDKAccessToken.currentAccessToken()) != nil){
print(FBSDKAccessToken.currentAccessToken().tokenString)
// FBSDKGraphRequest(graphPath: "me", parameters: ["fields": "id, name, first_name, last_name, picture.type(large), email"]).startWithCompletionHandler({ (connection, result, error) -> Void in
// if (error == nil){
// print(result)
// }
// })
}
}

Swift error when saving a child object using core data

I am getting the following error when attempting to perform my save function in a view on my app. I have passed my parent object in called Vacation. I am attempting to save a child object called SavingsEntry. The app stopped and shows
(lldb)
In the console and
libswiftCore.dylib`swift_dynamicCastClassUnconditional:
0x10c13b860: pushq %rbp
0x10c13b861: movq %rsp, %rbp
0x10c13b864: testq %rdi, %rdi
0x10c13b867: je 0x10c13b89e ;swift_dynamicCastClassUnconditional + 62
0x10c13b869: movabsq $-0x7fffffffffffffff, %rax
0x10c13b873: testq %rax, %rdi
0x10c13b876: jne 0x10c13b89e ; swift_dynamicCastClassUnconditional + 62
0x10c13b878: leaq 0xb52e9(%rip), %rax
0x10c13b87f: movq (%rax), %rax
0x10c13b882: andq (%rdi), %rax
0x10c13b885: nopw %cs:(%rax,%rax)
0x10c13b890: cmpq %rsi, %rax
0x10c13b893: je 0x10c13b8ad ; swift_dynamicCastClassUnconditional + 77
0x10c13b895: movq 0x8(%rax), %rax
0x10c13b899: testq %rax, %rax
0x10c13b89c: jne 0x10c13b890 ; swift_dynamicCastClassUnconditional + 48
0x10c13b89e: leaq 0x36b7d(%rip), %rax ; "Swift dynamic cast failed"
0x10c13b8a5: movq %rax, 0xb4c0c(%rip) ; gCRAnnotations + 8
0x10c13b8ac: int3
0x10c13b8ad: movq %rdi, %rax **Thread1:EXC_BREAKPOINT (code=EXC_I386_BPT,subcode=0x0)**
0x10c13b8b0: popq %rbp
0x10c13b8b1: retq
0x10c13b8b2: nopw %cs:(%rax,%rax)
Ive narrowed down the break is in the section where I am saving setting my object values and saving. But I can't see where the problem is.
if let managedObjectContext = (UIApplication.sharedApplication().delegate as AppDelegate).managedObjectContext {
savingsEntry = NSEntityDescription.insertNewObjectForEntityForName("SavingsEntry", inManagedObjectContext: managedObjectContext) as SavingsEntry
savingsEntry.vacation = vacation
savingsEntry.created = NSDate()
if addToSavings.text == "" {
savingsEntry.amount = NSDecimalNumber(string: removeFromSavings.text)
savingsEntry.type = "debit"
vacation.totalSaved = subtraction(vacation.totalSaved, right: savingsEntry.amount)
} else if removeFromSavings.text == "" {
savingsEntry.amount = NSDecimalNumber(string: addToSavings.text)
savingsEntry.type = "credit"
vacation.totalSaved = addition(vacation.totalSaved, right: savingsEntry.amount)
}
var e: NSError?
if managedObjectContext.save(&e) != true {
println("insert error: \(e!.localizedDescription)")
return
}
}

Resources