This is swift version for swnetworking

Related tags

Networking skywite
Overview

SkyWite

Skywite

Version License Platform Twitter

SkyWite is an open-source and highly versatile multi-purpose frameworks. Clean code and sleek features make SkyWite an ideal choice. Powerful high-level networking abstractions built into Cocoa. It has a modular architecture with well-designed, feature-rich APIs that are a joy to use.

Achieve your deadlines by using SkyWite. You will save Hundred hours.

Start development using Skywite. Definitely you will be happy....! yeah..

SkyWite being developed in clean code and its sleek features make it the “Dream Framework” for any iOS / Macos developer. Its modular architecture and feature-rich APIs makes it very simple for development. SkyWite’s powerful networking abstraction is built using Cocoa, which makes it easily available for everyone,

Its core being developed on Objective C, makes it compatible on the following platforms :

  •    iOS,
    
  •    Mac OS X,
    
  •    TV OS and
    

The next question that would pop for any developer is, why build a framework as such when there a many similar ones available. The answer was quite straight forward. 9 out of 10 frameworks out there in the market have the following features:

  1. Support all request methods
  2. Offline request support
  3. HTTP request operation manager
  4. Cocoa Pod Support
  5. SWIFT Compatible
  6. Supports Apple UI Kit.
  7. Background request support
  8. Session manager
  9. Reachability manager
  10. Secured
  11. Free support offered around the framework
  12. The framework will be continuously updated with the new OS drops
  13. Community around the framework to support bug fixes
  14. Code amendment flexibility
  15. 99% Guaranteed on crash management for the framework
  16. Block support
  17. MIT License

Above features are not only available on the other frameworks in the market, but is also available on SkyWite, but here is what makes SkyWite special:

  1. Offline sync support
  2. The frameworks adds in a loading indicator when a request is sent, allows for addition of custom indicators as well
  3. A sing line of code to initiate a request, which will approximately save 20 lines of code
  4. Block with background request
  5. Tag a request (set int value to identify requests)
  6. Set priority for offline requests.
  7. All the request/response body will generated automatically which would save the developer approximately 50-70 lines of coding

As same as the swnetworking framework we released earlier, this framework also doesn't have any issue. If you find any, I'll fix them as soon as possible. Now we don't need a team as there is no such issues to fix.

Requirements

You need to add "SystemConfiguration" framework into your project before implement this.

#How to apply to Xcode project

Downloading Source Code

Using CocoaPods

SkyWite is available through CocoaPods. To install it, simply add the following line to your Podfile:

pod "SkyWite"

If you are new to CocoaPods, please go to Wiki page.

Communication

  • If you need any help, use Stack Overflow. (Tag 'skywite') or you can send a mail with details ( we will provide fast feedback )
  • If you'd like to ask a general question, use Stack Overflow.
  • If you found a bug, and can provide steps to reliably reproduce it, open an issue or you can contribute.
  • If you have a feature request, send a request mail we will add as soon as possible.
  • If you want to contribute, submit a pull request.

#Architecture

  • SWRequest
    • SWRequest
    • SWGet
    • SWPost
    • SWMultiPart
    • SWPut
    • SWPatch
    • SWDelete
    • SWHead
    • SWOfflineRequestManger
  • ResponseType
    • SWResponseDataType
    • SWResponseJSONDataType
    • SWResponseXMLDataType
    • SWResponseStringDataType
    • SWResponseUIImageType
    • SWRequestDataType
    • SWRequestFormData
    • SWRequestMultiFormData
    • SWRequestJSONData
  • Reachability
    • SWReachability
  • File
    • SWMedia
  • UIKit+SkyWite
    • UIImageViewExtension
    • UIProgressViewExtension

How to Use

Use HTTP Request will be NSURLSession

ALL Requests will be NSURLSession. Session will add in to NSOperationQueue . Request creation , response serialization, network reachability handing and offline request as well.

GET Request

let s  = SWGet()
s.startDataTask(url: "", params:nil, success: { (task, object) in
}) { (task, error) in
    print("error", error)
}

If you want send parameters you have two options

let s  = SWGet()
s.startDataTask(url: "", params:"name=this is name&address=your address", success: { (task, object) in
}) { (task, error) in
    print("error", error)
}

If you want to encdoe parameters and values you need to pass Dictionary object with keys/values.

let s  = SWGet()
s.startDataTask(url: "", params:"name=this is name&address=your address", success: { (task, object) in
}) { (task, error) in
    print("error", error)
}

