2

I am currently making an app and I am using Swft 3 with Xcode 8.2 beta. I am trying to make it so that the user is able to access the social media from the SWRevealViewController in my iOS project. When the social media buttons are clicked they should open up the corresponding app. However, when the code is executed and the iOS simulator is opened, when I slide to open up the SWRevealViewController(the menu), the app crashes.

Full Error message:

 *** Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<TheGunnOracleApp.SocialMedia 0x7ffd0d50c0d0> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key dataSource.'
*** First throw call stack:
(
    0   CoreFoundation                      0x000000010212dd4b __exceptionPreprocess + 171
    1   libobjc.A.dylib                     0x0000000101b8f21e objc_exception_throw + 48
    2   CoreFoundation                      0x000000010212dc99 -[NSException raise] + 9
    3   Foundation                          0x000000010169db3f -[NSObject(NSKeyValueCoding) setValue:forKey:] + 291
    4   UIKit                               0x0000000102e8e99f -[UIViewController setValue:forKey:] + 88
    5   UIKit                               0x0000000103102c6e -[UIRuntimeOutletConnection connect] + 109
    6   CoreFoundation                      0x00000001020d2b60 -[NSArray makeObjectsPerformSelector:] + 256
    7   UIKit                               0x00000001031015f2 -[UINib instantiateWithOwner:options:] + 1867
    8   UIKit                               0x0000000102e950d1 -[UIViewController _loadViewFromNibNamed:bundle:] + 386
    9   UIKit                               0x0000000102e959f3 -[UIViewController loadView] + 177
    10  UIKit                               0x000000010311561c -[UITableViewController loadView] + 84
    11  UIKit                               0x0000000102e95d28 -[UIViewController loadViewIfRequired] + 201
    12  UIKit                               0x0000000102e9657c -[UIViewController view] + 27
    13  TheGunnOracleApp                    0x00000001014d50fb -[SWRevealViewController _deployForViewController:inView:] + 235
    14  TheGunnOracleApp                    0x00000001014d4f58 -[SWRevealViewController _deploymentForViewController:inView:appear:disappear:] + 136
    15  TheGunnOracleApp                    0x00000001014d48c1 -[SWRevealViewController _rearViewDeploymentForNewFrontViewPosition:] + 433
    16  TheGunnOracleApp                    0x00000001014d32f2 -[SWRevealViewController _setFrontViewPosition:withDuration:] + 82
    17  TheGunnOracleApp                    0x00000001014d26c6 __65-[SWRevealViewController _dispatchSetFrontViewPosition:animated:]_block_invoke + 70
    18  TheGunnOracleApp                    0x00000001014d1300 -[SWRevealViewController _enqueueBlock:] + 160
    19  TheGunnOracleApp                    0x00000001014d261b -[SWRevealViewController _dispatchSetFrontViewPosition:animated:] + 251
    20  TheGunnOracleApp                    0x00000001014d0154 -[SWRevealViewController setFrontViewPosition:animated:] + 148
    21  TheGunnOracleApp                    0x00000001014cffed -[SWRevealViewController revealToggleAnimated:] + 93
    22  TheGunnOracleApp                    0x00000001014d05df -[SWRevealViewController revealToggle:] + 63
    23  UIKit                               0x0000000102cf645c -[UIApplication sendAction:to:from:forEvent:] + 83
    24  UIKit                               0x0000000103137971 -[UIBarButtonItem(UIInternal) _sendAction:withEvent:] + 149
    25  UIKit                               0x0000000102cf645c -[UIApplication sendAction:to:from:forEvent:] + 83
    26  UIKit                               0x0000000102e7c344 -[UIControl sendAction:to:forEvent:] + 67
    27  UIKit                               0x0000000102e7c65d -[UIControl _sendActionsForEvents:withEvent:] + 444
    28  UIKit                               0x0000000102e7c7e7 -[UIControl _sendActionsForEvents:withEvent:] + 838
    29  UIKit                               0x0000000102e7b559 -[UIControl touchesEnded:withEvent:] + 668
    30  UIKit                               0x0000000102d63d5d -[UIWindow _sendTouchesForEvent:] + 2747
    31  UIKit                               0x0000000102d6544b -[UIWindow sendEvent:] + 4011
    32  UIKit                               0x0000000102d1254b -[UIApplication sendEvent:] + 371
    33  UIKit                               0x00000001034fda0f __dispatchPreprocessedEventFromEventQueue + 3248
    34  UIKit                               0x00000001034f6745 __handleEventQueue + 4879
    35  CoreFoundation                      0x00000001020d28e1 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
    36  CoreFoundation                      0x00000001020b7b0c __CFRunLoopDoSources0 + 556
    37  CoreFoundation                      0x00000001020b6ff6 __CFRunLoopRun + 918
    38  CoreFoundation                      0x00000001020b6a04 CFRunLoopRunSpecific + 420
    39  GraphicsServices                    0x0000000107e37a6f GSEventRunModal + 161
    40  UIKit                               0x0000000102cf4808 UIApplicationMain + 159
    41  TheGunnOracleApp                    0x00000001014f2d0f main + 111
    42  libdyld.dylib                       0x0000000105ddd68d start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb) 

Here is the code for each button in the social media.

Note: I removed code for the rest of the social media because of Facebook not working at first:

import Foundation
import UIKit

class SocialMedia: UITableViewController{
    @IBAction func facebookOpen(_ sender: Any) {
        UIApplication.shared.open(NSURL(string: "https://www.facebook.com/gunnoracle")! as URL)
    }
}

Here is a screenshot of what my Main.storyboard UITableViewController looks like:

SocialMedia

Rajat Khare
  • 522
  • 8
  • 26

1 Answers1

0

Seems that the problem is not caused by that very line of code as I just tried it and it worked.

when I slide to open up the SWRevealViewController(the menu), the app crashes.

This is might be the cause. Something wrong with how you use SWRevealViewController.

Fitsyu
  • 860
  • 11
  • 19
  • 1
    when I don't include the SocialMedia class though, the SWRevealViewController's opening works fine.. – Rajat Khare Mar 25 '17 at 05:23
  • I'm thinking that it must do to how I ordered buttons in my SWRevealViewController or something about the class. Otherwise, I'm clueless right now. – Rajat Khare Mar 25 '17 at 05:28
  • What do you mean by SocialMedia class? – Fitsyu Mar 25 '17 at 05:38
  • The class for SocialMedia that is in the first code I have on my question. "class SocialMedia: UITableViewController{ @IBAction func facebookOpen(_ sender: Any) { UIApplication.shared.open(NSURL(string: "https://www.facebook.com/gunnoracle")! as URL) } }" – Rajat Khare Mar 25 '17 at 05:39
  • Looking at your storyboard, I think SocialMedia class should inherits from UITableViewCell not UITableViewController. – Fitsyu Mar 25 '17 at 05:42
  • when I try to connect my SocialMedia buttons to the class when using UITableViewCell, they won't connect – Rajat Khare Mar 25 '17 at 05:48
  • did you change the class name in identity inspector? – Fitsyu Mar 25 '17 at 05:53
  • yes I have changed the class name in the identity inspector, and I still cannot control drag my button, when the class is inherited to a UITableViewCell – Rajat Khare Mar 25 '17 at 06:19
  • @RajatKhare - shall i delete my answer if it is not useful – Anbu.Karthik Mar 27 '17 at 10:11
  • @Anbu.Karthikn yes you may delete it if you please. It may help others though. – Rajat Khare Mar 28 '17 at 20:55