Skip to content

Instantly share code, notes, and snippets.

View pardel's full-sized avatar
🥑

Paul Ardeleanu pardel

🥑
View GitHub Profile
@pardel
pardel / gist:81eee1d308471fde2a5ccc4243372aad
Created February 21, 2017 15:19
swift IPv4 validation
func isValidIPv4(_ ip: String) -> Bool {
return ip
.characters.split(separator: ".").map { String($0) }
.flatMap { Int($0) }
.filter { (0...255).contains($0) }
.count == 4
}
//: Playground - noun: a place where people can play
import UIKit
class AView: UIView {
override init(frame: CGRect) {
super.init(frame: frame)
customInitialisation()
}
@pardel
pardel / MyAppAccount.swift
Created October 2, 2015 09:44
An example of using Latch (https://github.com/DanielTomlinson/Latch) to store user credentials
//
// MyAppAccount
//
struct MyAppAccount {
let latch = Latch(service: (NSBundle.mainBundle().bundleIdentifier ?? "com.example.MyApp"))
var username: String? {
@pardel
pardel / AlertView.swift
Created September 19, 2015 14:09
UIAlerView with Swift closures
//
// AlertView.swift
//
import UIKit
// holding array so the AlertView objects don't go out of scope
internal var alerts = [AlertView]()
@pardel
pardel / gist:cee3b428224d4f656296
Last active August 29, 2015 14:16
NSUUID().toString
extension NSUUID {
var toString: String {
return self.UUIDString
}
}
let uuid = NSUUID().toString
@pardel
pardel / gist:2c4a89c34875281aa2b7
Created September 16, 2014 04:17
iOS 8 GM memory warnings...
Sep 16 05:13:57 i5s SpringBoard[48] <Warning>: Received memory warning.
Sep 16 05:13:57 i5s discoveryd[50] <Notice>: Basic DeviceInformation Memory Pressure Warning sent: pressure
Sep 16 05:13:57 i5s MobileMail[1305] <Warning>: Received memory warning.
Sep 16 05:13:57 i5s MobilePhone[1176] <Warning>: Received memory warning.
Sep 16 05:13:57 i5s MobileSMS[316] <Warning>: Received memory warning.
Sep 16 05:13:57 i5s InCallService[163] <Warning>: Received memory warning.
Sep 16 05:13:57 i5s syncdefaultsd[1848] <Notice>: (Warn ) received memory warning
...
Sep 16 05:14:20 i5s Kindle[1827] <Warning>: Received memory warning.
...
@pardel
pardel / gist:3ffe5a94b764cbd813e9
Created September 8, 2014 09:15
saveContext extract
var error: NSError? = nil
if self.managedObjectContext?.save(&error) == true {
return
}
NSLog("Unresolved error \(error), \(error!.userInfo)")
@pardel
pardel / gist:6f8fc73c745925f47e38
Created September 7, 2014 05:53
CoreData saveContext with if/return transposition
func saveContext () {
return if self.managedObjectContext == nil
return if self.managedObjectContext?.hasChanges == false
var error: NSError? = nil
return if self.managedObjectContext?.save(&error) == true
NSLog("Unresolved error \(error), \(error!.userInfo)")
abort()
}