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 Displaying API Data with Collection Views in Objective-C Show Me the Data - API’s, OAuth, and NSURLSession Gettings Started with OAuth 2.0

Video might be outdated. SimpleAuth/Foursquare launches it’s WebView then crashes. Anybody get it working?

So Xcode 8 forces you to convert any Swift code you might have in your project — including any code inside of your project’s dependencies — to either Swift 2.3 or Swift 3.0. Complying with Xcode’s demands seems to have no adverse effects for most of SimpleAuth’s dependencies with the exception of ReactiveCocoa; ReactiveCocoa throws like 17 errors upon conversion. The only way around this, then, is to set the Use Legacy Swift Language Version property of each project to YES (the setting can be found in each project’s Build Settings). The easiest method of doing this would be to add the following to the bottom of your Podfile:

post_install do |installer|
  installer.pods_project.targets.each do |target|
    target.build_configurations.each do |config|
      config.build_settings['SWIFT_VERSION'] = 2.3
    end
  end
end

StackOverflow reference


So, that allows the project to compile. Unfortunately, there now seems to be something wrong with SimpleAuth/Foursquare. I set up the SimpleAuth configuration in AppDelegate#didFinishLaunchingWithOptions, like so:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {   
    SimpleAuth.configuration[@"foursquare-web"] = @{@"client_id:":@"<CLIENT_ID_HIDDEN>",@"redirect_uri":@"photoPhun://auth/foursquare"};
    return YES;
}

And I’m calling SimpleAuth#authorize in my TPPUICollectionViewController#viewDidLoad, like this:

- (void)viewDidLoad {
    [super viewDidLoad];

    // CollectionView setup…

    [SimpleAuth authorize:@"foursquare-web" completion:^(id responseObject, NSError *error) {
        NSLog(@"\nResponse: %@\nError:%@", responseObject, error);
    }];

    // Load photos or whatever …
}

When I build and run the app, the CollectionView displays it’s content as expected and, subsequently, SimpleAuth’s WebView modal slides up… but then it crashes; the expected Foursquare login screen is not displayed. The first error in the stack trace says:

*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[__NSPlaceholderDictionary initWithObjects:forKeys:count:]: attempt to insert nil object from objects[0]'

It appears that some dictionary somewhere has a nil value where one should not be. Furthermore, this dictionary seems to have origins inside of SimpleAuth. Not sure if this has something to do with the config that I gave to SimpleAuth; I double-checked my credentials and everything seems correct on my side. So, yeah, I’m stuck. Any ideas?

CC: Gabe Nadel Ben Jakuben Pasan Premaratne

Update: Filed this issue on GitHub.

I am also having exactly the same issue.... The video needs updating or an addendum needs adding.

Caleb Kleveter
Caleb Kleveter
Treehouse Moderator 37,862 Points

Add an exception break point to you project in the breakpoints pane. See where it crashes.

Did that already, Caleb; I know where it crashes... just not sure why. Check out the GitHub issue I linked above.

10 Answers

Amit Bijlani
STAFF
Amit Bijlani
Treehouse Guest Teacher

Sorry about that. I've updated the project files for Xcode 8.

Here are the steps to make it compatible with Xcode 8.

1. When prompted by Xcode to upgrade the Swift version, uncheck all targets and only select the PhotoPhun target.

2. Add the following to the Podfile:

use_frameworks!

target 'PhotoPhun' do
  pod 'SimpleAuth', '0.3.9'
  pod 'SAMCache'
  pod 'ReactiveCocoa', '4.2.2'
end

3. Make sure that the ReactiveCocoa framework is set to use Legacy Swift.

Followed the above and I am now getting the following issue:- /PhotoPhun/Pods/SimpleAuth/Providers/TwitterWeb/SimpleAuthTwitterWebProvider.m:14:9: 'cocoa-oauth/GCOAuth.h' file not found

But if I change the Podfile to say SimpleAuth/FoursquareWeb then it does now compile. I have yet to try adding any of the SimpleAuth stuff to the project... Which will be the next step.

Still not working. The SimpleAuth authorize call is returning null for the responseObject and the error.

    [SimpleAuth authorize:@"foursquare-web" completion:^(id responseObject, NSError *error) {
        NSLog(@"Error:%@ \n Response:%@ ",error, responseObject);
    }];

My Pod File is

 Uncomment this line to define a global platform for your project
# platform :ios, '9.0'

target 'PhotoPhun' do
  # Uncomment this line if you're using Swift or would like to use dynamic framew$
  use_frameworks!

  pod 'SimpleAuth/FoursquareWeb', '0.3.2'
  pod 'SAMCache'

  # Pods for PhotoPhun

  target 'PhotoPhunTests' do
    inherit! :search_paths
    # Pods for testing
  end

end

Works when I remove the 0.3.2 from the SimpleAuth

Amit Bijlani
STAFF
Amit Bijlani
Treehouse Guest Teacher

If you have followed the steps I outlined above and are now receiving nil in the responseObject then you must follow the steps outlined below.

1. Clear the derived data folder. You can access it via the menu Xcode > Preferences > Locations. Click on the arrow next to Derived Data and delete the folder in Finder

2. Update the Cocoapods version in your Gemfile:

gem 'cocoapods', '1.1.1'

3. Edit your Podfile:

source 'https://github.com/CocoaPods/Specs.git'
use_frameworks!

platform :ios, '8.0'
xcodeproj 'PhotoPhun'
workspace 'PhotoPhun'

target 'PhotoPhun' do

    pod 'SimpleAuth', '0.3.9'
    pod 'SAMCache'

end

post_install do |_|
    work_dir = Dir.pwd
    file_name = "#{work_dir}/Pods/Target\ Support\ Files/SimpleAuth/SimpleAuth.xcconfig"
    config = File.read(file_name)
    new_config = config.gsub(/HEADER_SEARCH_PATHS = "/, 'HEADER_SEARCH_PATHS = "${PODS_ROOT}" "')
    File.open(file_name, 'w') { |file| file << new_config }
end

4. Build and run! You should now have an access token and a valid response object.

Thanks Amit Bijlani. Your solution worked for me!

It is Seriously confusing for a Beginner Can you post a simplified solution as in at what step i need to do what ? I followed adding post_install do |installer| installer.pods_project.targets.each do |target| target.build_configurations.each do |config| config.build_settings['SWIFT_VERSION'] = ‘2.3’ end end end to my pod file and then install pod and now i see 7 compile error and most of them say cannot compile objective-cmodule andwhere is gem file that you want me to update ?

Please help this outdated video as seriously depressed me to limits

Amit Bijlani
STAFF
Amit Bijlani
Treehouse Guest Teacher

Hello everyone, seems like my previously posted solution is no longer working. The main issue is with SimpleAuth. I'm currently working on updating this course and apologize for the inconvenience. A new version will be released later in March. In the interim I will see if I can post a separate set of instructions so it does not get lost in this thread. Thank you for your patience.

PS. The new course will avoid OAuth and will focus on collection views instead. We would like to know how important it is it is to you to learn about OAuth. Please reply with a comment.

Hi Amit Bijlani,

It will be great if you guys can create a dedicate video about OAuth since it is so important part of app authentication and networking.

Thanks, George

Jonathan Law
seal-mask
.a{fill-rule:evenodd;}techdegree
Jonathan Law
iOS Development Techdegree Student 6,824 Points

Really confused here. When I add:

import <SimpleAuth/SimpleAuth.h>

to the TPPCollectionViewController header, I get a compiler error:

SimpleAuth/SimpleAuth.h file not found

Can't tell if this is related to above issues mentioned in this thread or not. I am totally new to using CocoaPods. Also, I don't see any file for the "Podfile" in the list of files in the program (although one appears on Gabe's xCode project in the video.)

I am using the .xcworkspace file, not the original project and there IS a folder named Pods in the file list but nothing for "Podfile." Can't tell if I did something wrong and am unsure if its related to above issues. Anyone have thoughts on this?

Jonathan Law
seal-mask
.a{fill-rule:evenodd;}techdegree
Jonathan Law
iOS Development Techdegree Student 6,824 Points

Update: Podfile issue solved. Somehow during the lag (and 'window confusion') of updating I DID open the old file instead of .xcworkspace by mistake.

Unfortunately, I think this just puts me where everyone else is now concerning the SimpleAuth issue...

Hi Jonathan,

Edit your podfile to the following:-

Uncomment this line to define a global platform for your project
# platform :ios, '9.0'

target 'PhotoPhun' do
  # Uncomment this line if you're using Swift or would like to use dynamic framew$
  use_frameworks!

  pod 'SimpleAuth/FoursquareWeb'
  pod 'SAMCache'

  # Pods for PhotoPhun

  target 'PhotoPhunTests' do
    inherit! :search_paths
    # Pods for testing
  end

end

And then in the terminal make sure you are in the correct project folder and do pod update. See if that fixes your errors.

Amit Bijlani
STAFF
Amit Bijlani
Treehouse Guest Teacher

We are working on updating this course. Meanwhile, if anyone still has issues can you please share your project to see how we can help.

Kevin Murphy
Kevin Murphy
24,380 Points

Getting NULL also as response from the call to SimpleAuth - Anyone get a valid response object yet? The podfile / reactiveCocoa legacy Swift instructions were helpful as far as getting the project to build/run.

Kevin Murphy
Kevin Murphy
24,380 Points

Any news to report on this Amit Bijlani ? Please note my earlier comment above.

Amit Bijlani
Amit Bijlani
Treehouse Guest Teacher

Kevin Murphy can you please share you project so I can take a look?

Kevin Murphy
Kevin Murphy
24,380 Points

Amit Bijlani Sure I can do that. I'll post to github tomorrow unless you have an alternate method of sharing you'd recommend.

Kevin Murphy
Kevin Murphy
24,380 Points

Ok Amit Bijlani my project is on github at this link: https://github.com/murphykevin/UICollectionViewObjCTreehouse

Thanks for looking into this.

Nicole Owens
Nicole Owens
1,502 Points

Was there a fix to this problem? I am experiencing the exact same thing and cannot find a solution. Thanks

Faris Zaman
Faris Zaman
2,802 Points

Still getting a null response to the responseObject. Would it be possible to maybe upload an updated xcodeproject to the download file list? To allow comparison to where the last file was finished, currently the suggested troubleshoots to solve this problem aren't working. Editing the podfile as suggested actually leads to the initial problem of reactiveSwift being included and as a result a tonne of compiler errors. A response would be highly appreciate by both others still strugling and myself Amit Bijlani

Aleksandrs Muravjovs
Aleksandrs Muravjovs
1,734 Points

Can't get SimpleAuth work. When all pod is installed it is showing that something needs to be converted to Swift 3.

When I am doing convert is showing errors.

Have also tried this one:

use_frameworks!

target 'PhotoPhun' do pod 'SimpleAuth', '0.3.9' pod 'SAMCache' pod 'ReactiveCocoa', '4.2.2' end

Anyway I am getting a lot of errors. Can somebody help.