Comments (5)
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.
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.
Thanks @gabovanlugo
from alamofire-swiftyjson.
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
Of course, if anyone is having such problem.
from alamofire-swiftyjson.
Thanks @gabovanlugo Closing for now.
from alamofire-swiftyjson.
Related Issues (20)
- Cannot call value of non-function type NSHTTPURLResponse HOT 5
- Can't run in Swift 2.0 : NSHTTPURLResponse HOT 1
- Unable to find a specification for `Alamofire-SwiftyJSON` HOT 2
- No such module 'Alamofire', SwiftyJSON
- Would it be good to do the parsing to JSON from NSData directly?
- Please update for Swift 3 and the latest Alamofire/SwiftyJSON HOT 6
- Please update version to be compatible with Alamofire (~> 4.0) HOT 1
- Support for Carthage HOT 2
- Pod not installing for iOS 8 HOT 1
- no support swift version HOT 1
- cfbundleshortversionstring 2.0.0-beta must be a period-separated list HOT 1
- Unable to build using Xcode9 HOT 1
- would you please update the version?
- The bundle contains disallowed nested bundles. HOT 1
- Wrong PLIST entry in version 3.0.0 HOT 1
- SPM support please
- Please update to support SwiftyJSON & Alamofire-SwiftyJSON with swift4.2 in a development pod.
- Can't compile with Xcode 10.2 HOT 3
- Alamofire 5.0 and swift 5.0 support HOT 1
- PromiseKit
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from alamofire-swiftyjson.