Skip to content

Commit

Permalink
[+] Migrate to swift 4.0
Browse files Browse the repository at this point in the history
  • Loading branch information
dmiotti committed Sep 21, 2017
1 parent 7feb372 commit c4c2931
Show file tree
Hide file tree
Showing 11 changed files with 26 additions and 26 deletions.
4 changes: 2 additions & 2 deletions SwiftHelpers.podspec
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
Pod::Spec.new do |s|
s.name = 'SwiftHelpers'
s.version = '5.0.4'
s.version = '6.0.0'
s.license = 'MIT'
s.summary = 'A collection of Swift extensions'
s.homepage = '[email protected]:dmiotti/SwiftHelpers.git'
s.social_media_url = 'https://twitter.com/davidmiotti'
s.authors = { 'David Miotti' => '[email protected]' }
s.source = { :git => '[email protected]:dmiotti/SwiftHelpers.git', :tag => 'v5.0.4' }
s.source = { :git => '[email protected]:dmiotti/SwiftHelpers.git', :tag => 'v6.0.0' }

s.platform = :ios, '8.0'

Expand Down
4 changes: 2 additions & 2 deletions SwiftHelpers.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -661,7 +661,7 @@
PRODUCT_NAME = "$(TARGET_NAME)";
SKIP_INSTALL = YES;
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_VERSION = 3.0;
SWIFT_VERSION = 4.0;
};
name = Debug;
};
Expand All @@ -681,7 +681,7 @@
PRODUCT_BUNDLE_IDENTIFIER = "com.wopata.$(PRODUCT_NAME:rfc1034identifier)";
PRODUCT_NAME = "$(TARGET_NAME)";
SKIP_INSTALL = YES;
SWIFT_VERSION = 3.0;
SWIFT_VERSION = 4.0;
};
name = Release;
};
Expand Down
2 changes: 1 addition & 1 deletion SwiftHelpers/Core/SHArrayExtension.swift
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ extension Array {
guard
case let swapIndex = Int(arc4random_uniform(UInt32(count - index))) + index,
swapIndex != index else { continue }
swap(&elements[index], &elements[swapIndex])
elements.swapAt(index, swapIndex)
}
return elements
}
Expand Down
2 changes: 1 addition & 1 deletion SwiftHelpers/Core/SHNSTimerExtension.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ private class TimerBlock {
self.block = block
}

dynamic func execute() {
@objc dynamic func execute() {
block()
}
}
Expand Down
10 changes: 5 additions & 5 deletions SwiftHelpers/Core/SHStringExtension.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import Foundation
import UIKit

