Skip to content

Instantly share code, notes, and snippets.

@burhanaksendir
burhanaksendir / remoteFileExists
Created June 23, 2015 02:31
How to check if a remote file exists in Swift ?
func remoteFileExists(url: String) -> Bool {
var exists: Bool = false
let url: NSURL = NSURL(string: url)!
var request: NSMutableURLRequest = NSMutableURLRequest(URL: url)
request.HTTPMethod = "HEAD"
var response: NSURLResponse?
NSURLConnection.sendSynchronousRequest(request, returningResponse: &response , error: nil)
@burhanaksendir
burhanaksendir / gist:2e84877396670533a5ba
Last active August 29, 2015 14:23
Main View Controller
override func viewDidLoad() {
super.viewDidLoad()
NSNotificationCenter.defaultCenter().addObserver(self, selector: "remoteNotificationReceiveAction:", name: "remoteNotificationReceived", object: nil)
}
func remoteNotificationReceiveAction(data: NSNotification) {
if let apsPayloadContent: AnyObject = data.userInfo as? AnyObject {
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
// Parse initialization
Parse.setApplicationId(“xxxxxxxxxxxxxxxx", clientKey: “xxxxxxxxxxxxx")
let types = UIUserNotificationType.Badge | UIUserNotificationType.Alert | UIUserNotificationType.Sound
let settings = UIUserNotificationSettings(forTypes: types, categories: nil)
application.registerUserNotificationSettings(settings)
return true
//declare closure outsize class definition (above class definition)
typealias CompletionHandler = (success:Bool!) -> Void
//declare library variable inside class
var library:ALAssetsLibrary?
//initialize variable in viewDidLoad
library = ALAssetsLibrary();
@IBAction func shareFacebook(sender: AnyObject) {
if SLComposeViewController.isAvailableForServiceType(SLServiceTypeFacebook){
var facebookSheet: SLComposeViewController = SLComposeViewController(forServiceType: SLServiceTypeFacebook)
facebookSheet.setInitialText("Demo")
self.presentViewController(facebookSheet, animated: true, completion: nil)
} else {
@burhanaksendir
burhanaksendir / gist:ab01fbe778e519532bff
Created May 27, 2015 12:07
SplashScreen animation in Swift
//
// SplashViewController.swift
// splashAnimation
//
// Created by Burhan Aksendir on 26.03.2015.
// Copyright (c) 2015 Aksendir. All rights reserved.
//
import UIKit
@burhanaksendir
burhanaksendir / gist:4832b818cd1a08181220
Created December 14, 2014 21:13
Flex Mobile : CheckBox iconItemRenderer
<?xml version="1.0" encoding="utf-8"?>
<s:IconItemRenderer xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark">
<fx:Metadata>
[Event(name="checkBoxIconItemRendererChanged", type="flash.events.Event")]
</fx:Metadata>
<fx:Script>
<![CDATA[
import spark.components.CheckBox;
@burhanaksendir
burhanaksendir / gist:8544fbe00598a1e8d7a4
Created December 14, 2014 21:11
Flex Mobile Spark List View
<?xml version="1.0" encoding="utf-8"?>
<s:View xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
creationComplete="view1_creationCompleteHandler(event)" xmlns:views="views.*"
>
<fx:Script>
<![CDATA[
import mx.collections.ArrayCollection;
import mx.events.FlexEvent;
[Bindable]