Skip to content

Instantly share code, notes, and snippets.

View amlcurran's full-sized avatar

Alex Curran amlcurran

View GitHub Profile
@amlcurran
amlcurran / StrictMode violation with Intent.ACTION_CALL
Last active August 29, 2015 14:01
StrictMode violation with Intent.ACTION_CALL
05-24 17:44:17.270 1388-1388/com.amlcurran.messages D/StrictMode﹕ StrictMode policy violation; ~duration=233 ms: android.os.StrictMode$StrictModeDiskReadViolation: policy=2335 violation=2
at android.os.StrictMode$AndroidBlockGuardPolicy.onReadFromDisk(StrictMode.java:1135)
at libcore.io.BlockGuardOs.open(BlockGuardOs.java:106)
at libcore.io.IoBridge.open(IoBridge.java:393)
at java.io.FileOutputStream.<init>(FileOutputStream.java:88)
at java.io.FileOutputStream.<init>(FileOutputStream.java:73)
at com.android.server.pm.Settings.writePackageRestrictionsLPr(Settings.java:1062)
at com.android.server.pm.PackageManagerService.findPreferredActivity(PackageManagerService.java:3086)
at com.android.server.pm.PackageManagerService.chooseBestActivity(PackageManagerService.java:2945)
at com.android.server.pm.PackageManagerService.resolveIntent(PackageManagerService.java:2886)
<link rel="import" href="../core-icon-button/core-icon-button.html">
<link rel="import" href="../core-toolbar/core-toolbar.html">
<link rel="import" href="../core-header-panel/core-header-panel.html">
<polymer-element name="my-element">
<template>
<style>
:host {
position: absolute;
class FirstViewController: UIViewController, UITableViewDelegate {
private let items : [String] = [ /* some items */]
private let tableView = UITableView()
/* lots of other methods */
override func viewDidAppear(animated: Bool) {
super.viewDidAppear(animated)
tableView.delegate = self
@amlcurran
amlcurran / inheritance.swift
Created June 12, 2016 12:58
Delegation 1: Inheritance
class FirstViewController: UIViewController, UITableViewDelegate {
private let items : [String] = [ /* some items */]
private let tableView = UITableView()
/* lots of other methods */
override func viewDidAppear(animated: Bool) {
super.viewDidAppear(animated)
tableView.delegate = self
@amlcurran
amlcurran / extension.swift
Created June 12, 2016 12:58
Delegation 2: extension
class FirstViewController: UIViewController {
private let items : [String] = [ /* some items */]
private let tableView = UITableView()
/* lots of other methods */
override func viewDidAppear(animated: Bool) {
super.viewDidAppear(animated)
tableView.delegate = self
@amlcurran
amlcurran / delegation.swift
Last active June 12, 2016 12:59
Delegation 3: Delegation
class FirstViewController: UIViewController {
private let items : [String] = [ /* some items */]
private let tableView = UITableView()
private var delegate : UITableViewDelegate!
/* lots of other methods */
override func viewDidAppear(animated: Bool) {
super.viewDidAppear(animated)
var string: String = "hello"
string = nil // fails to compile - trying to assign nil to a non-optional value
var optionalString: String? = "hello"
optionalString = nil // compiles fine, as we've declared this to be an optional string
@amlcurran
amlcurran / Chaining.swift
Created July 31, 2016 13:36
swift-optional-chaining
let optionalString: String? = nil
let count = optionalString?.utf8.count // count is an optional Int
@amlcurran
amlcurran / Ifguardlet.swift
Created July 31, 2016 13:55
if let and guard let
func doSomething(optionalString: String?) {
if let string = optionalString {
let count = string.utf8.count // string is not optional and can be used normally
}
}
func doSomething(optionalString: String?) {
guard let string = optionalString else {
// this closure is called if optionalString was nil
return
// this is less descriptive and more difficult to read
if (user.getState() == LoginState.LOGGED_IN && articleList.getQueue().size() > 0) {
uploadArticles();
}
// this is much easier to read and know what's happening
if (user.isLoggedIn() && articleList.hasQueuedArticles()) {
uploadArticles();
}