Skip to content

Commit

Permalink
Update for Swift 3.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Antoine van der Lee committed Nov 4, 2016
1 parent 96d68ef commit a0fcb77
Show file tree
Hide file tree
Showing 11 changed files with 209 additions and 228 deletions.
11 changes: 5 additions & 6 deletions ALDataRequestView.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = "ALDataRequestView"
s.version = "1.0.4"
s.version = "2.0.0"
s.summary = "A view representation for data requests. Support for ReactiveCocoa and RXSwift."
s.description = "A view representation for data requests. Support for ReactiveCocoa and RXSwift by attached it to signalproducers and observables."
s.homepage = "https://github.com/AvdLee/ALDataRequestView"
Expand All @@ -10,28 +10,27 @@ Pod::Spec.new do |s|
s.social_media_url = 'https://twitter.com/twannl'

s.ios.deployment_target = '8.0'
s.tvos.deployment_target = '9.0'
s.requires_arc = true

s.default_subspec = "Core"

s.subspec "Core" do |ss|
ss.source_files = "Source/*.swift"
ss.dependency "PureLayout"
ss.dependency "ReachabilitySwift"
ss.dependency "ReachabilitySwift", "~> 3"
ss.framework = "Foundation"
end

s.subspec "RxSwift" do |ss|
ss.source_files = "Source/RxSwift/*.swift"
ss.dependency "RxSwift", "~> 2.0.0"
ss.dependency "RxCocoa", "~> 2.0.0"
ss.dependency "RxSwift", "~> 3.0.0"
ss.dependency "RxCocoa", "~> 3.0.0"
ss.dependency "ALDataRequestView/Core"
end

s.subspec "ReactiveCocoa" do |ss|
ss.source_files = "Source/ReactiveCocoa/*.swift"
ss.dependency "ReactiveCocoa"
ss.dependency "ReactiveSwift", "1.0.0-alpha.3"
ss.dependency "ALDataRequestView/Core"
end
end
98 changes: 49 additions & 49 deletions Example/ALDataRequestView.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

