Skip to content

Commit

Permalink
Merge pull request #83 from marty-suzuki/swift5
Browse files Browse the repository at this point in the history
Support Swift5
  • Loading branch information
marty-suzuki authored Sep 30, 2019
2 parents 5c28b40 + 9a2aa3e commit fc19b64
Show file tree
Hide file tree
Showing 8 changed files with 44 additions and 66 deletions.
1 change: 0 additions & 1 deletion .swift-version

This file was deleted.

4 changes: 2 additions & 2 deletions Example/Cartfile
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
github "marty-suzuki/MisterFusion" "3.2.0"
github "marty-suzuki/NoticeObserveKit" "0.4.0"
github "marty-suzuki/MisterFusion" "5.0.0"
github "marty-suzuki/NoticeObserveKit" "0.12.0"
4 changes: 2 additions & 2 deletions Example/Cartfile.resolved
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
github "marty-suzuki/MisterFusion" "3.2.0"
github "marty-suzuki/NoticeObserveKit" "0.4.0"
github "marty-suzuki/MisterFusion" "5.0.0"
github "marty-suzuki/NoticeObserveKit" "0.12.0"
8 changes: 4 additions & 4 deletions Example/URLEmbeddedViewSample.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -362,14 +362,14 @@
"$(PROJECT_DIR)/Carthage/Build/iOS",
);
INFOPLIST_FILE = URLEmbeddedViewSample/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 9.0;
IPHONEOS_DEPLOYMENT_TARGET = 10.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = "jp.marty-suzuki.URLEmbeddedViewSample";
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = "";
SWIFT_OBJC_BRIDGING_HEADER = "URLEmbeddedViewSample/URLEmbeddedViewSample-Bridging-Header.h";
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_VERSION = 4.2;
SWIFT_VERSION = 5.0;
TARGETED_DEVICE_FAMILY = "1,2";
};
name = Debug;
Expand All @@ -386,13 +386,13 @@
"$(PROJECT_DIR)/Carthage/Build/iOS",
);
INFOPLIST_FILE = URLEmbeddedViewSample/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 9.0;
IPHONEOS_DEPLOYMENT_TARGET = 10.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = "jp.marty-suzuki.URLEmbeddedViewSample";
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = "";
SWIFT_OBJC_BRIDGING_HEADER = "URLEmbeddedViewSample/URLEmbeddedViewSample-Bridging-Header.h";
SWIFT_VERSION = 4.2;
SWIFT_VERSION = 5.0;
TARGETED_DEVICE_FAMILY = "1,2";
};
name = Release;
Expand Down
74 changes: 26 additions & 48 deletions Example/URLEmbeddedViewSample/OGSampleViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class OGSampleViewController: UIViewController {
@IBOutlet weak var searchBar: UISearchBar!
@IBOutlet weak var embeddedViewBottomConstraint: NSLayoutConstraint!

private var pool = NoticeObserverPool()
private var pool = Notice.ObserverPool()

override func viewDidLoad() {
super.viewDidLoad()
Expand All @@ -45,67 +45,27 @@ class OGSampleViewController: UIViewController {
}
}
}

private struct KeyboardInfo: NoticeUserInfoDecodable {
#if swift(>=4.2)
typealias UIViewAnimationOptions = UIView.AnimationOptions
#endif

let animationDuration: TimeInterval
let animationOptions: UIViewAnimationOptions
let frame: CGRect

init?(info: [AnyHashable: Any]) {
#if swift(>=4.2)
animationDuration = info[UIResponder.keyboardAnimationDurationUserInfoKey] as? TimeInterval ?? 0
animationOptions = UIView.AnimationOptions(rawValue:info[UIResponder.keyboardAnimationCurveUserInfoKey] as? UInt ?? 0)
frame = (info[UIResponder.keyboardFrameEndUserInfoKey] as? NSValue)?.cgRectValue ?? .zero
#else
animationDuration = info[UIKeyboardAnimationDurationUserInfoKey] as? TimeInterval ?? 0
animationOptions = UIViewAnimationOptions(rawValue:info[UIKeyboardAnimationCurveUserInfoKey] as? UInt ?? 0)
frame = (info[UIKeyboardFrameEndUserInfoKey] as? NSValue)?.cgRectValue ?? .zero
#endif
}
}

private struct UIKeyboardWillShow: NoticeType {
typealias InfoType = KeyboardInfo
#if swift(>=4.2)
static let name: Notification.Name = UIResponder.keyboardWillShowNotification
#else
static let name: Notification.Name = .UIKeyboardWillShow
#endif
}

private struct UIKeyboardWillHide: NoticeType {
typealias InfoType = KeyboardInfo
#if swift(>=4.2)
static let name: Notification.Name = UIResponder.keyboardWillHideNotification
#else
static let name: Notification.Name = .UIKeyboardWillHide
#endif
}

override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)