public extension NSAttributedString {
public func replace(HTMLTag tag: String, with attributes: [String: AnyObject]) -> NSAttributedString {
public func replace(HTMLTag tag: String, with attributes: [NSAttributedStringKey: AnyObject]) -> NSAttributedString {
let openTag = "<\(tag)>"
let closeTag = "</\(tag)>"
let resultingText: NSMutableAttributedString = self.mutableCopy() as! NSMutableAttributedString
Expand Down Expand Up @@ -143,17 +143,17 @@ public extension String {
}

public extension String {
public func fontSizeThatFits(_ font: UIFont, attributes: [String: AnyObject]?, size: CGSize) -> UIFont {
public func fontSizeThatFits(_ font: UIFont, attributes: [NSAttributedStringKey: AnyObject]?, size: CGSize) -> UIFont {
let txt = NSString(string: self)
var fntSize = font.pointSize + 1
var width = CGFloat(Float.infinity)
var height = CGFloat(Float.infinity)
repeat {
fntSize -= 1
let fnt = UIFont(name: font.fontName, size: fntSize)
var attrs = attributes ?? [String: AnyObject]()
attrs[NSFontAttributeName] = fnt
let size = txt.size(attributes: attrs)
var attrs = attributes ?? [NSAttributedStringKey: AnyObject]()
attrs[.font] = fnt
let size = txt.size(withAttributes: attrs)
width = size.width
height = size.height
} while ((width > size.width || height > size.height) && fntSize > 0)
Expand Down
6 changes: 3 additions & 3 deletions SwiftHelpers/CoreData/SHCoreDataStack.swift
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ public final class CoreDataStack: NSObject {
nc.addObserver(self, selector: #selector(CoreDataStack.persistentStoreDidImportUbiquitousContentChanges(_:)), name: NSNotification.Name.NSPersistentStoreDidImportUbiquitousContentChanges, object: nil)
}

func storesWillChange(_ notification: Foundation.Notification) {
@objc func storesWillChange(_ notification: Foundation.Notification) {
managedObjectContext.perform {
if self.managedObjectContext.hasChanges {
do {
Expand All @@ -131,11 +131,11 @@ public final class CoreDataStack: NSObject {
NotificationCenter.default.post(name: Notification.Name(rawValue: kCoreDataStackStoreWillChange), object: nil, userInfo: nil)
}

func storesDidChange(_ notification: Foundation.Notification) {
@objc func storesDidChange(_ notification: Foundation.Notification) {
NotificationCenter.default.post(name: Notification.Name(rawValue: kCoreDataStackStoreDidChange), object: nil, userInfo: nil)
}

func persistentStoreDidImportUbiquitousContentChanges(_ notification: Foundation.Notification) {
@objc func persistentStoreDidImportUbiquitousContentChanges(_ notification: Foundation.Notification) {
managedObjectContext.perform {
self.managedObjectContext.mergeChanges(fromContextDidSave: notification)
NSLog("NSPersistentStoreDidImportUbiquitousContentChangesNotification executed")
Expand Down
4 changes: 2 additions & 2 deletions SwiftHelpers/Misc/SHKeyboardViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ open class SHKeyboardViewController: UIViewController {
NotificationCenter.default.addObserver(self, selector: #selector(SHKeyboardViewController.keyboardWillHide(_:)), name: NSNotification.Name.UIKeyboardWillHide, object: nil)
}

open func keyboardWillShow(_ notification: Foundation.Notification) {
@objc open func keyboardWillShow(_ notification: Foundation.Notification) {
if let scrollableView = scrollableView {
let scrollViewRect = view.convert(scrollableView.frame, from: scrollableView.superview)

Expand All @@ -42,7 +42,7 @@ open class SHKeyboardViewController: UIViewController {
}
}

open func keyboardWillHide(_ notification: Foundation.Notification) {
@objc open func keyboardWillHide(_ notification: Foundation.Notification) {
if let scrollableView = scrollableView {
var contentInsets = scrollableView.contentInset
contentInsets.bottom = 0
Expand Down
8 changes: 4 additions & 4 deletions SwiftHelpers/UI/SHAttributedLabel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -45,16 +45,16 @@ import UIKit
}

fileprivate func refreshAttributes() {
var attributes: [String: AnyObject] = [:]
attributes[NSFontAttributeName] = font
var attributes: [NSAttributedStringKey: AnyObject] = [:]
attributes[.font] = font
if kerning > 0 {
attributes[NSKernAttributeName] = kerning as AnyObject?
attributes[.kern] = kerning as AnyObject?
}
if interlineSpacing > 0 {
let paragraphStyle = NSMutableParagraphStyle()
paragraphStyle.alignment = textAlignment
paragraphStyle.lineSpacing = CGFloat(interlineSpacing)
attributes[NSParagraphStyleAttributeName] = paragraphStyle
attributes[.paragraphStyle] = paragraphStyle
}
attributedText = NSAttributedString(string: text ?? "", attributes: attributes)
}
Expand Down
8 changes: 4 additions & 4 deletions SwiftHelpers/UI/SHDatePickerController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -94,19 +94,19 @@ open class SHDatePickerViewController: UIViewController {
toolbar.items = [leftSpace, cancelButton, centerSpace, confirmButton, rightSpace]
}

func tappedDoneButton(_ button: UIBarButtonItem) {
@objc func tappedDoneButton(_ button: UIBarButtonItem) {
dismissWithDate(datePicker.date)
}

func tappedCancelButton(_ button: UIBarButtonItem) {
@objc func tappedCancelButton(_ button: UIBarButtonItem) {
dismissWithDate(nil)
}

func tappedBackgroundView(_ gestureRecognizer: UITapGestureRecognizer) {
@objc func tappedBackgroundView(_ gestureRecognizer: UITapGestureRecognizer) {
dismissWithDate(nil)
}

func swipedBackgroundView(_ gestureRecognizer: UISwipeGestureRecognizer) {
@objc func swipedBackgroundView(_ gestureRecognizer: UISwipeGestureRecognizer) {
dismissWithDate(nil)
}

Expand Down
2 changes: 1 addition & 1 deletion SwiftHelpers/UI/SHPagedScrollView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ open class SHPagedScrollView: UIScrollView {
isPagingEnabled = true
}

func viewWasTapped(_ gestureRecognizer: UITapGestureRecognizer) {
@objc func viewWasTapped(_ gestureRecognizer: UITapGestureRecognizer) {
guard let view = gestureRecognizer.view, let index = views.index(of: view) else { return }
datasource?.pagedScrollView?(self, tappedViewAt: index)
}
Expand Down
2 changes: 1 addition & 1 deletion SwiftHelpers/UI/SHUIImageExtension.swift
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public extension UIImage {

let width = Int(self.size.width)
let height = Int(self.size.height)
let context = CGContext(data: nil, width: width, height: height, bitsPerComponent: 8, bytesPerRow: 0, space: colorSpace, bitmapInfo: .allZeros);
let context = CGContext(data: nil, width: width, height: height, bitsPerComponent: 8, bytesPerRow: 0, space: colorSpace, bitmapInfo: 0);
context?.draw(cgImage!, in: imageRect)

if let imageRef = context?.makeImage() {
Expand Down

0 comments on commit c4c2931

Please sign in to comment.