48 changes: 26 additions & 22 deletions Example/ALDataRequestView/Base.lproj/Main.storyboard
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="10116" systemVersion="15D21" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" initialViewController="YhN-l8-BAI">
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="11542" systemVersion="15G31" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES" initialViewController="YhN-l8-BAI">
<device id="retina4_7" orientation="portrait">
<adaptation id="fullscreen"/>
</device>
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="10085"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="11524"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<scenes>
<!--View Controller-->
Expand All @@ -14,32 +18,32 @@
<viewControllerLayoutGuide type="bottom" id="2fi-mo-0CV"/>
</layoutGuides>
<view key="view" contentMode="scaleToFill" id="kh9-bI-dsS">
<rect key="frame" x="0.0" y="0.0" width="600" height="600"/>
<rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<subviews>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="beG-5V-Upb">
<rect key="frame" x="20" y="550" width="187" height="30"/>
<rect key="frame" x="20" y="617" width="111.5" height="30"/>
<state key="normal" title="Set Loading"/>
<connections>
<action selector="setLoadingButtonTapped:" destination="vXZ-lx-hvc" eventType="touchUpInside" id="BPS-tF-JdQ"/>
<action selector="setLoadingButtonTappedWithSender:" destination="vXZ-lx-hvc" eventType="touchUpInside" id="wmN-4K-pPe"/>
</connections>
</button>
<button opaque="NO" contentMode="scaleToFill" misplaced="YES" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="7eV-Lg-gbk">
<rect key="frame" x="207" y="550" width="187" height="30"/>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="7eV-Lg-gbk">
<rect key="frame" x="131.5" y="617" width="112" height="30"/>
<state key="normal" title="Set Reload"/>
<connections>
<action selector="setReloadButtonTapped:" destination="vXZ-lx-hvc" eventType="touchUpInside" id="beZ-jV-VaY"/>
<action selector="setReloadButtonTappedWithSender:" destination="vXZ-lx-hvc" eventType="touchUpInside" id="Pe3-h1-fxl"/>
</connections>
</button>
<button opaque="NO" contentMode="scaleToFill" misplaced="YES" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="WPo-7I-ymu">
<rect key="frame" x="394" y="550" width="186" height="30"/>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="WPo-7I-ymu">
<rect key="frame" x="243.5" y="617" width="111.5" height="30"/>
<state key="normal" title="Set Empty"/>
<connections>
<action selector="setEmptyButtonTapped:" destination="vXZ-lx-hvc" eventType="touchUpInside" id="Lkj-bv-kr0"/>
<action selector="setEmptyButtonTappedWithSender:" destination="vXZ-lx-hvc" eventType="touchUpInside" id="4yJ-Lg-06l"/>
</connections>
</button>
</subviews>
<color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="calibratedWhite"/>
<color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<constraints>
<constraint firstItem="WPo-7I-ymu" firstAttribute="leading" secondItem="7eV-Lg-gbk" secondAttribute="trailing" id="50O-eN-QMY"/>
<constraint firstAttribute="trailing" secondItem="WPo-7I-ymu" secondAttribute="trailing" constant="20" id="BRJ-5p-DXC"/>
Expand Down Expand Up @@ -73,32 +77,32 @@
<viewControllerLayoutGuide type="bottom" id="hKu-ox-zRX"/>
</layoutGuides>
<view key="view" contentMode="scaleToFill" id="N8C-HV-xYv">
<rect key="frame" x="0.0" y="0.0" width="600" height="600"/>
<rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<subviews>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="AZ8-YR-uzS">
<rect key="frame" x="20" y="550" width="187" height="30"/>
<rect key="frame" x="20" y="617" width="111.5" height="30"/>
<state key="normal" title="Set Loading"/>
<connections>
<action selector="setLoadingButtonTapped:" destination="cDS-v0-U8x" eventType="touchUpInside" id="QQW-6J-Ic7"/>
<action selector="setLoadingButtonTappedWithSender:" destination="cDS-v0-U8x" eventType="touchUpInside" id="j6j-4Q-eFP"/>
</connections>
</button>
<button opaque="NO" contentMode="scaleToFill" misplaced="YES" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="qd0-1h-FPm">
<rect key="frame" x="207" y="550" width="187" height="30"/>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="qd0-1h-FPm">
<rect key="frame" x="131.5" y="617" width="112" height="30"/>
<state key="normal" title="Set Reload"/>
<connections>
<action selector="setReloadButtonTapped:" destination="cDS-v0-U8x" eventType="touchUpInside" id="cQi-OG-hkX"/>
<action selector="setReloadButtonTappedWithSender:" destination="cDS-v0-U8x" eventType="touchUpInside" id="14m-rQ-WFo"/>
</connections>
</button>
<button opaque="NO" contentMode="scaleToFill" misplaced="YES" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="LtL-Fy-PYw">
<rect key="frame" x="394" y="550" width="186" height="30"/>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="LtL-Fy-PYw">
<rect key="frame" x="243.5" y="617" width="111.5" height="30"/>
<state key="normal" title="Set Empty"/>
<connections>
<action selector="setEmptyButtonTapped:" destination="cDS-v0-U8x" eventType="touchUpInside" id="Eih-qb-qN0"/>
<action selector="setEmptyButtonTappedWithSender:" destination="cDS-v0-U8x" eventType="touchUpInside" id="bFj-Cs-fBE"/>
</connections>
</button>
</subviews>
<color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="calibratedWhite"/>
<color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<constraints>
<constraint firstItem="AZ8-YR-uzS" firstAttribute="leading" secondItem="N8C-HV-xYv" secondAttribute="leading" constant="20" id="8md-Dp-3ut"/>
<constraint firstAttribute="trailing" secondItem="LtL-Fy-PYw" secondAttribute="trailing" constant="20" id="FbL-xx-Vgw"/>
Expand Down
59 changes: 28 additions & 31 deletions Example/ALDataRequestView/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ import UIKit
import ALDataRequestView
import PureLayout
import RxSwift
import ReactiveCocoa
import ReactiveSwift
import RxCocoa