pool = NoticeObserverPool()
UIKeyboardWillShow.observe { [weak self] keyboard in
pool = Notice.ObserverPool()

NotificationCenter.default.nok.observe(name: .keyboardWillShow) { [weak self] keyboard in
self?.embeddedViewBottomConstraint.constant = keyboard.frame.size.height + 12
UIView.animate(withDuration: keyboard.animationDuration, delay: 0, options: keyboard.animationOptions, animations: {
self?.view.layoutIfNeeded()
}, completion: nil)
}
.disposed(by: pool)
.invalidated(by: pool)

UIKeyboardWillHide.observe { [weak self] keyboard in
NotificationCenter.default.nok.observe(name: .keyboardWillHide) { [weak self] keyboard in
self?.embeddedViewBottomConstraint.constant = 0
UIView.animate(withDuration: keyboard.animationDuration, delay: 0, options: keyboard.animationOptions, animations: {
self?.view.layoutIfNeeded()
}, completion: nil)
}
.disposed(by: pool)
.invalidated(by: pool)
}

override func viewDidAppear(_ animated: Bool) {
Expand All @@ -115,7 +75,7 @@ class OGSampleViewController: UIViewController {

override func viewWillDisappear(_ animated: Bool) {
super.viewWillDisappear(animated)
pool = NoticeObserverPool()
pool = Notice.ObserverPool()
searchBar.resignFirstResponder()
}

Expand Down Expand Up @@ -155,3 +115,21 @@ extension OGSampleViewController: UISearchBarDelegate {
}
}
}

private struct KeyboardInfo: NoticeUserInfoDecodable {

let animationDuration: TimeInterval
let animationOptions: UIView.AnimationOptions
let frame: CGRect

init?(info: [AnyHashable: Any]) {
animationDuration = info[UIResponder.keyboardAnimationDurationUserInfoKey] as? TimeInterval ?? 0
animationOptions = UIView.AnimationOptions(rawValue:info[UIResponder.keyboardAnimationCurveUserInfoKey] as? UInt ?? 0)
frame = (info[UIResponder.keyboardFrameEndUserInfoKey] as? NSValue)?.cgRectValue ?? .zero
}
}

extension Notice.Names {
fileprivate static let keyboardWillShow = Notice.Name<KeyboardInfo>(UIResponder.keyboardWillShowNotification)
fileprivate static let keyboardWillHide = Notice.Name<KeyboardInfo>(UIResponder.keyboardWillHideNotification)
}
7 changes: 3 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,9 @@
- [x] Clearable image cache
- [x] Clearable data cache
- [x] Support Swift3.2 (until 0.11.x)
- [x] Support Swift4
- [x] Supprot Swift4.x (until 0.17.1)
- [x] Support Swift5 (since 0.18.0)
- [x] Support Carthage since 0.11.1
- [x] Supprot Swift4.1 since 0.15.0
- [x] Supprot Swift4.2 since 0.17.0
- [x] Support tvOS since 0.16.0
- [x] Custom implementation of OGData cache

Expand Down Expand Up @@ -204,7 +203,7 @@ github "marty-suzuki/URLEmbeddedView"

## Requirements

- Xcode 9 or greater
- Xcode 10.2 or greater
- iOS 8.0 or greater
- tvOS 10.0 or greater
- UIKit
Expand Down
3 changes: 2 additions & 1 deletion URLEmbeddedView.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

Pod::Spec.new do |s|
s.name = "URLEmbeddedView"
s.version = "0.17.1"
s.version = "0.18.0"
s.summary = "URLEmbeddedView is a view that automatically cache the Open Graph Protocol."

# This description is used to generate tags and improve search results.
Expand All @@ -29,6 +29,7 @@ Pod::Spec.new do |s|
s.ios.deployment_target = '8.0'
s.tvos.deployment_target = '10.0'
s.requires_arc = true
s.swift_version = '5.0'

s.source_files = 'URLEmbeddedView/**/*.{swift}'
s.resources = 'Resources/*.{pdf,xcdatamodeld}'
Expand Down
9 changes: 5 additions & 4 deletions URLEmbeddedView.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,7 @@
developmentRegion = English;
hasScannedForEncodings = 0;
knownRegions = (
English,
en,
);
mainGroup = ED602B5F1F42D4EB00A45816;
Expand Down Expand Up @@ -532,7 +533,7 @@
SDKROOT = appletvos;
SKIP_INSTALL = YES;
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_VERSION = 4.2;
SWIFT_VERSION = 5.0;
TARGETED_DEVICE_FAMILY = 3;
TVOS_DEPLOYMENT_TARGET = 10.0;
};
Expand All @@ -559,7 +560,7 @@
PROVISIONING_PROFILE_SPECIFIER = "";
SDKROOT = appletvos;
SKIP_INSTALL = YES;
SWIFT_VERSION = 4.2;
SWIFT_VERSION = 5.0;
TARGETED_DEVICE_FAMILY = 3;
TVOS_DEPLOYMENT_TARGET = 10.0;
};
Expand Down Expand Up @@ -705,7 +706,7 @@
PROVISIONING_PROFILE_SPECIFIER = "";
SKIP_INSTALL = YES;
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_VERSION = 4.2;
SWIFT_VERSION = 5.0;
};
name = Debug;
};
Expand All @@ -729,7 +730,7 @@
PRODUCT_NAME = URLEmbeddedView;
PROVISIONING_PROFILE_SPECIFIER = "";
SKIP_INSTALL = YES;
SWIFT_VERSION = 4.2;
SWIFT_VERSION = 5.0;
};
name = Release;
};
Expand Down

0 comments on commit fc19b64

Please sign in to comment.