-
Notifications
You must be signed in to change notification settings - Fork 419
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #55 from rjburdish/master
Added Swift version of LikedOrNope called SwiftLikedOrNope
- Loading branch information
Showing
17 changed files
with
1,445 additions
and
0 deletions.
There are no files selected for viewing
542 changes: 542 additions & 0 deletions
542
Examples/SwiftLikedOrNope/SwiftLikedOrNope.xcodeproj/project.pbxproj
Large diffs are not rendered by default.
Oops, something went wrong.
7 changes: 7 additions & 0 deletions
7
.../SwiftLikedOrNope/SwiftLikedOrNope.xcodeproj/project.xcworkspace/contents.xcworkspacedata
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
111 changes: 111 additions & 0 deletions
111
Examples/SwiftLikedOrNope/SwiftLikedOrNope/AppDelegate.swift
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
// | ||
// AppDelegate.swift | ||
// SwiftLikedOrNope | ||
// | ||
// Created by richard burdish on 3/28/15. | ||
// Copyright (c) 2015 Richard Burdish. All rights reserved. | ||
// | ||
|
||
import UIKit | ||
import CoreData | ||
|
||
@UIApplicationMain | ||
class AppDelegate: UIResponder, UIApplicationDelegate { | ||
|
||
var window: UIWindow? | ||
|
||
|
||
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool { | ||
// Override point for customization after application launch. | ||
return true | ||
} | ||
|
||
func applicationWillResignActive(application: UIApplication) { | ||
// Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state. | ||
// Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game. | ||
} | ||
|
||
func applicationDidEnterBackground(application: UIApplication) { | ||
// Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. | ||
// If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. | ||
} | ||
|
||
func applicationWillEnterForeground(application: UIApplication) { | ||
// Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background. | ||
} | ||
|
||
func applicationDidBecomeActive(application: UIApplication) { | ||
// Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface. | ||
} | ||
|
||
func applicationWillTerminate(application: UIApplication) { | ||
// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. | ||
// Saves changes in the application's managed object context before the application terminates. | ||
self.saveContext() | ||
} | ||
|
||
// MARK: - Core Data stack | ||
|
||
lazy var applicationDocumentsDirectory: NSURL = { | ||
// The directory the application uses to store the Core Data store file. This code uses a directory named "MDCSwipeToChoose.SwiftLikedOrNope" in the application's documents Application Support directory. | ||
let urls = NSFileManager.defaultManager().URLsForDirectory(.DocumentDirectory, inDomains: .UserDomainMask) | ||
return urls[urls.count-1] as NSURL | ||
}() | ||
|
||
lazy var managedObjectModel: NSManagedObjectModel = { | ||
// The managed object model for the application. This property is not optional. It is a fatal error for the application not to be able to find and load its model. | ||
let modelURL = NSBundle.mainBundle().URLForResource("SwiftLikedOrNope", withExtension: "momd")! | ||
return NSManagedObjectModel(contentsOfURL: modelURL)! | ||
}() | ||
|
||
lazy var persistentStoreCoordinator: NSPersistentStoreCoordinator? = { | ||
// The persistent store coordinator for the application. This implementation creates and return a coordinator, having added the store for the application to it. This property is optional since there are legitimate error conditions that could cause the creation of the store to fail. | ||
// Create the coordinator and store | ||
var coordinator: NSPersistentStoreCoordinator? = NSPersistentStoreCoordinator(managedObjectModel: self.managedObjectModel) | ||
let url = self.applicationDocumentsDirectory.URLByAppendingPathComponent("SwiftLikedOrNope.sqlite") | ||
var error: NSError? = nil | ||
var failureReason = "There was an error creating or loading the application's saved data." | ||
if coordinator!.addPersistentStoreWithType(NSSQLiteStoreType, configuration: nil, URL: url, options: nil, error: &error) == nil { | ||
coordinator = nil | ||
// Report any error we got. | ||
var dict = [String: AnyObject]() | ||
dict[NSLocalizedDescriptionKey] = "Failed to initialize the application's saved data" | ||
dict[NSLocalizedFailureReasonErrorKey] = failureReason | ||
dict[NSUnderlyingErrorKey] = error | ||
error = NSError(domain: "YOUR_ERROR_DOMAIN", code: 9999, userInfo: dict) | ||
// Replace this with code to handle the error appropriately. | ||
// abort() causes the application to generate a crash log and terminate. You should not use this function in a shipping application, although it may be useful during development. | ||
NSLog("Unresolved error \(error), \(error!.userInfo)") | ||
abort() | ||
} | ||
|
||
return coordinator | ||
}() | ||
|
||
lazy var managedObjectContext: NSManagedObjectContext? = { | ||
// Returns the managed object context for the application (which is already bound to the persistent store coordinator for the application.) This property is optional since there are legitimate error conditions that could cause the creation of the context to fail. | ||
let coordinator = self.persistentStoreCoordinator | ||
if coordinator == nil { | ||
return nil | ||
} | ||
var managedObjectContext = NSManagedObjectContext() | ||
managedObjectContext.persistentStoreCoordinator = coordinator | ||
return managedObjectContext | ||
}() | ||
|
||
// MARK: - Core Data Saving support | ||
|
||
func saveContext () { | ||
if let moc = self.managedObjectContext { | ||
var error: NSError? = nil | ||
if moc.hasChanges && !moc.save(&error) { | ||
// Replace this implementation with code to handle the error appropriately. | ||
// abort() causes the application to generate a crash log and terminate. You should not use this function in a shipping application, although it may be useful during development. | ||
NSLog("Unresolved error \(error), \(error!.userInfo)") | ||
abort() | ||
} | ||
} | ||
} | ||
|
||
} | ||
|
41 changes: 41 additions & 0 deletions
41
Examples/SwiftLikedOrNope/SwiftLikedOrNope/Base.lproj/LaunchScreen.xib
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
<?xml version="1.0" encoding="UTF-8" standalone="no"?> | ||
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="6214" systemVersion="14A314h" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" launchScreen="YES" useTraitCollections="YES"> | ||
<dependencies> | ||
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="6207"/> | ||
<capability name="Constraints with non-1.0 multipliers" minToolsVersion="5.1"/> | ||
</dependencies> | ||
<objects> | ||
<placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner"/> | ||
<placeholder placeholderIdentifier="IBFirstResponder" id="-2" customClass="UIResponder"/> | ||
<view contentMode="scaleToFill" id="iN0-l3-epB"> | ||
<rect key="frame" x="0.0" y="0.0" width="480" height="480"/> | ||
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/> | ||
<subviews> | ||
<label opaque="NO" clipsSubviews="YES" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text=" Copyright (c) 2015 Richard Burdish. All rights reserved." textAlignment="center" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" minimumFontSize="9" translatesAutoresizingMaskIntoConstraints="NO" id="8ie-xW-0ye"> | ||
<rect key="frame" x="20" y="439" width="441" height="21"/> | ||
<fontDescription key="fontDescription" type="system" pointSize="17"/> | ||
<color key="textColor" cocoaTouchSystemColor="darkTextColor"/> | ||
<nil key="highlightedColor"/> | ||
</label> | ||
<label opaque="NO" clipsSubviews="YES" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="SwiftLikedOrNope" textAlignment="center" lineBreakMode="middleTruncation" baselineAdjustment="alignBaselines" minimumFontSize="18" translatesAutoresizingMaskIntoConstraints="NO" id="kId-c2-rCX"> | ||
<rect key="frame" x="20" y="140" width="441" height="43"/> | ||
<fontDescription key="fontDescription" type="boldSystem" pointSize="36"/> | ||
<color key="textColor" cocoaTouchSystemColor="darkTextColor"/> | ||
<nil key="highlightedColor"/> | ||
</label> | ||
</subviews> | ||
<color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="calibratedWhite"/> | ||
<constraints> | ||
<constraint firstItem="kId-c2-rCX" firstAttribute="centerY" secondItem="iN0-l3-epB" secondAttribute="bottom" multiplier="1/3" constant="1" id="5cJ-9S-tgC"/> | ||
<constraint firstAttribute="centerX" secondItem="kId-c2-rCX" secondAttribute="centerX" id="Koa-jz-hwk"/> | ||
<constraint firstAttribute="bottom" secondItem="8ie-xW-0ye" secondAttribute="bottom" constant="20" id="Kzo-t9-V3l"/> | ||
<constraint firstItem="8ie-xW-0ye" firstAttribute="leading" secondItem="iN0-l3-epB" secondAttribute="leading" constant="20" symbolic="YES" id="MfP-vx-nX0"/> | ||
<constraint firstAttribute="centerX" secondItem="8ie-xW-0ye" secondAttribute="centerX" id="ZEH-qu-HZ9"/> | ||
<constraint firstItem="kId-c2-rCX" firstAttribute="leading" secondItem="iN0-l3-epB" secondAttribute="leading" constant="20" symbolic="YES" id="fvb-Df-36g"/> | ||
</constraints> | ||
<nil key="simulatedStatusBarMetrics"/> | ||
<freeformSimulatedSizeMetrics key="simulatedDestinationMetrics"/> | ||
<point key="canvasLocation" x="548" y="455"/> | ||
</view> | ||
</objects> | ||
</document> |
25 changes: 25 additions & 0 deletions
25
Examples/SwiftLikedOrNope/SwiftLikedOrNope/Base.lproj/Main.storyboard
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<?xml version="1.0" encoding="UTF-8" standalone="no"?> | ||
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="6751" systemVersion="14B25" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" initialViewController="BYZ-38-t0r"> | ||
<dependencies> | ||
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="6736"/> | ||
</dependencies> | ||
<scenes> | ||
<!--Choose Person View Controller--> | ||
<scene sceneID="tne-QT-ifu"> | ||
<objects> | ||
<viewController id="BYZ-38-t0r" customClass="ChoosePersonViewController" customModule="SwiftLikedOrNope" customModuleProvider="target" sceneMemberID="viewController"> | ||
<layoutGuides> | ||
<viewControllerLayoutGuide type="top" id="y3c-jy-aDJ"/> | ||
<viewControllerLayoutGuide type="bottom" id="wfy-db-euE"/> | ||
</layoutGuides> | ||
<view key="view" contentMode="scaleToFill" id="8bC-Xf-vdC"> | ||
<rect key="frame" x="0.0" y="0.0" width="600" height="600"/> | ||
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/> | ||
<color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="calibratedWhite"/> | ||
</view> | ||
</viewController> | ||
<placeholder placeholderIdentifier="IBFirstResponder" id="dkx-z0-nzr" sceneMemberID="firstResponder"/> | ||
</objects> | ||
</scene> | ||
</scenes> | ||
</document> |
34 changes: 34 additions & 0 deletions
34
Examples/SwiftLikedOrNope/SwiftLikedOrNope/BridgingHeader.h
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
// | ||
// BridgingHeader.h | ||
// SwiftLikedOrNope | ||
// | ||
// Copyright (c) 2014 to present, Richard Burdish @rjburdish | ||
// | ||
// 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 USE OR OTHER DEALINGS IN | ||
// THE SOFTWARE. | ||
// | ||
|
||
|
||
#ifndef SwiftLikedOrNope_BridgingHeader_h | ||
#define SwiftLikedOrNope_BridgingHeader_h | ||
|
||
|
||
#import <UIKit/UIKit.h> | ||
#import <MDCSwipeToChoose/MDCSwipeToChoose.h> | ||
|
||
#endif |
109 changes: 109 additions & 0 deletions
109
Examples/SwiftLikedOrNope/SwiftLikedOrNope/ChoosePersonView.swift
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
// | ||
// ChoosePersonView.swift | ||
// SwiftLikedOrNope | ||
// | ||
// Copyright (c) 2014 to present, Richard Burdish @rjburdish | ||
// | ||
// 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 USE OR OTHER DEALINGS IN | ||
// THE SOFTWARE. | ||
// | ||
|
||
import UIKit | ||
|
||
class ChoosePersonView: MDCSwipeToChooseView { | ||
|
||
let ChoosePersonViewImageLabelWidth:CGFloat = 42.0; | ||
var person: Person! | ||
var informationView: UIView! | ||
var nameLabel: UILabel! | ||
var carmeraImageLabelView:ImagelabelView! | ||
var interestsImageLabelView: ImagelabelView! | ||
var friendsImageLabelView: ImagelabelView! | ||
|
||
init(frame: CGRect, person: Person, options: MDCSwipeToChooseViewOptions) { | ||
|
||
super.init(frame: frame, options: options) | ||
self.person = person | ||
|
||
self.imageView.image = self.person.Image! | ||
self.autoresizingMask = UIViewAutoresizing.FlexibleHeight | UIViewAutoresizing.FlexibleWidth | ||
UIViewAutoresizing.FlexibleBottomMargin | ||
|
||
self.imageView.autoresizingMask = self.autoresizingMask | ||
constructInformationView() | ||
} | ||
|
||
required init(coder aDecoder: NSCoder) { | ||
super.init(coder: aDecoder) | ||
} | ||
|
||
func constructInformationView() -> Void{ | ||
var bottomHeight:CGFloat = 60.0 | ||
var bottomFrame:CGRect = CGRectMake(0, | ||
CGRectGetHeight(self.bounds) - bottomHeight, | ||
CGRectGetWidth(self.bounds), | ||
bottomHeight); | ||
self.informationView = UIView(frame:bottomFrame) | ||
self.informationView.backgroundColor = UIColor.whiteColor() | ||
self.informationView.clipsToBounds = true | ||
self.informationView.autoresizingMask = UIViewAutoresizing.FlexibleWidth | UIViewAutoresizing.FlexibleTopMargin | ||
self.addSubview(self.informationView) | ||
constructNameLabel() | ||
constructCameraImageLabelView() | ||
constructInterestsImageLabelView() | ||
constructFriendsImageLabelView() | ||
} | ||
|
||
func constructNameLabel() -> Void{ | ||
var leftPadding:CGFloat = 12.0 | ||
var topPadding:CGFloat = 17.0 | ||
var frame:CGRect = CGRectMake(leftPadding, | ||
topPadding, | ||
floor(CGRectGetWidth(self.informationView.frame)/2), | ||
CGRectGetHeight(self.informationView.frame) - topPadding) | ||
self.nameLabel = UILabel(frame:frame) | ||
self.nameLabel.text = "\(person.Name), \(person.Age)" | ||
self.informationView .addSubview(self.nameLabel) | ||
} | ||
func constructCameraImageLabelView() -> Void{ | ||
var rightPadding:CGFloat = 10.0 | ||
var image:UIImage = UIImage(named:"camera")! | ||
self.carmeraImageLabelView = buildImageLabelViewLeftOf(CGRectGetWidth(self.informationView.bounds), image:image, text:person.NumberOfPhotos.stringValue) | ||
self.informationView.addSubview(self.carmeraImageLabelView) | ||
} | ||
func constructInterestsImageLabelView() -> Void{ | ||
var image: UIImage = UIImage(named: "book")! | ||
self.interestsImageLabelView = self.buildImageLabelViewLeftOf(CGRectGetMinX(self.carmeraImageLabelView.frame), image: image, text:person.NumberOfPhotos.stringValue) | ||
self.informationView.addSubview(self.interestsImageLabelView) | ||
} | ||
|
||
func constructFriendsImageLabelView() -> Void{ | ||
var image:UIImage = UIImage(named:"group")! | ||
self.friendsImageLabelView = buildImageLabelViewLeftOf(CGRectGetMinX(self.interestsImageLabelView.frame), image:image, text:"No Friends") | ||
self.informationView.addSubview(self.friendsImageLabelView) | ||
} | ||
|
||
func buildImageLabelViewLeftOf(x:CGFloat, image:UIImage, text:NSString) -> ImagelabelView{ | ||
var frame:CGRect = CGRect(x:x-ChoosePersonViewImageLabelWidth, y: 0, | ||
width: ChoosePersonViewImageLabelWidth, | ||
height: CGRectGetHeight(self.informationView.bounds)) | ||
var view:ImagelabelView = ImagelabelView(frame:frame, image:image, text:text) | ||
view.autoresizingMask = UIViewAutoresizing.FlexibleLeftMargin | ||
return view | ||
} | ||
} |
Oops, something went wrong.