0

This seems like it should be so simple - I have researched and looked and tried different things and just can't figure it out. I have a view controller which allows a user to enter their own review of a winery. Its a modal view from a detail winery page - I am simply trying to populate a Label in this modal view with the winery name from the previous view. (then saving the winery name and the users review) the review part worked fine - its transferring the name over that is giving me fits crashing on me with "Swift Dynamic Cast Failed" Any help is greatly appreciated see code:

"review" view controller:

import UIKit
import CoreData

class MyReviewViewController: UIViewController {

var myreview:wineryReview!
var passName:String!


@IBOutlet weak var wineryNameLabel:UILabel!
@IBOutlet weak var myReview:UITextView!

override func viewDidLoad() {
    super.viewDidLoad()

    // Do any additional setup after loading the view.

    wineryNameLabel.text = passName

the code of the passing tableviewcontroller:

var wineryNames = "Glenora Wine Cellars"
(because I am just testing functionaility the variable is just simply called)         in the class

// MARK: - Navigation


 override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject!) {
    if segue.identifier == "mapWinery" {
        let mvc = segue.destinationViewController as WineryMapViewController
        mvc.wineryMap = wineryAddress
    }
    if segue.identifier == "goToMyReview" {
        let mrvc = segue.destinationViewController as MyReviewViewController
        mrvc.passName = wineryNames
    }

}

Error:

libswiftCore.dylib swift_dynamicCastClassUnconditional: 0x103450860: pushq %rbp 0x103450861: movq %rsp, %rbp 0x103450864: testq %rdi, %rdi 0x103450867: je 0x10345089e ; swift_dynamicCastClassUnconditional + 62 0x103450869: movabsq $-0x7fffffffffffffff, %rax 0x103450873: testq %rax, %rdi 0x103450876: jne 0x10345089e ; swift_dynamicCastClassUnconditional + 62 0x103450878: leaq 0xb52e9(%rip), %rax 0x10345087f: movq (%rax), %rax 0x103450882: andq (%rdi), %rax 0x103450885: nopw %cs:(%rax,%rax) 0x103450890: cmpq %rsi, %rax 0x103450893: je 0x1034508ad ; swift_dynamicCastClassUnconditional + 77 0x103450895: movq 0x8(%rax), %rax 0x103450899: testq %rax, %rax 0x10345089c: jne 0x103450890 ; swift_dynamicCastClassUnconditional + 48 0x10345089e: leaq 0x36b7d(%rip), %rax ; "Swift dynamic cast failed" 0x1034508a5: movq %rax, 0xb4c0c(%rip) ; gCRAnnotations + 8 0x1034508ac: int3
0x1034508ad: movq %rdi, %rax 0x1034508b0: popq %rbp 0x1034508b1: retq
0x1034508b2: nopw %cs:(%rax,%rax)

Mike Gibbs
  • 35
  • 1
  • 9
  • When is this occurring? Should save be executing or just viewdidload? – Nick Feb 03 '15 at 00:57
  • http://stackoverflow.com/questions/26307335/swift-dynamiccastclassunconditional-issues-in-swift – rakeshbs Feb 03 '15 at 01:00
  • just view did load - it crashes when the button is pressed which takes you to this view controller - save only executes upon a save button press in this view – Mike Gibbs Feb 03 '15 at 01:00
  • @MikeGibbs Do you have something in prepareforsegue in the previous view controller that sets passName? That's more relevant than the save function you've included but doesn't get a chance to run. – Nick Feb 03 '15 at 01:05
  • yes as follows: 'override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject!) { if segue.identifier == "mapWinery" { let mvc = segue.destinationViewController as WineryMapViewController mvc.wineryMap = wineryAddress } if segue.identifier == "goToMyReview" { let mrvc = segue.destinationViewController as MyReviewViewController mrvc.passName = wineryNames }' } – Mike Gibbs Feb 03 '15 at 01:07
  • I know this should work as you can see I have to prepareforsegues and the first one works fine when I pass it to a different view controller – Mike Gibbs Feb 03 '15 at 01:08
  • Are you sure `wineryNames` is a `String`? Where does that get set? Edit the original post if you can. – Nick Feb 03 '15 at 01:10
  • Use debugger, otherwise this like looking for a needle in a haystack. – Sulthan Feb 03 '15 at 01:35
  • `passName` and `myreview` should be optionals (? not !), they don't exist when the class is instantiated. – Nick Feb 03 '15 at 02:25
  • @Nick - I changed prepareforsegue - anyobject? with a question mark and in the destination view controller my var passName:String? with a question mark - still no luck - my review stays with an exclamation point as it refers to my entity class. – Mike Gibbs Feb 03 '15 at 02:42
  • @Sulthan what am I looking for in the debugger? I am still learning and not really clear what I am looking at when I go through the debugger – Mike Gibbs Feb 03 '15 at 02:43

0 Answers0