We are recommend to use second option because if you have & sign with parameter or value it will break sending values.

GET with Response type

Available as response types SWResponseJSONDataType, SWResponseJSONDataType, SWResponseXMLDataType, SWResponseStringDataType,SWResponseUIImageType
You need set responseDataType.

// this response will be JSON
let s  = SWGet()
s.responseDataType = SWResponseStringDataType()
s.startDataTask(url: "", params:nil, success: { (task, object) in
print("item", object)
}) { (task, error) in
    print("error", error)
}

GET with loading indicator

If you set your parent view to method, loading indicator will be displayed.

let s  = SWGet()
s.responseDataType = SWResponseDataType()
s.startDataTask(url: "", params:nil, parentView: self.view , success: { (task, object) in
    print("item", object)
}) { (task, error) in
    print("error", error)
}

If you want custom loading view you need to add new nib file to your project and name it as 'sw_loadingView'. It will be displayed on the screen.

Cache Response

If you want to access cached data on the response. You need to use relevant method that include cache block

let s  = SWGet()
s.responseDataType = SWResponseStringDataType()
s.startDataTask(url: "", params: nil, parentView: self.view, cache: { (response, object) in
    print("chache", object)
}, success: { (task, object) in
    print("success", object)
}) { (task, error) in
    print("success", error)
}

POST request (simple)

Cache, Loading view available for the on the relevant method. Please check available methods

let s = SWPost()
s.responseDataType = SWResponseStringDataType()
s.startDataTask(url: "", params:["name":"this is name", "address": "your address"] as AnyObject  , success: { (task, object) in
    print("item", object)
}) { (task, error) in
    print("error", error)
}

let s2 = SWPost()
s2.responseDataType = SWResponseStringDataType()
s2.startDataTask(url: "", params:"saman=test" as AnyObject  , success: { (task, object) in
    print("item", object)
}) { (task, error) in
    print("error", error)
}

POST multipart request

It is really easy.

let s = SWPost()

let image = NSImage(named: "skywite")
let imgData = pngRepresentationOfImage(image: image!)

let media1 = SWMedia(fileName: "imagefile.png", key: "image", data: imgData)
let media2 = SWMedia(fileName: "imagefile.jpg", key: "image2", mineType:"image/jpeg", data: imgData)

s.responseDataType = SWResponseStringDataType()
s.startUploadTask(url: "", files:[media1, media2] , params: ["name":"this is name", "address": "your address"] as AnyObject, success: { (task, object) in

}) { (task, error) in

}

//create with custom mine type one

let media2 = SWMedia(fileName: "imagefile.jpg", key: "image2", mineType:"image/jpeg", data: imgData)

PUT simple request

let s = SWPut()
s.responseDataType = SWResponseStringDataType()
s.startDataTask(url: "", params:"saman=test" as AnyObject  , success: { (task, object) in
    print("item", object)
}) { (task, error) in
    print("error", error)
}

PATCH simple request

let s = SWPatch()
s.responseDataType = SWResponseStringDataType()
s.startDataTask(url: "", params:"saman=test" as AnyObject  , success: { (task, object) in
    print("item", object)
}) { (task, error) in
    print("error", error)
}

DELETE simple request

let s = SWDelete()
s.responseDataType = SWResponseStringDataType()
s.startDataTask(url: "", params:"saman=test" as AnyObject  , success: { (task, object) in
    print("item", object)
}) { (task, error) in
    print("error", error)
}

HEAD simple request

let s = SWHead()
s.responseDataType = SWResponseStringDataType()
s.startDataTask(url: "", params:"saman=test" as AnyObject  , success: { (task, object) in
    print("item", object)
}) { (task, error) in
    print("error", error)
}

Features

all the following features averrable on all the request types. eg : If you want to access you need to call relevant method that include cache block

Custom headers

If you want to add custom headers you can set to accessing request object.

let s = SWPost()
s.reqeust.setValue("application/x-www-form-urlencoded", forHTTPHeaderField: "Content-Type")
s.responseDataType = SWResponseStringDataType()
s.startDataTask(url: "", params:["name":"this is name", "address": "your address"] as AnyObject  , success: { (task, object) in
    print("item", object)
}) { (task, error) in
    print("error", error)
}

Custom time out

If you want to change request timeout , you have to change property call timeOut.

let s = SWPost()
s.timeOut = 120
s.responseDataType = SWResponseStringDataType()
s.startDataTask(url: "", params:["name":"this is name", "address": "your address"] as AnyObject  , success: { (task, object) in
    print("item", object)
}) { (task, error) in
    print("error", error)
}

