Skip to content

Instantly share code, notes, and snippets.

View Gernot's full-sized avatar

Gernot Poetsch Gernot

View GitHub Profile
public struct Time {
init(date: NSDate) {
NSCalendar.currentCalendar().getHour(&hours, minute: &minutes, second: &seconds, nanosecond: &nanoseconds, fromDate: date)
}
private(set) public var hours: Int = 0
private(set) public var minutes: Int = 0
private(set) public var seconds: Int = 0
private(set) public var nanoseconds: Int = 0
struct Time {
/* Is there any good way to do this without the intermediate vars? Swift 1.2 (Xcode 6.3b4) does not seem to let me write into the structs constants directly before initializing them. */
init(date: NSDate) {
var hour: Int = 0, minute: Int = 0, second: Int = 0, nanosecond: Int = 0
NSCalendar.currentCalendar().getHour(&hour, minute: &minute, second: &second, nanosecond: &nanosecond, fromDate: date)
self.hour = hour; self. minute = minute; self.second = second; self.nanosecond = nanosecond
}
let hour: Int
@Gernot
Gernot / Swift-Workshop.md
Created November 25, 2014 14:02
Swift Workshop
extension NSURL {
convenience init?(optionalString: String?) {
if (optionalString == nil) {
self.init() //Yeah, this makes sense. Go on, try deleting it. Compiler will complain… (At least in Xcode 6.1)
return nil
}
self.init(string:optionalString!)
}
}
@Gernot
Gernot / gist:1206389
Created September 9, 2011 14:35
ARC + Analyzer
+ (NSString *)nx_stringWithUUID;
{
CFUUIDRef theUUID = CFUUIDCreate(kCFAllocatorDefault);
CFStringRef string = CFUUIDCreateString(kCFAllocatorDefault, theUUID);
CFRelease(theUUID);
NSString *returnValue = (__bridge_transfer NSString*)string;
return returnValue;
/*
From e73676528a86527149063b03882b58ca84e3958d Mon Sep 17 00:00:00 2001
From: Gernot Poetsch <[email protected]>
Date: Wed, 17 Aug 2011 15:39:48 +0200
Subject: [PATCH] Increasing LastUpgradeCheck to please THE STEVE
---
SoundCloudUI.xcodeproj/project.pbxproj | 1 +
1 files changed, 1 insertions(+), 0 deletions(-)
diff --git a/SoundCloudUI.xcodeproj/project.pbxproj b/SoundCloudUI.xcodeproj/project.pbxproj
NSDictionary *testDict = [NSDictionary dictionary];
NSMutableDictionary *mutableTestDict = [NSMutableDictionary dictionary];
if ([testDict isKindOfClass:[NSDictionary class]]
&& ![testDict isKindOfClass:[NSMutableDictionary class]] //notice the negation here!
&& [mutableTestDict isKindOfClass:[NSDictionary class]]
&& [mutableTestDict isKindOfClass:[NSMutableDictionary class]])
{
NSLog(@"Hey Christian, klappt doch!");
}