class ViewController: UIViewController {

var dataRequestView:ALDataRequestView?
var signalProducer:SignalProducer<[String], NSError>?
var dataSignalProducer:SignalProducer<NSData, NSError>?
var dataSignalProducer:SignalProducer<Data, NSError>?
var rxDisposable:RxSwift.Disposable?
let (signal, subscriber) = Signal<[String], NSError>.pipe()

Expand All @@ -28,11 +28,11 @@ class ViewController: UIViewController {
view.addSubview(dataRequestView!)
dataRequestView?.autoPinEdgesToSuperviewEdges()
dataRequestView?.dataSource = self
view.sendSubviewToBack(dataRequestView!)
view.sendSubview(toBack: dataRequestView!)


// testWithFailureCallObservable()
testWithFailureCallSignalProducer()
testWithFailureCallObservable()
// testWithFailureCallSignalProducer()
// testWithFailureCallObservable()
}

Expand All @@ -41,60 +41,57 @@ class ViewController: UIViewController {
}

func testWithEmptySignalProducer(){
signalProducer = SignalProducer(signal: signal).attachToDataRequestView(dataRequestView!)
signalProducer = SignalProducer(signal: signal).attachToDataRequestView(dataRequestView: dataRequestView!)
signalProducer?.start()

delay(3.0, closure: { [weak self] () -> Void in
delay(delay: 3.0, closure: { [weak self] () -> Void in
let emptyArray:[String] = []
self?.subscriber.sendNext(emptyArray) // Send empty array
self?.subscriber.send(value: emptyArray) // Send empty array
self?.subscriber.sendCompleted()
})
}

func testWithFailureCallSignalProducer(){
let URLRequest = NSURLRequest(URL: NSURL(string: "http://httpbin.org/status/400")!)
dataSignalProducer = NSURLSession.sharedSession()
.rac_dataWithRequest(URLRequest)
.flatMap(.Latest, transform: { (data, response) -> SignalProducer<NSData, NSError> in
if let httpResponse = response as? NSHTTPURLResponse where httpResponse.statusCode > 299 {
let request = URLRequest(url: URL(string: "http://httpbin.org/status/400")!)
dataSignalProducer = URLSession.shared
.reactive.data(with: request)
.flatMap(.latest, transform: { (data, response) -> SignalProducer<Data, NSError> in
if let httpResponse = response as? HTTPURLResponse, httpResponse.statusCode > 299 {
return SignalProducer(error: NSError(domain: "", code: httpResponse.statusCode, userInfo: nil))
}
return SignalProducer(value: data)
})
.attachToDataRequestView(dataRequestView!)
.attachToDataRequestView(dataRequestView: dataRequestView!)
dataSignalProducer?.start()
}

func testWithFailureCallObservable(){
let URLRequest = NSURLRequest(URL: NSURL(string: "http://httpbin.org/status/400")!)
rxDisposable = NSURLSession.sharedSession().rx_data(URLRequest).attachToDataRequestView(dataRequestView!).subscribe()
let request = URLRequest(url: URL(string: "http://httpbin.org/status/400")!)
rxDisposable = URLSession.shared.rx.data(request: request).attachToDataRequestView(dataRequestView: dataRequestView!).subscribe()
}

@IBAction func setLoadingButtonTapped(sender: UIButton) {
dataRequestView?.changeRequestState(RequestState.Loading)
dataRequestView?.changeRequestState(state: RequestState.Loading)
}

@IBAction func setEmptyButtonTapped(sender: UIButton) {
dataRequestView?.changeRequestState(RequestState.Empty)
dataRequestView?.changeRequestState(state: RequestState.Empty)
}

@IBAction func setReloadButtonTapped(sender: UIButton) {
dataRequestView?.changeRequestState(RequestState.Failed)
dataRequestView?.changeRequestState(state: RequestState.Failed)
}

func delay(delay:Double, closure:()->()) {
dispatch_after(
dispatch_time(
DISPATCH_TIME_NOW,
Int64(delay * Double(NSEC_PER_SEC))
),
dispatch_get_main_queue(), closure)
func delay(delay:Double, closure:@escaping ()->()) {
DispatchQueue.main.asyncAfter(deadline: .now() + delay) {
closure()
}
}
}

extension ViewController : ALDataRequestViewDataSource {
func loadingViewForDataRequestView(dataRequestView: ALDataRequestView) -> UIView? {
let loadingView = UIActivityIndicatorView(activityIndicatorStyle: UIActivityIndicatorViewStyle.Gray)
let loadingView = UIActivityIndicatorView(activityIndicatorStyle: UIActivityIndicatorViewStyle.gray)
loadingView.startAnimating()
return loadingView
}
Expand Down Expand Up @@ -127,15 +124,15 @@ final class ReloadViewController : UIViewController, ALDataReloadType {
init(){
super.init(nibName: nil, bundle: nil)

retryButton = UIButton(type: UIButtonType.System)
retryButton.setTitle("Reload!", forState: UIControlState.Normal)
retryButton = UIButton(type: UIButtonType.system)
retryButton.setTitle("Reload!", for: UIControlState.normal)
view.addSubview(retryButton)
retryButton.autoCenterInSuperview()

statusLabel = UILabel(forAutoLayout: ())
view.addSubview(statusLabel)
statusLabel.autoAlignAxisToSuperviewAxis(ALAxis.Vertical)
statusLabel.autoPinEdge(.Bottom, toEdge: .Top, ofView: retryButton)
statusLabel.autoAlignAxis(toSuperviewAxis: ALAxis.vertical)
statusLabel.autoPinEdge(.bottom, to: .top, of: retryButton)
}

required init?(coder aDecoder: NSCoder) {
Expand Down
11 changes: 0 additions & 11 deletions Example/Podfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,15 @@ source 'https://github.com/CocoaPods/Specs.git'
use_frameworks!

def sharedPods
pod "ReachabilitySwift", :git => "https://github.com/ashleymills/Reachability.swift.git", :branch => "swift-2.3"
pod 'ALDataRequestView', :path => '../'
pod 'ALDataRequestView/ReactiveCocoa', :path => '../'
pod 'ALDataRequestView/RxSwift', :path => '../'
end

target 'ALDataRequestView_Example' do
sharedPods
pod 'RxCocoa', '~> 2.0.0'
end

target 'ALDataRequestView_Tests' do
sharedPods
end

# Build configurations
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
Loading

0 comments on commit a0fcb77

Please sign in to comment.