Coder Social home page Coder Social logo

Comments (5)

kukabi avatar kukabi commented on May 25, 2024

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.

from alamofire-swiftyjson.

gabovanlugo avatar gabovanlugo commented on May 25, 2024

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.

from alamofire-swiftyjson.

jorgecasariego avatar jorgecasariego commented on May 25, 2024

Thanks @gabovanlugo

from alamofire-swiftyjson.

gabovanlugo avatar gabovanlugo commented on May 25, 2024

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.

from alamofire-swiftyjson.

wongzigii avatar wongzigii commented on May 25, 2024

Thanks @gabovanlugo Closing for now.

from alamofire-swiftyjson.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.