Skip to content

Instantly share code, notes, and snippets.

//matches route https://BASEURL/users/67 but not https://BASEURL/users/H67p
drop.get("users", Int.self) { request, userId in
return "You requested User #\(userId)"
}
//matches route https://BASEURL/players/67 if there is a persisted User in Database with id==67
import PackageDescription
let package = Package(
name: "DockerSwiftBackend",
dependencies: [
.Package(url: "https://github.com/necolt/Swifton.git", Version(0,0,5)),
.Package(url: "https://github.com/necolt/Curassow.git", versions: Version(0,4,0)..<Version(1,0,0)),
.Package(url: "git@GIT_REPO_URL_TO_SHAREDCODE", versions: Version(0,0,9)..<Version(1,0,0)),
]
)
import Inquiline
import Swifton
import SharedCode
class LoginController: Controller {
override init() {
super.init()
action("login") {request in
import Swifton
import Curassow
let router = Router()
router.post("/login", LoginController() ["login"])
serve { router.respond($0) }
func performRequestWithUsername(username: String, password: String) {
let loginRequest = LoginRequest(userId: username, password: password)
let json = loginRequest.toJSON()
let urlRequest = NSMutableURLRequest( URL: NSURL(string: "https://SWIFT-WEBSERVICE-URL/login")!,
cachePolicy: .ReloadIgnoringLocalCacheData,
timeoutInterval: 60)
urlRequest.HTTPMethod = "POST"
urlRequest.setValue("application/json", forHTTPHeaderField: "Content-Type")
urlRequest.HTTPBody = try? json.rawData()
import PackageDescription
let package = Package(
name: "SharedCode",
targets: [ ],
dependencies: [ ]
)
import Foundation
public class LoginResponse {
public var text: String = ""
public init (text: String) {
self.text = text
}
import Foundation
public class LoginRequest {
public var userId: String = ""
public var password: String = ""
public init(userId: String, password: String) {
self.userId = userId
self.password = password
@flandy84
flandy84 / gist:3183844
Created July 26, 2012 19:05
"modern Objective-C" syntax
//"modern Objective-C" syntax
//new enum-macros for better autocompletion, switch statement, more precise warnings, ...
typedef NS_ENUM(NSInteger, MyViewContentMode) {
MyViewContentModeLeft,
MyViewContentModeRight,
MyViewContentModeTopLeft,
MyViewContentModeTopRight,
@flandy84
flandy84 / gist:2003852
Created March 8, 2012 22:24
iOS "skip backup" file/directory flag since ios 5.1
- (BOOL)addSkipBackupAttributeToItemAtURL:(NSURL *)URL{
return [URL setResourceValue:[NSNumber numberWithBool:YES] forKey:NSURLIsExcludedFromBackupKey error:nil];
}