Response Encoding

You need to sent object type for the responseDataType on all your requests.

//JSON
let s = SWPost()
s.responseDataType = SWResponseJSONDataType()
s.startDataTask(url: "" , params: ["name":"this is name for testing", "address": "your address"] as AnyObject, parentView: nil, sendLaterIfOffline: true, cache: { (cache, response) in
}, success: { (task, response) in
}) { (task, error) in
}

//String
let s2 = SWPost()
s2.responseDataType = SWResponseStringDataType()
s2.startDataTask(url: "" , params: ["name":"this is name for testing", "address": "your address"] as AnyObject, parentView: nil, sendLaterIfOffline: true, cache: { (cache, response) in
}, success: { (task, response) in
}) { (task, error) in
}

UIImageView with SkyWite

No need to download image and set to UIImageView anymore. You can set url to UIImageView.

// Please use only one method . you can see 4 methods :)

let imageView = UIImageView.init(frame: CGRect(x:0, y:0, width:300, height:300))
imageView.loadWithURLString(url: "")
imageView.loadWithURLString(url: "", loadFromCacheFirst: true)
imageView.loadWithURLString(url: "") { (image) in
}
imageView.loadWithURLString(url: "", loadFromCacheFirst: true) { (image) in
}

Check Reachability

New Reachability class to support block when change network status available Status

NotReachable WWAN Wifi

if (SWReachability.getCurrentNetworkStatus() == .NotReachable) {
//connection not avaible
}

//if you want to get status chnage notification
SWReachability.checkNetowrk(currentNetworkStatus: { (currentStatus) in
}) { (changedStatus) in
}

Upload progress With Request

let s = SWPost()
let image = UIImage(named: "skywite")
let imgData = UIImagePNGRepresentation(image!)

let media1 = SWMedia(fileName: "imagefile.png", key: "image", data: imgData!)
let media2 = SWMedia(fileName: "imagefile.jpg", key: "image2", mineType:"image/jpeg", data: imgData!)

s.responseDataType = SWResponseStringDataType()
s.startUploadTask(url: "http://localhost:3000/api/v1/users/users", files:[media1, media2] , params: ["name":"this is name", "address": "your address"] as AnyObject, success: { (task, object) in

}) { (task, error) in

}
progressView.setRequestForUpload(request: s)

Download Progress With Request

let s = SWPost()
s.responseDataType = SWResponseJSONDataType()
s.startDownloadTask(url: "http://192.168.1.36:3000/api/v1/users/jobs" , params:nil , parentView: nil, sendLaterIfOffline: true, cache: { (cache, response) in
}, success: { (task, response) in
}) { (task, error) in
}
progressView.setRequestForDownload(request: s)

Pass object to response block

You can set custom object to your request object as userObject . This will allow any type

let s = SWPost()
s.userObject = //any type object.

Identify the Request

You can set tag for the request

let s = SWPost()
s.tag = 12;

Offline request from SkyWite

This is really simple. First of all you need to send offline request expire time. this is seconds

SWOfflineManager.requestExpireTime(seconds: 1300)

You have methods with parameter passing sendLaterIfOllfine. Just pass YES. That's it.

let s = SWPost()
s.responseDataType = SWResponseJSONDataType()
s.startDownloadTask(url: "http://192.168.1.36:3000/api/v1/users/jobs" , params:nil , parentView: nil, sendLaterIfOffline: true, cache: { (cache, response) in
}, success: { (task, response) in
}) { (task, error) in
}

If you want catch offline request you need to use following methods. Better to add following lines to your AppDelegate didFinishLaunchingWithOptions methods.

SWOfflineManager.sharedInstance.request(success: { (squreqeust, obj) in
}) { (request, error) in
}

