Skip to content

Instantly share code, notes, and snippets.

@krodak
krodak / Realm+CascadeDeleting.swift
Last active Aug 14, 2021
Cascade deletion for RealmSwift
View Realm+CascadeDeleting.swift
import RealmSwift
import Realm
protocol CascadeDeleting: class {
func delete<Entity>(_ list: List<Entity>, cascading: Bool)
func delete<Entity>(_ results: Results<Entity>, cascading: Bool)
func delete<Entity: Object>(_ entity: Entity, cascading: Bool)
}
@Ben-G
Ben-G / L10NTests.swift
Created Jun 16, 2017
Very simple automated test to ensure localizations exist and are well-formed on iOS.
View L10NTests.swift
import Foundation
import XCTest
/// Basic sanity check that ensures that we are able to retrieve localized strings for all languages
/// we support.
final class L10NTests: XCTestCase {
func testLocalizations() {
let locales = ["en", "es", "zh-Hans", "zh-Hant", "fi"]
for locale in locales {
@balachandarlinks
balachandarlinks / Dockerfile
Last active Nov 27, 2020
Dockerfile for https://github.com/gojuno/mainframer remote android build system.
View Dockerfile
FROM ubuntu:16.04
MAINTAINER Balachandar KM "balachandarlinks@gmail.com"
# Install java7
RUN apt-get update && \
apt-get install -y software-properties-common && \
add-apt-repository -y ppa:webupd8team/java && \
(echo oracle-java7-installer shared/accepted-oracle-license-v1-1 select true | /usr/bin/debconf-set-selections) && \
apt-get update && \
View WifiConnectionReceiver.java
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.net.wifi.WifiConfiguration;
import android.net.wifi.WifiManager;
import android.support.annotation.NonNull;
import android.util.Log;
import static android.content.ContentValues.TAG;
@brennanMKE
brennanMKE / TaskScheduler.swift
Created Jan 20, 2017
Task Scheduler with Swift 2.3
View TaskScheduler.swift
public class TaskScheduler: NSObject {
weak var timer: NSTimer? = nil
var task: ((NSTimer) -> Void)?
public func schedule(interval: NSTimeInterval, repeats: Bool, task: ((NSTimer) -> Void)? = nil) -> NSTimer? {
if !NSThread.isMainThread() {
return nil
}
@gonzalezreal
gonzalezreal / A.LICENSE.md
Last active Jul 1, 2020
Using Realm with Value Types
View A.LICENSE.md

Copyright 2017 Guillermo Gonzalez

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE U

@ryuichis
ryuichis / Event.swift
Created Oct 15, 2016
Swift 3 Struct & NSCoding
View Event.swift
public struct Event {
public internal(set) var timeStamp: Date
public internal(set) var eventTag: String
public init(timeStamp: Date, tag: String) {
self.timeStamp = timeStamp
self.eventTag = tag
}
}
View export-fat-swift-dynamic-framework.sh
exec > /tmp/${PROJECT_NAME}_archive.log 2>&1
UNIVERSAL_OUTPUTFOLDER=${BUILD_DIR}/${CONFIGURATION}-universal
if [ "true" == ${ALREADYINVOKED:-false} ]
then
echo "RECURSION: Detected, stopping"
else
export ALREADYINVOKED="true"
View PHPhotoLibrary+PhotoAsset.swift
extension PHPhotoLibrary {
typealias PhotoAsset = PHAsset
typealias PhotoAlbum = PHAssetCollection
static func saveImage(image: UIImage, albumName: String, completion: (PHAsset?)->()) {
if let album = self.findAlbum(albumName) {
saveImage(image, album: album, completion: completion)
return
}
@acrookston
acrookston / README.md
Last active Aug 29, 2021
Xcode pre-action to build custom Info.plist
View README.md

Automatic build versions from git in Xcode (and other goodies)

Installation procedure for pre-build actions to automatically populate Xcode Info.plist with dynamic data.

1. Xcode Scheme pre-action

Edit Xcode Scheme and add a pre-action script. Copy the contents of preaction.sh into the pre-action script box.