Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Swift5 update #8

Open
wants to merge 13 commits into
base: master
Choose a base branch
from
19 changes: 18 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,18 @@
/Pods
### Xcode ###
build/
*.pbxuser
!default.pbxuser
*.mode1v3
!default.mode1v3
*.mode2v3
!default.mode2v3
*.perspectivev3
!default.perspectivev3
xcuserdata
*.xccheckout
*.moved-aside
DerivedData
*.xcuserstate

### Pods ###
Pods/
2 changes: 1 addition & 1 deletion KiwiPods.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Pod::Spec.new do |s|
#

s.name = "KiwiPods"
s.version = "0.0.4"
s.version = "0.0.8"
s.summary = "Summary"

# This description is used to generate tags and improve search results.
Expand Down
6 changes: 4 additions & 2 deletions KiwiPods.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,7 @@
TargetAttributes = {
D6B0315B2189D172003431C6 = {
CreatedOnToolsVersion = 10.0;
LastSwiftMigration = 1020;
};
};
};
Expand All @@ -259,6 +260,7 @@
hasScannedForEncodings = 0;
knownRegions = (
en,
Base,
);
mainGroup = D6B031522189D172003431C6;
productRefGroup = D6B0315D2189D172003431C6 /* Products */;
Expand Down Expand Up @@ -489,7 +491,7 @@
PRODUCT_BUNDLE_IDENTIFIER = Kiwitech.KiwiPods;
PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)";
SKIP_INSTALL = YES;
SWIFT_VERSION = 4.2;
SWIFT_VERSION = 5.0;
TARGETED_DEVICE_FAMILY = "1,2";
};
name = Debug;
Expand All @@ -515,7 +517,7 @@
PRODUCT_BUNDLE_IDENTIFIER = Kiwitech.KiwiPods;
PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)";
SKIP_INSTALL = YES;
SWIFT_VERSION = 4.2;
SWIFT_VERSION = 5.0;
TARGETED_DEVICE_FAMILY = "1,2";
};
name = Release;
Expand Down
8 changes: 4 additions & 4 deletions KiwiPods/ImagePicker/ImagePickerController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ extension ImagePickerController: UICollectionViewDataSource {
}
}
extension ImagePickerController: UICollectionViewDelegate {
func collectionView(_ collectionView: UICollectionView, shouldSelectItemAt indexPath: IndexPath) -> Bool {
public func collectionView(_ collectionView: UICollectionView, shouldSelectItemAt indexPath: IndexPath) -> Bool {
guard indexPath.row < imageAryCount else {
return false
}
Expand All @@ -304,7 +304,7 @@ extension ImagePickerController: UICollectionViewDelegate {
delegate?.imagePicker(picker: self, failedWithError: .maxItemSelectionLimitExceeded)
return false
}
func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
public func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {

}
}
Expand All @@ -331,7 +331,7 @@ fileprivate extension ImagePickerController {
}
}
extension ImagePickerController: UICollectionViewDelegateFlowLayout {
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
public func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
if indexPath.row < imageAryCount {
return CGSize(width: (UIScreen.main.bounds.width/3)-3, height: (UIScreen.main.bounds.width/3)-3)
} else {
Expand All @@ -340,7 +340,7 @@ extension ImagePickerController: UICollectionViewDelegateFlowLayout {
}
}
extension ImagePickerController: UIScrollViewDelegate {
func scrollViewDidScroll(_ scrollView: UIScrollView) {
public func scrollViewDidScroll(_ scrollView: UIScrollView) {
let fiftyPercent = (scrollView.contentSize.height*50) / 100.0
if scrollView.bounds.maxY > fiftyPercent {
if type == .facebook {
Expand Down
30 changes: 18 additions & 12 deletions KiwiPods/Networking/NetworkModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -48,18 +48,23 @@ public protocol APIConfigurable: URLRequestConvertible {
}

public extension APIConfigurable {
public func asURLRequest() throws -> URLRequest {
var queryItems = ""
func asURLRequest() throws -> URLRequest {
let hasUrlEncodedParams = (type == .GET || type == .DELETE || type == .HEAD)
if hasUrlEncodedParams, parameters.count > 0 {
queryItems = parameters.reduce("?") { (value: String, arg1: (String, Any)) -> String in
return value + "\(arg1.0)=\(arg1.1)&"
}
queryItems.removeLast()
}
let url = URL(string: (path + queryItems))
// if hasUrlEncodedParams, parameters.count > 0 {
// queryItems = parameters.reduce("?") { (value: String, arg1: (String, Any)) -> String in
// return value + "\(arg1.0)=\(arg1.1)&"
// }
// queryItems.removeLast()
// }
let url = URL(string: path)
do {
var urlRequest = try URLRequest(url: url!, method: type.httpMethod)
if hasUrlEncodedParams {
let encoding = URLEncoding()
urlRequest = try encoding.encode(urlRequest, with: parameters)
} else {
urlRequest.httpBody = try JSONSerialization.data(withJSONObject: parameters, options: JSONSerialization.WritingOptions.prettyPrinted)
}
var apiHeaders = self.headers
//check if `Content-Type` is provided
// if `Content-Type` are not provided then add `application/json` as default
Expand All @@ -72,9 +77,6 @@ public extension APIConfigurable {
apiHeaders?["Content-Type"] = "application/json"
}
urlRequest.allHTTPHeaderFields = apiHeaders
if !hasUrlEncodedParams {
urlRequest.httpBody = try JSONSerialization.data(withJSONObject: parameters, options: JSONSerialization.WritingOptions.prettyPrinted)
}
return urlRequest
} catch {
throw error
Expand Down Expand Up @@ -141,6 +143,10 @@ public enum Response<ResponseType> where ResponseType: ParameterConvertible {
public struct ResponseValue {
public let value: ResponseType
public let statusCode: Int?
public init(value: ResponseType, statusCode: Int?) {
self.value = value
self.statusCode = statusCode
}
}
case success(ResponseValue),
failed(ResponseError)
Expand Down
6 changes: 4 additions & 2 deletions KiwiPods/Social/Facebook/FacebookHandler.swift
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,10 @@ open class FacebookHandler: NSObject {
}
}
}
public func getFacebookUserInfo(controller: UIViewController, completion: @escaping (_ result: FaceBookLoginData?, _ error: Error?) -> Void) {
// FacebookLoginHelper().getUserInfo(requestData: <#T##[String]#>, completion: <#T##(FaceBookLoginData?, Error?) -> Void#>)
public func getFacebookUserInfo(controller: UIViewController, completion: @escaping (_ email: String?, _ error: Error?) -> Void) {
FacebookLoginHelper().getUserInfo(requestData: ["email"]) { (result, error) in
completion(result?.email, error)
}
}
fileprivate static var imageUrls = [String: String]()
fileprivate static var queuedUrls = [String]()
Expand Down
4 changes: 2 additions & 2 deletions KiwiPods/Social/Google/GoogleHandler.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ open class GoogleHandler: NSObject {
} else {
loginCompletion = completion
loginHandlerController = controller
GIDSignIn.sharedInstance()?.uiDelegate = self
GIDSignIn.sharedInstance()?.delegate = self
GIDSignIn.sharedInstance()?.signIn()
}
}
Expand All @@ -40,7 +40,7 @@ extension GoogleHandler: GIDSignInDelegate {
loginCompletion?(user.authentication.idToken, nil)
}
}
extension GoogleHandler: GIDSignInUIDelegate {
extension GoogleHandler {
public func sign(_ signIn: GIDSignIn!, present viewController: UIViewController!) {
guard let controller = loginHandlerController else {
return
Expand Down
6 changes: 3 additions & 3 deletions Podfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ target 'KiwiPods' do
# Comment the next line if you're not using Swift and don't want to use dynamic frameworks
use_frameworks!
pod 'Alamofire', '~> 4.7'
pod 'FBSDKLoginKit', '~> 5.0.0'
pod 'FBSDKShareKit', '~> 5.0.0'
pod 'SDWebImage', '~> 5.0'
pod 'FBSDKLoginKit', '5.0.0'
pod 'FBSDKShareKit', '5.0.0'
pod 'SDWebImage', '5.0'
pod 'TwitterKit'
pod 'MBProgressHUD'
pod 'GoogleSignIn'
Expand Down