swift - Object Not Passing in NavigationController -


i having issue that's confusing me. converting project objective-c swift , using storyboards first time. app downloads rss data , stores title, link , pubdate in article object in coredata. when user clicks row loads article in webview.

the issue having has passing article object the webview. able pass button placed on tableviewcell selecting cell causes app crash , says article object passed webview nil. if test before passing println(), shows not nil.

here code using button placed on cell.

@ibaction func article(sender: anyobject)     {         // pulling recent story display on homeviewcontroller         let fetchrequest = nsfetchrequest(entityname: "article")         let predicate = nspredicate(format: "feed == 'flo cycling' or feed == 'triathlete' or feed == 'velo news' or feed == 'cycling news' or feed == 'ironman'")         fetchrequest.predicate = predicate         let sortdescriptor = nssortdescriptor(key: "pubdate", ascending: true)         fetchrequest.sortdescriptors = [sortdescriptor]          // set nserror fetch         var fetcherror : nserror?         // when perform fetch returned object array of atricle entities.         let fetchedobjects = self.articlecontext.executefetchrequest(fetchrequest, error: &fetcherror) as! [article]          //grab latest article , place title in label in homeviewcontroller         self.latestarticle = fetchedobjects.last          // grab latestarticleviewcontroller can presented modally.  make sure set storyboard identifier.         self.articleview = self.storyboard!.instantiateviewcontrollerwithidentifier("articleviewcontroller") as? articleviewcontroller         self.articleview!.currentarticle = self.latestarticle         self.articleview!.articlecontext = self.articlecontext         self.presentviewcontroller(self.articleview!, animated: true, completion: nil)     } 

here code using didselectrowatindexpath

override func tableview(tableview: uitableview, didselectrowatindexpath indexpath: nsindexpath) {     let selectedarticle = self.fetchedresultscontroller!.objectatindexpath(indexpath) as? article     self.articleview = self.storyboard!.instantiateviewcontrollerwithidentifier("articleviewcontroller") as? articleviewcontroller     self.articleview!.currentarticle = selectedarticle     self.articleview!.articlecontext = self.articlecontext     println("this coming didselectrowatindexpath \(self.articleview!.currentarticle!.link)")      self.navigationcontroller!.pushviewcontroller(self.articleview!, animated: true)      tableview.deselectrowatindexpath(indexpath, animated: true) } 

here picture of app button on cell.

enter image description here

this happens when tap button.

enter image description here

here output console when touch cell. can see println() shows article has link.

this coming didselectrowatindexpath http://flocycling.blogspot.com/2015/05/order-20-of-details-its-hard-to-believe.html fatal error: unexpectedly found nil while unwrapping optional value

here screen shot of line app crashes on.

enter image description here

any appreciated.

current article declaration , initialization

currentarticle declared in articleviewcontroller in following way.

    class articleviewcontroller: uiviewcontroller, uiwebviewdelegate, mfmailcomposeviewcontrollerdelegate {     // properties     var currentarticle : article? } 

as initialization in didselectrowatindexpath method following initialize value articleviewcontroller load.

    let selectedarticle = self.fetchedresultscontroller!.objectatindexpath(indexpath) as? article self.articleview!.currentarticle = selectedarticle 

which equivalent when tap button following. or @ least think it's same.

self.latestarticle = fetchedobjects.last self.articleview!.currentarticle = self.latestarticle 

two errors thrown

2015-05-31 18:42:38.227 flocycling1.1.1[98389:6596654] coredata: error: failed call designated initializer on nsmanagedobject class 'flocycling1_1_1.article' 2015-05-31 18:42:38.227 flocycling1.1.1[98389:6596654] -[flocycling1_1_1.article link]: unrecognized selector sent instance 0x7f81ead7f940

take care,

jon

your var currentarticle not initialized time calling it, see in pic you're did lazy initialization in code, repete variable , should start work fine, append example below:

lazy var currentarticle: article = {     let article = article()     //any other initialization need     return article }() 

i hope you!


Comments

Popular posts from this blog

angularjs - ADAL JS Angular- WebAPI add a new role claim to the token -

php - CakePHP HttpSockets send array of paramms -

node.js - Using Node without global install -