Skip to content

Instantly share code, notes, and snippets.

@gkye
gkye / shuffleArray.swift
Last active February 22, 2016 03:59
shuffle array (self)
mutating func shuffle() {
if count < 2 { return }
for i in 0..<(count - 1) {
let j = Int(arc4random_uniform(UInt32(count - i))) + i
swap(&self[i], &self[j])
}
}
var tags = [1,7782,25]
tags.shuffle()
@gkye
gkye / shiftArrayIndex.swift
Created February 22, 2016 03:58
shift array index
mutating func moveItem(fromIndex oldIndex: Index, toIndex newIndex: Index) {
insert(removeAtIndex(oldIndex), atIndex: newIndex)
}
var tags = [1,2,3,4,5,7782,25]
tags.moveItem(fromIndex: 2, toIndex: tags.count-1)
class VerticalLayout: UIView {
var yOffsets: [CGFloat] = []
init(width: CGFloat) {
super.init(frame: CGRectMake(0, 0, width, 0))
}
required init(coder aDecoder: NSCoder) {
@gkye
gkye / clear cache memory warning
Created March 24, 2016 17:34
clear cache memory warning. swift 2.2
func applicationDidReceiveMemoryWarning(application: UIApplication) {
NSURLCache.sharedURLCache().removeAllCachedResponses()
}
@gkye
gkye / getRequest.swift
Last active September 6, 2020 16:48
NSURLSession: GET Request with parameters swift 2.0
//Encode params to be web friendly and return a string. Reference ->http://stackoverflow.com/a/27724627/6091482
extension String {
/// Percent escapes values to be added to a URL query as specified in RFC 3986
///
/// This percent-escapes all characters besides the alphanumeric character set and "-", ".", "_", and "~".
///
/// http://www.ietf.org/rfc/rfc3986.txt
///
--http://stackoverflow.com/a/26326006/5222077
public extension UIView {
public class func fromNib(nibNameOrNil: String? = nil) -> Self {
return fromNib(nibNameOrNil, type: self)
}
public class func fromNib<T : UIView>(nibNameOrNil: String? = nil, type: T.Type) -> T {
let v: T? = fromNib(nibNameOrNil, type: T.self)
return v!
//
// ProfileViewController.swift
// Drizzle
//
// Created by George on 2016-04-17.
// Copyright © 2016 George. All rights reserved.
//
import UIKit
import IBAnimatable
extension String {
//Convert html strings to an attributed string
var html2AttributedString: NSMutableAttributedString? {
guard
let data = dataUsingEncoding(NSUTF8StringEncoding)
else { return nil }
do {
let attrStr = try NSMutableAttributedString(data: data, options: [NSDocumentTypeDocumentAttribute:NSHTMLTextDocumentType,NSCharacterEncodingDocumentAttribute:NSUTF8StringEncoding], documentAttributes: nil)
attrStr.addAttributes([NSFontAttributeName: UIFont.systemFontOfSize(17.0)], range: NSRange(location: 0, length: attrStr.length))
return attrStr

Swiper

UIView sublass for creating Tinder like swipe cards, with a peek view.

Usage

Check out the demo app for a detailed example.

Adding Swiper View

A Swiper view can be added via storyboard or programmatically

var swiperView = Swiper(frame: CGRect(x: 0, y: 0, width: 350, height: 350)))

Updates

  • Added public func pauseInteractiveTransition() to ContainerTransition
  • Updated Project Settings,
  • Updated inout parameters
  • Guard stament to prevent presentingViewController from returning nil and crashing (Flip presentation)
  • Issues Unable to go back after using Cover presentation