Skip to content
This repository has been archived by the owner on Dec 29, 2022. It is now read-only.

Commit

Permalink
Refactored Xcode Project Setup
Browse files Browse the repository at this point in the history
  • Loading branch information
SvenTiigi committed Jan 18, 2019
1 parent 09ed300 commit 7cebbce
Show file tree
Hide file tree
Showing 53 changed files with 930 additions and 679 deletions.
6 changes: 3 additions & 3 deletions .codeclimate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ plugins:
swiftlint:
enabled: true
exclude_patterns:
- "STLocationRequestExample/"
- "STLocationRequestTests/"
- "Example-iOS/"
- "Tests/"
- "Configs/"
- "Carthage/"
- "fastlane/"
Expand All @@ -20,4 +20,4 @@ exclude_patterns:
- "Cartfile"
- "Cartfile.resolved"
- "**/*.h"
- "**/*.plist"
- "**/*.plist"
5 changes: 3 additions & 2 deletions .swiftlint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,11 @@ opt_in_rules: # some rules are only opt-in
- valid_docs

included: # paths to include during linting. `--path` is ignored if present.
- STLocationRequest
- Sources

excluded: # paths to ignore during linting. Takes precedence over `included`.
- Frameworks
- Tests
- Example-iOS

disabled_rules: # rule identifiers to exclude from running
- trailing_whitespace
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<plist version="1.0">
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>$(DEVELOPMENT_LANGUAGE)</string>
<string>en</string>
<key>CFBundleExecutable</key>
<string>$(EXECUTABLE_NAME)</string>
<key>CFBundleIdentifier</key>
Expand All @@ -16,8 +16,12 @@
<string>FMWK</string>
<key>CFBundleShortVersionString</key>
<string>3.2.2</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>$(CURRENT_PROJECT_VERSION)</string>
<key>NSHumanReadableCopyright</key>
<string>Copyright © 2019 Sven Tiigi. All rights reserved.</string>
<key>NSPrincipalClass</key>
<string></string>
</dict>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<plist version="1.0">
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>$(DEVELOPMENT_LANGUAGE)</string>
<string>en</string>
<key>CFBundleExecutable</key>
<string>$(EXECUTABLE_NAME)</string>
<key>CFBundleIdentifier</key>
Expand All @@ -15,7 +15,9 @@
<key>CFBundlePackageType</key>
<string>BNDL</string>
<key>CFBundleShortVersionString</key>
<string>3.2.2</string>
<string>1.0</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>1</string>
</dict>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
//
// AppDelegate.swift
// STLocationRequestExample
// Example-iOS
//
// Created by Sven Tiigi on 16.02.18.
// Copyright © 2018 Sven Tiigi. All rights reserved.
// Created by Sven Tiigi on 18.01.19.
// Copyright © 2019 Sven Tiigi. All rights reserved.
//

import UIKit
Expand All @@ -16,15 +16,23 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
/// The UINavigationController with ViewController as rootViewController
lazy var navigationController: UINavigationController = {
let navigationController = UINavigationController(rootViewController: ViewController())
navigationController.navigationBar.prefersLargeTitles = true
navigationController.navigationBar.largeTitleTextAttributes = [
.foregroundColor: UIColor.main
]
if #available(iOS 11.0, *) {
navigationController.navigationBar.prefersLargeTitles = true
navigationController.navigationBar.largeTitleTextAttributes = [
.foregroundColor: UIColor.main
]
}
navigationController.navigationBar.tintColor = .main
navigationController.navigationBar.titleTextAttributes = [.foregroundColor: UIColor.main]
return navigationController
}()

/// Application did finish launching with options
///
/// - Parameters:
/// - application: The Application
/// - launchOptions: The LaunchOptions
/// - Returns: Bool
func application(_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.
Expand All @@ -34,4 +42,6 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
return true
}


}

Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
//
// PresentButton.swift
// STLocationRequest_Example
// Example-iOS
//
// Created by Sven Tiigi on 29.01.18.
// Copyright © 2018 CocoaPods. All rights reserved.
// Created by Sven Tiigi on 18.01.19.
// Copyright © 2019 Sven Tiigi. All rights reserved.
//

import UIKit
Expand Down Expand Up @@ -68,3 +68,4 @@ class PresentButton: UIButton {
}

}

Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
//
// UIColor+Main.swift
// STLocationRequest_Example
// Example-iOS
//
// Created by Sven Tiigi on 29.01.18.
// Copyright © 2018 CocoaPods. All rights reserved.
// Created by Sven Tiigi on 18.01.19.
// Copyright © 2019 Sven Tiigi. All rights reserved.
//

import UIKit
Expand Down
98 changes: 49 additions & 49 deletions ...xample/Supporting Files/UIImage+Gif.swift → Example-iOS/Extensions/UIImage+Gif.swift
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
//
// Gif.swift
// SwiftGif
// UIImage+Gif.swift
// Example-iOS
//
// Created by Arne Bahlo on 07.06.14.
// Copyright (c) 2014 Arne Bahlo. All rights reserved.
// Created by Sven Tiigi on 18.01.19.
// Copyright © 2019 Sven Tiigi. All rights reserved.
//

