Skip to content

Instantly share code, notes, and snippets.

View juliengdt's full-sized avatar
🎯
Focusing

juliengdt juliengdt

🎯
Focusing
View GitHub Profile
@juliengdt
juliengdt / gist:e1c143a7e6652458bb0b
Last active August 29, 2015 14:25 — forked from bwhiteley/gist:049e4bede49e71a6d2e2
Initialize Swift subclass of UIView, designed in .xib
// Create CustomView.xib, set File's Owner to CustomView.
// Link the top level view in the XIB to the contentView outlet.
class CustomView : UIView {
@IBOutlet weak private var contentView:UIView!
// other outlets
override init(frame: CGRect) { // for using CustomView in code
super.init(frame: frame)
self.commonInit()
@juliengdt
juliengdt / SpringExtension.swift
Last active August 29, 2015 14:27
Because Spring framework in Swift 2.0 is awesome, lazy functions are moaar awesome !!!
extension SpringView {
func fadeIn(duration: CGFloat, completion: (() -> ())? = nil) {
self.animation = "fadeIn"
self.duration = duration
self.animateNext() {
completion?()
}
}
@juliengdt
juliengdt / AutoScroll.swift
Last active August 29, 2015 14:27
Auto-Scroll in Swift, wherever you want, everywhere - not perfect but works like a charm
extension UIView {
//MARK: - AutoScroll Stuff -
private func autoScroll(view: UIView, kbFrame: CGRect, animated: Bool) {
let offset = kbFrame.height + 20
let deltaOffset = CGRectGetMinY(view.convertRect(view.bounds, toView: self.view)) - offset
autoScrollOffset = deltaOffset < 0 ? 0 : deltaOffset
totalAutoScrollOffset = autoScrollOffset
@juliengdt
juliengdt / SwiftIntegerChecker.swift
Created August 26, 2015 07:48
To check if a number is between a range in Swift
// To check if a number is between a range, don't do
if number >=0 && number <= 100 {
}
// Use range and news operators instead :
if 0...100 ~= number {
}
@juliengdt
juliengdt / ats-workaround.plist
Created October 14, 2015 14:35
Apple ATS Workarounds
<!--Allow unsecured connections in a whitelist-->
<key>NSAppTransportSecurity</key>
<dict>
<key>NSExceptionDomains</key>
<dict>
<key>yourserver.com</key>
<dict>
<!--Include to allow subdomains-->
<key>NSIncludesSubdomains</key>
<true/>
@juliengdt
juliengdt / Theme.swift
Created October 28, 2015 08:43
Theme in swift, just by applying in your appDelegate Theme.applyThemeAppearance()
//
// Theme.swift
// juliengdt
//
// Created by julien.GOUDET on 26/10/2015.
// Copyright © 2015 julien.GOUDET. All rights reserved.
//
import Foundation
import UIKit
@juliengdt
juliengdt / CollectionTypeSkipper.swift
Created March 30, 2016 14:15
CollectionType Skipper
// MARK: - CollectionType Addition
extension CollectionType {
/**
Create and return a new CollectionType made with only skipped items, which index is not a divider of "skip"
- parameter skip: the divider index
- returns: the new collectionType
*/
func skip(skip: Int) -> [Generator.Element] {
struct Throttle {
static func onQueue(queue: NSOperationQueue, by timeInterval: NSTimeInterval, function: () -> ()) {
queue.cancelAllOperations()
let delayOperation = DelayOperation(timeInterval: timeInterval)
let throttledOperation = NSBlockOperation() {
function()
}
throttledOperation.addDependency(delayOperation)
queue.addOperations([delayOperation, throttledOperation], waitUntilFinished: false)
@juliengdt
juliengdt / HCLog_Playground_V2.swift
Last active May 19, 2016 09:28
Swift Protocol Logger with level condition, Swift 2.X and Swift 3.X version
//: Playground - noun: a place where people can play
// Usage for Swift 2.X using the deadly old Swift Debugger Identifiers, ie: __FILE__
// @see: https://github.com/apple/swift-evolution/blob/master/proposals/0028-modernizing-debug-identifiers.md
enum LogLevel: Int {
case verbose = 1
case debug = 2
case info = 3
case warning = 4
@juliengdt
juliengdt / lowpower_mode.md
Last active August 26, 2023 18:26
Detect and make your iPhone app responds to low-power mode

Low Power Mode - LPM

With iOS 9 Apple added a Low Power Mode to the iPhone. It extends battery life by stopping some battery heavy features such as email fetch, Hey Siri and background app refresh until you can recharge the device.

It is important to understand that it is the user who decides to enter low power mode. You need to go into the battery settings to turn it on.

Detection

To detect LPM you have to be in the couple iOS 9.X / iPhone:

  • For iOS 8.X, you need test availablity before use it