Please note you need to set tag or userObject to identify the request. userObject should be `'NSCording' support object

Set Task for UIProgressView

Please use following method to set task for UIProgressView

func setDownloadTask(task: URLSessionDownloadTask) {}
func setUploadTask(task: URLSessionUploadTask) {}

Credits

SkyWite is owned and maintained bye the SkyWite SkyWite was originally created by saman kumara. If you want to contact [email protected]

Security disclosure

If you believe you have identified a security vulnerability with SkyWite, you should report it as soon as possible via email to [email protected]. Please do not post it to a public issue tracker.

License

Skywite is released under the MIT license. See LICENSE for details.

You might also like...
Network abstraction layer written in Swift.
Network abstraction layer written in Swift.

Moya 14.0.0 A Chinese version of this document can be found here. You're a smart developer. You probably use Alamofire to abstract away access to URLS

Versatile HTTP Networking in Swift
Versatile HTTP Networking in Swift

Net is a versatile HTTP networking library written in Swift. 🌟 Features URL / JSON / Property List Parameter Encoding Upload File / Data / Stream / M

A type-safe, high-level networking solution for Swift apps
A type-safe, high-level networking solution for Swift apps

What Type-safe network calls made easy Netswift offers an easy way to perform network calls in a structured and type-safe way. Why Networking in Swift

OAuth2 framework for macOS and iOS, written in Swift.
OAuth2 framework for macOS and iOS, written in Swift.

OAuth2 OAuth2 frameworks for macOS, iOS and tvOS written in Swift 5.0. ⤵️ Installation 🛠 Usage 🖥 Sample macOS app (with data loader examples) 📖 Tec

Swift based OAuth library for iOS
Swift based OAuth library for iOS

OAuthSwift Swift based OAuth library for iOS and macOS. Support OAuth1.0, OAuth2.0 Twitter, Flickr, Github, Instagram, Foursquare, Fitbit, Withings, L

🏇 A Swift HTTP / HTTPS networking library just incidentally execute on machines
🏇 A Swift HTTP / HTTPS networking library just incidentally execute on machines

Thus, programs must be written for people to read, and only incidentally for machines to execute. Harold Abelson, "Structure and Interpretation of Com

Swift/Obj-C HTTP framework with a focus on REST and JSON

Now Archived and Forked PMHTTP will not be maintained in this repository going forward. Please use, create issues on, and make PRs to the fork of PHMT

A Swift framework for working with emails
A Swift framework for working with emails

Postal is a swift framework providing simple access to common email providers. Example Connect let postal = Postal(configuration: .icloud(login: "myem

Replacement for Apple's Reachability re-written in Swift with closures
Replacement for Apple's Reachability re-written in Swift with closures

Reachability.swift Reachability.swift is a replacement for Apple's Reachability sample, re-written in Swift with closures. It is compatible with iOS (

Owner
Saman Kumara
I am a technical architect.
Saman Kumara
Socket framework for Swift using the Swift Package Manager. Works on iOS, macOS, and Linux.

BlueSocket Socket framework for Swift using the Swift Package Manager. Works on iOS, macOS, and Linux. Prerequisites Swift Swift Open Source swift-5.1

Kitura 1.3k Dec 26, 2022
Swift Express is a simple, yet unopinionated web application server written in Swift

Documentation <h5 align="right"><a href="http://demo.swiftexpress.io/">Live ?? server running Demo <img src="https://cdn0.iconfinder.com/data/icons/

Crossroad Labs 850 Dec 2, 2022
Swift backend / server framework (Pure Swift, Supports Linux)

NetworkObjects NetworkObjects is a #PureSwift backend. This framework compiles for OS X, iOS and Linux and serves as the foundation for building power

Alsey Coleman Miller 258 Oct 6, 2022
Swift-multipart-formdata - MultipartFormData: Build multipart/form-data type-safe in Swift

MultipartFormData Build multipart/form-data type-safe in Swift. A result builder

Felix Herrmann 21 Dec 29, 2022
Approov Integration Examples 0 Jan 26, 2022
Swift-flows - Simplistic hot and cold flow-based reactive observer pattern for Swift… ideal for MVVM architectures

SwiftFlows Simplistic hot and cold flow-based reactive observer pattern for Swif

Tyler Suehr 0 Feb 2, 2022
Elegant HTTP Networking in Swift

Alamofire is an HTTP networking library written in Swift. Features Component Libraries Requirements Migration Guides Communication Installation Usage

Alamofire 38.7k Jan 8, 2023
Robust Swift networking for web APIs

Conduit Conduit is a session-based Swift HTTP networking and auth library. Within each session, requests are sent through a serial pipeline before bei

Mindbody 52 Oct 26, 2022
Easy to use OAuth 2 library for iOS, written in Swift.

Heimdallr Heimdallr is an OAuth 2.0 client specifically designed for easy usage. It currently supports the resource owner password credentials grant f

trivago N.V. 628 Oct 17, 2022
Swift HTTP for Humans

Just is a client-side HTTP library inspired by python-requests - HTTP for Humans. Features Just lets you to the following effortlessly: URL queries cu

Daniel Duan 1.4k Dec 30, 2022