import ImageIO
import UIKit

extension UIImageView {

public func loadGif(name: String) {
DispatchQueue.global().async {
let image = UIImage.gif(name: name)
Expand All @@ -19,85 +19,85 @@ extension UIImageView {
}
}
}

}

extension UIImage {

public class func gif(data: Data) -> UIImage? {
// Create source from data
guard let source = CGImageSourceCreateWithData(data as CFData, nil) else {
print("SwiftGif: Source for the image does not exist")
return nil
}

return UIImage.animatedImageWithSource(source)
}

public class func gif(url: String) -> UIImage? {
// Validate URL
guard let bundleURL = URL(string: url) else {
print("SwiftGif: This image named \"\(url)\" does not exist")
return nil
}

// Validate data
guard let imageData = try? Data(contentsOf: bundleURL) else {
print("SwiftGif: Cannot turn image named \"\(url)\" into NSData")
return nil
}

return gif(data: imageData)
}

public class func gif(name: String) -> UIImage? {
// Check for existance of gif
guard let bundleURL = Bundle.main
.url(forResource: name, withExtension: "gif") else {
print("SwiftGif: This image named \"\(name)\" does not exist")
return nil
.url(forResource: name, withExtension: "gif") else {
print("SwiftGif: This image named \"\(name)\" does not exist")
return nil
}

// Validate data
guard let imageData = try? Data(contentsOf: bundleURL) else {
print("SwiftGif: Cannot turn image named \"\(name)\" into NSData")
return nil
}

return gif(data: imageData)
}

internal class func delayForImageAtIndex(_ index: Int, source: CGImageSource!) -> Double {
var delay = 0.1

// Get dictionaries
let cfProperties = CGImageSourceCopyPropertiesAtIndex(source, index, nil)
let gifPropertiesPointer = UnsafeMutablePointer<UnsafeRawPointer?>.allocate(capacity: 0)
if CFDictionaryGetValueIfPresent(cfProperties, Unmanaged.passUnretained(kCGImagePropertyGIFDictionary).toOpaque(), gifPropertiesPointer) == false {
return delay
}

let gifProperties:CFDictionary = unsafeBitCast(gifPropertiesPointer.pointee, to: CFDictionary.self)

// Get delay time
var delayObject: AnyObject = unsafeBitCast(
CFDictionaryGetValue(gifProperties,
Unmanaged.passUnretained(kCGImagePropertyGIFUnclampedDelayTime).toOpaque()),
Unmanaged.passUnretained(kCGImagePropertyGIFUnclampedDelayTime).toOpaque()),
to: AnyObject.self)
if delayObject.doubleValue == 0 {
delayObject = unsafeBitCast(CFDictionaryGetValue(gifProperties,
Unmanaged.passUnretained(kCGImagePropertyGIFDelayTime).toOpaque()), to: AnyObject.self)
Unmanaged.passUnretained(kCGImagePropertyGIFDelayTime).toOpaque()), to: AnyObject.self)
}

delay = delayObject as? Double ?? 0

if delay < 0.1 {
delay = 0.1 // Make sure they're not too fast
}

return delay
}

internal class func gcdForPair(_ a: Int?, _ b: Int?) -> Int {
var a = a
var b = b
Expand All @@ -111,19 +111,19 @@ extension UIImage {
return 0
}
}

// Swap for modulo
if a! < b! {
let c = a
a = b
b = c
}

// Get greatest common divisor
var rest: Int
while true {
rest = a! % b!

if rest == 0 {
return b! // Found it
} else {
Expand All @@ -132,70 +132,70 @@ extension UIImage {
}
}
}

internal class func gcdForArray(_ array: Array<Int>) -> Int {
if array.isEmpty {
return 1
}

var gcd = array[0]

for val in array {
gcd = UIImage.gcdForPair(val, gcd)
}

return gcd
}

internal class func animatedImageWithSource(_ source: CGImageSource) -> UIImage? {
let count = CGImageSourceGetCount(source)
var images = [CGImage]()
var delays = [Int]()

// Fill arrays
for i in 0..<count {
// Add image
if let image = CGImageSourceCreateImageAtIndex(source, i, nil) {
images.append(image)
}

// At it's delay in cs
let delaySeconds = UIImage.delayForImageAtIndex(Int(i),
source: source)
source: source)
delays.append(Int(delaySeconds * 1000.0)) // Seconds to ms
}

// Calculate full duration
let duration: Int = {
var sum = 0

for val: Int in delays {
sum += val
}

return sum
}()

}()
// Get frames
let gcd = gcdForArray(delays)
var frames = [UIImage]()

var frame: UIImage
var frameCount: Int
for i in 0..<count {
frame = UIImage(cgImage: images[Int(i)])
frameCount = Int(delays[Int(i)] / gcd)

for _ in 0..<frameCount {
frames.append(frame)
}
}

// Heyhey
let animation = UIImage.animatedImage(with: frames,
duration: Double(duration) / 1000.0)

duration: Double(duration) / 1000.0)
return animation
}

}
Loading

0 comments on commit 7cebbce

Please sign in to comment.