Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

iOS Build a Playlist Browser with Swift Using a Navigation Controller With Segues Modifying the UI

Wants "as!" instead of "as"

It keeps asking me "'Any Object' is not convertible to 'PlaylistDetailViewController', did you mean to use 'as!" to use 'as!' to force downcast?"

Where did I go wrong??

Here's my code...

override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) { if segue.identifier == "showPlaylistDetailSegue" { let playlistDetailController = segue.destinationViewController as PlaylistDetailViewController

3 Answers

Hi Beth,

Don't panic - this isn't your fault!

Your code is fine; you've not gone wrong - but accept the suggested change. as! is the new as (it isn't that simple).

The latest release of Xcode included a change into how types are handled. Follow the code in the videos as normal and accept the suggested changes that crop up. This is one of them. If you come across errors like this, just accept the "fix-it" and post in here if that doesn't work. That advice applies only to the as -vs- as! warning because I'm not sure what else was changed in the last release - I will look into that this week.

Keep coding!

Steve.

Joakim Mattsson
Joakim Mattsson
3,074 Points

Hey Steve,

Im got the same error and just replacing the as with as! works in xCode. However when you run the app and presses the button you get an error instead.

Hi Joakim

I've run my code and it is working fine with the new as! inserted.

Can you show the error messages that you're getting in your console, please?

We can get to the bottom of your problem with a bit of digging.

Steve.

Joakim Mattsson
Joakim Mattsson
3,074 Points

Thank you for the fast response. Here is a print from my xCode. http://imgur.com/BtKF8WN

edit: Something i realised when having simulator up but not running the application in xCode the button works great. But during 'build' in xCode i get the error.

OK - when you stop the app it should produce some more detailed logs of the problem in the lower pane. Can you paste that in?

It looks like something to do with the segue, obviously, but the console output should give us some more info.

Joakim Mattsson
Joakim Mattsson
3,074 Points

Im so sorry for taking up your time. Realised I had placed a breakpoint at that row and therefore its paused every time i ran the app. Thanks for the great support tho. Have a great day ahead.

Ha! Glad you got it fixed!

Steve.

Eunice Cheung
Eunice Cheung
1,987 Points

When I use as! I can't pass information between views.

Kenton Raiford
Kenton Raiford
5,101 Points

I have the same issue, but I haven't been able to fix it. When I click on the button my app crashes. Below is my error:

2015-07-18 13:41:25.440 Algorhythm[2843:186395] -[NSLayoutConstraint setText:]: unrecognized selector sent to instance 0x7fdf92c934b0 2015-07-18 13:41:25.444 Algorhythm[2843:186395] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NSLayoutConstraint setText:]: unrecognized selector sent to instance 0x7fdf92c934b0' *** First throw call stack: ( 0 CoreFoundation 0x00000001078b3c65 exceptionPreprocess + 165 1 libobjc.A.dylib 0x000000010941ebb7 objc_exception_throw + 45 2 CoreFoundation 0x00000001078bb0ad -[NSObject(NSObject) doesNotRecognizeSelector:] + 205 3 CoreFoundation 0x000000010781113c ___forwarding_ + 988 4 CoreFoundation 0x0000000107810cd8 CF_forwarding_prep_0 + 120 5 Algorhythm 0x00000001076b0b5a _TFC10Algorhythm28PlaylistDetailViewController11viewDidLoadfS0_FT_T + 410 6 Algorhythm 0x00000001076b0c02 TToFC10Algorhythm28PlaylistDetailViewController11viewDidLoadfS0_FT_T + 34 7 UIKit 0x00000001082831d0 -[UIViewController loadViewIfRequired] + 738 8 UIKit 0x00000001082833ce -[UIViewController view] + 27 9 UIKit 0x00000001082a8257 -[UINavigationController startCustomTransition:] + 633 10 UIKit 0x00000001082b437f -[UINavigationController _startDeferredTransitionIfNeeded:] + 386 11 UIKit 0x00000001082b4ece -[UINavigationController __viewWillLayoutSubviews] + 43 12 UIKit 0x00000001083ff6d5 -[UILayoutContainerView layoutSubviews] + 202 13 UIKit 0x00000001081d29eb -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 536 14 QuartzCore 0x000000010bfa0ed2 -[CALayer layoutSublayers] + 146 15 QuartzCore 0x000000010bf956e6 _ZN2CA5Layer16layout_if_neededEPNS_11TransactionE + 380 16 QuartzCore 0x000000010bf95556 _ZN2CA5Layer28layout_and_display_if_neededEPNS_11TransactionE + 24 17 QuartzCore 0x000000010bf0186e _ZN2CA7Context18commit_transactionEPNS_11TransactionE + 242 18 QuartzCore 0x000000010bf02a22 _ZN2CA11Transaction6commitEv + 462 19 UIKit 0x000000010814f5e6 _UIApplicationHandleEventQueue + 2140 20 CoreFoundation 0x00000001077e7431 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION_ + 17 21 CoreFoundation 0x00000001077dd2fd __CFRunLoopDoSources0 + 269 22 CoreFoundation 0x00000001077dc934 __CFRunLoopRun + 868 23 CoreFoundation 0x00000001077dc366 CFRunLoopRunSpecific + 470 24 GraphicsServices 0x000000010b887a3e GSEventRunModal + 161 25 UIKit 0x00000001081528c0 UIApplicationMain + 1282 26 Algorhythm 0x00000001076b8ec7 main + 135 27 libdyld.dylib 0x0000000109b54145 start + 1 ) libc++abi.dylib: terminating with uncaught exception of type NSException (lldb)

gökhan sayılgan
gökhan sayılgan
2,285 Points

yes the problem is segue and the error says İnstance member 'segueLAbelText' cannot be used on type 'PlaylistDetailViewController' .
please help me i can't get rid of it Thank you

Can you post your code please. That will help us track down any issues.

Steve.

gökhan sayılgan
gökhan sayılgan
2,285 Points

hi Steve Hunter i download the project given below actually it says you should use just a ! operator. there must be something else wrong but their code working and my code seem same to me. i copy paste Pasan's code and it works :D thank you any way !!!

As long as you're on your way, that's great.

Any other problems, just shout and I'll help if I can.

Steve.