Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SwiftyJSON @ 11fdc5c doesn't exist #32

Closed
gabovanlugo opened this issue Sep 13, 2015 · 5 comments
Closed

SwiftyJSON @ 11fdc5c doesn't exist #32

gabovanlugo opened this issue Sep 13, 2015 · 5 comments

Comments

@gabovanlugo
Copy link

I'm trying to use this repo in CocoaPods but there's an error retrieving the mentioned version of SwiftyJSON. I think it's just matter of pointing to the right tree.

@kukabi
Copy link

kukabi commented Sep 15, 2015

I'm suffering from this too, there seems to be no Swift 2.0 support with SwiftyJSON yet. Also, NSError is still in the source code, looks like ErrorType should replace it in Swift 2.0.

@gabovanlugo
Copy link
Author

I ended up with a solution that works great in Swift 2.0 and Xcode 7. I just made a little modification to the file in order to resolve the NSError issue.

https://gist.github.com/gabovanlugo/c1c0588ab929df81b3a7

You need to import that file into your project tree manually (no CocoaPods). However, don't forget to install Alamofire and SwiftyJSON for Swift 2.0

Here's my Podfile:

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

target 'yourApp' do
  pod 'SwiftyJSON', :git => 'https://github.com/SwiftyJSON/SwiftyJSON.git', :branch => 'xcode7'
  pod 'Alamofire', '~> 2.0'

end

In this example you can see how I'm using it.

override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.

        // Mark: API call

        let url = "http://192.168.0.100:3000"
        var templateRemoteData: JSON = [:]

        Alamofire.request(.GET, url)
            .responseSwiftyJSON({ (request, response, json, error) in
                if(error != nil) {
                    print(error)
                    print(request)
                    print(response)
                }
                else {
                    self.templateRemoteData = JSON!(json)
                    print(self.templateRemoteData)

                    // My API returns a ["data"] object, don't forget to change it to whatever you need
                    for item in self.templateRemoteData["data"].arrayValue {
                        // Do whatever you want with your remote data
                        }
                    }
                }
            })

    }

Need to mention that you need to import:

import SwiftyJSON
import Alamofire

... in your ViewController as well.

Another thing, I'm getting data from a local server I did with Node.js, it isn't HTTPS so you can get some warning coming from Xcode 7. You can solve it this way: http://stackoverflow.com/questions/31254725/transport-security-has-blocked-a-cleartext-http

Hope it helps.

@jorgecasariego
Copy link

Thanks @gabovanlugo

@gabovanlugo
Copy link
Author

No problem, @GUMARELO.

By the way, for those who are already in OS X "El Capitan", there's a known bug (Even in Xcode 7.1 - 7B91b) that does't allow us to connect to a localhost through an IP address.

// This won't work
let url = "http://192.168.0.100:3000"

Simple solution as the Xcode Release Notes says (As for October 2015):

Simulator

"When running in the Simulator, an app cannot communicate with TCP/IP services locally hosted by the Mac via the Mac’s local IP address.
Connect via a loopback address, such as localhost or 127.0.0.1. (22453539)"

// This WILL work
let url = "http://localhost:3000"

More info here: https://forums.developer.apple.com/thread/20919

And here: https://developer.apple.com/library/ios/releasenotes/DeveloperTools/RN-Xcode/Chapters/xc7_release_notes.html#//apple_ref/doc/uid/TP40001051-CH5-DontLinkElementID_162

Of course, if anyone is having such problem.

@wongzigii
Copy link
Member

Thanks @gabovanlugo Closing for now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants