This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// sends SwiftyBeaver logs to a file in your app’s document directory | |
// instead of the default caches directory | |
// learn more about SwiftyBeaver at https://github.com/SwiftyBeaver/SwiftyBeaver | |
let fm = NSFileManager.defaultManager() | |
if let docsURL = fm.URLsForDirectory(.DocumentDirectory, inDomains: .UserDomainMask).first { | |
let file = FileDestination() | |
file.logFileURL = docsURL.URLByAppendingPathComponent("my.log") | |
log.addDestination(file) | |
log.info("writing logs to \(file.logFileURL)") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// returns optional relative date interval string like "2d" | |
/// depending on the unitsstyle, see docs at http://apple.co/1ox2sOX | |
/// inject an existing NSDateComponentsFormatter() for performance | |
func relativeDateInterval(date: NSDate, | |
unitsStyle: NSDateComponentsFormatterUnitsStyle, | |
formatter: NSDateComponentsFormatter) -> String? { | |
// inspired by top answer at http://bit.ly/1TzMQqV | |
let formatter = NSDateComponentsFormatter() | |
formatter.unitsStyle = unitsStyle //.Abbreviated, .Full, ... | |
formatter.includesApproximationPhrase = false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Build settings from command line: | |
ONLY_ACTIVE_ARCH = NO | |
SDKROOT = iphonesimulator9.2 | |
=== BUILD TARGET SwiftyBeaver (iOS) OF PROJECT SwiftyBeaver WITH CONFIGURATION Release === | |
Check dependencies | |
Write auxiliary files | |
write-file /Users/sebastian/Library/Developer/Xcode/DerivedData/SwiftyBeaver-afdkbmzqyrmnmdcgjtcdgpqjjvcp/Build/Intermediates/SwiftyBeaver.build/all-product-headers.yaml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import CloudKit | |
iCloudUserIDAsync() { | |
recordID, error in | |
if let userID = recordID?.recordName { | |
print("received iCloudID \(userID)") | |
} else { | |
print("Fetched iCloudID was nil") | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import CloudKit | |
/// async gets iCloud record ID object of logged-in iCloud user | |
func iCloudUserIDAsync(complete: (instance: CKRecordID?, error: NSError?) -> ()) { | |
let container = CKContainer.defaultContainer() | |
container.fetchUserRecordIDWithCompletionHandler() { | |
recordID, error in | |
if error != nil { | |
print(error!.localizedDescription) | |
complete(instance: nil, error: error) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extension Int { | |
static func random(max: Int) -> Int { | |
let rnd = Int(arc4random_uniform(UInt32(max) + 1)) | |
return rnd | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// returns a random int within given range | |
func randomInt(from: Int, to: Int) -> Int { | |
let range = UInt32(to - from) | |
let rndInt = Int(arc4random_uniform(range + 1)) + from | |
return rndInt | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// returns a random color | |
func randomColor() -> UIColor{ | |
let red = CGFloat(drand48()) | |
let green = CGFloat(drand48()) | |
let blue = CGFloat(drand48()) | |
return UIColor(red: red, green: green, blue: blue, alpha: 1.0) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// returns a random email as string | |
func randomEmail() -> String { | |
let nameLength = randomInt(5, to: 10) | |
let domainLength = randomInt(5, to: 10) | |
let domainSuffixes = ["com", "net", "org", "io", "co.uk"] | |
let name = randomText(nameLength, justLowerCase: true) | |
let domain = randomText(domainLength, justLowerCase: true) | |
let randomDomainSuffixIndex = Int(arc4random_uniform(UInt32(domainSuffixes.count))) | |
let domainSuffix = domainSuffixes[randomDomainSuffixIndex] | |
let text = name + "@" + domain + "." + domainSuffix |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// returns random text of a defined length | |
// optional bool parameter justLowerCase | |
// to just generate random lowercase text | |
func randomText(length: Int, justLowerCase: Bool = false) -> String { | |
var text = "" | |
for _ in 1...length { | |
var decValue = 0 // ascii decimal value of a character | |
var charType = 3 // default is lowercase | |
if justLowerCase == false { | |
// randomize the character type |