Skip to content

Instantly share code, notes, and snippets.

Avatar
🥑

Paul Ardeleanu pardel

🥑
View GitHub Profile
View gist:81eee1d308471fde2a5ccc4243372aad
func isValidIPv4(_ ip: String) -> Bool {
return ip
.characters.split(separator: ".").map { String($0) }
.flatMap { Int($0) }
.filter { (0...255).contains($0) }
.count == 4
}
View test playground
//: 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 Oct 2, 2015
An example of using Latch (https://github.com/DanielTomlinson/Latch) to store user credentials
View MyAppAccount.swift
//
// MyAppAccount
//
struct MyAppAccount {
let latch = Latch(service: (NSBundle.mainBundle().bundleIdentifier ?? "com.example.MyApp"))
var username: String? {
@pardel
pardel / AlertView.swift
Created Sep 19, 2015
UIAlerView with Swift closures
View AlertView.swift
//
// AlertView.swift
//
import UIKit
// holding array so the AlertView objects don't go out of scope
internal var alerts = [AlertView]()
View gist:cee3b428224d4f656296
extension NSUUID {
var toString: String {
return self.UUIDString
}
}
let uuid = NSUUID().toString
@pardel
pardel / gist:2c4a89c34875281aa2b7
Created Sep 16, 2014
iOS 8 GM memory warnings...
View gist:2c4a89c34875281aa2b7
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.
...
View gist:3ffe5a94b764cbd813e9
var error: NSError? = nil
if self.managedObjectContext?.save(&error) == true {
return
}
NSLog("Unresolved error \(error), \(error!.userInfo)")
@pardel
pardel / gist:6f8fc73c745925f47e38
Created Sep 7, 2014
CoreData saveContext with if/return transposition
View gist:6f8fc73c745925f47e38
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()
}