Guide to Reference

ARC is a compile time feature that is Apple’s version of automated memory management. It stands for Automatic Reference Counting. This means that it only frees up memory for objects when there are zero strong references/ to them.

A guide to reference: when to use Strong reference, Weak reference, Unowned reference, ImplicitlyUnwrappedOptional property

  Optional non-Optional
Optional strong reference &

weak reference

 strong reference &

unowned reference

non-Optional strong reference &

unowned reference

 unowned reference &

implicitly unwrapped optional property

Extension

extension String {

func toFloat() -> Float {

if let unwrappedNum = Float(self) {

return unwrappedNum

}

else {

print(“Error converting \”” + self + “\” to Float”)

return 0.0

}

}

}

// Double to String with Format

var text = String.localizedStringWithFormat(“%.2f”, doubleValue)

// String to Float/Double

var floatValue = text.toFloat()

Term Project1

Design of Portable Multimedia Devices (448460)
– iOS CampusLife AR Application –
Fall 2016
Kyoung Shin Park
October 4, 2016

 

Term Project

Term Project 1 – 조별 학교생활 AR 어플 제안서

Term Project 2 – 조별 학교생활 AR 어플에 대한 측정요소

Term Project 3 – 조별 학교생활 AR 어플 진행보고서

Term Project 4 – 조별 학교생활 AR 어플 최종보고서

TemperatureConverter

// ConverterType
enum ConverterType : Int, CustomStringConvertible {
case FA_TO_CE = 1
case CE_TO_FA = 2
init(_ name: String) {
switch name {
case “FA_TO_CE”, “1”: self = .FA_TO_CE
case “CE_TO_FA”, “2”: self = .CE_TO_FA
default: self = .CE_TO_FA
}
}
var description: String {
switch self {
case .FA_TO_CE: return “FA_TO_CE”
case .CE_TO_FA: return “CE_TO_FA”
}
}
static func enumerate() -> AnyGenerator {
var nextIndex = FA_TO_CE.rawValue
return anyGenerator { ConverterType(rawVale: nextIndex++) }

}
}

// Converter
protocol Converter : CustomStringConvertible {
var description : String { get }
var type : ConverterType { get }
var fahrenheit : Double { get }
var celsius : Double { get }
}

// FahrenheitToCelsius
class FahrenheitToCelsius : Converter {
var temperature = 0.0

convenience init() {
self.init(temperature: 0.0)
}

init(temperature: Double) {
self.temperature = temperature
}

var description : String {
return “Converter=\(type.description) F=\(fahrenheit) => C=\(celsius)”
}
var type : ConverterType {
return ConverterType.FA_TO_CE
}

var fahrenheit : Double {
return self.temperature
}

var celsius : Double {
return (temperature – 32.0) * (5.0 / 9.0)
}
}

// CelsiusToFahrenheit
class CelsiusToFahrenheit : Converter {
var temperature = 0.0

convenience init() {
self.init(temperature: 0.0)
}

init(temperature: Double) {
self.temperature = temperature
}

var description : String {
return “Converter=\(type.description) C=\(celsius) => F=\(fahrenheit)”
}
var type : ConverterType {
return ConverterType.CE_TO_FA
}

var fahrenheit : Double {
return ((9.0/5.0) * temperature + 32.0)
}

var celsius : Double {
return self.temperature
}
}

// TemperatureConverter
class TemperatureConverter {

func getUserInputDouble() -> Double {
var value : Double
while true {
if let inputSeting = readLine() {
if let inputNumber = Double(inputString) {
value = inputNumber
return value
}
else {
print(“Error! Please re-enter Double value”)
}
}
}
}

func convert(mode: ConverterType) {
if (mode == ConverterType.FA_TO_CE) {
print(“Please enter temperature (F) : “)
let converter = FahrenheitToCelsius(temperature: getUserInputDouble())
print(converter.description)
}
else if (mode == ConverterType.CE_TO_FA) {
print(“Please enter temperature (C) : “)
let converter = CelsiusToFahrenheit(temperature: getUserInputDouble())
print(converter.description)
}
}

func getUserInputConverterType() -> ConverterType {
var i = 0
let g = ConvertType.FA_TO_CE
repeat {
print(“Please select converter type (1 or 2):”)
if let inputString = readLine() {
if let inputNumber = Int(inputString) {
i = inputNumber
if let c = ConverterType(rawValue: i) {
return c
}
}
}
} while i < 1 || i > 2
return g
}

func calculateAll() {
for i in 1…2 {
convert(ConverterType(rawValue: i)!)
}

for c in ConverterType.enumerate() {
convert(c)
}

var convertList = [Converter]()
convertList.append(FahrenheitToCelsius(temperature: 75.5))
convertList.append(CelsiusToFahrenheit(temperature: 25.5))
for c in convertList {
print(c.description)
}

convert(getUserInputConverterType())
}
}

Individual Assignment 2

– “LBS-based Mobile Augmented Reality” survey

Fall 2016

Kyoung Shin Park

September 20, 2016

 

Individual assignment – “LBS-based Mobile Augmented Reality” survey report (10 points)

 

With the advances in mobile devices and technologies that combine the real world with virtual information, augmented reality applications are as near to hand as any other application on a smart phone. Mobile AR application allows users to get experience interacting with virtual people/objects in the physical world using their mobile devices.

The goal of this assignment is for you to learn the key design aspect of augmented reality applications/games on a mobile phone, and think about how to design if you would create your own Mobile AR application.

In this assignment, you are to research 2~3 subjects of your interest on Mobile Augmented Reality Applications from the web sites given below and then summit the report (3-page) on Mobile AR technology survey, due by Sep 27th, 2016.

 

Reference:

 

Layar, worlds first mobile augmented reality browser on mobile
http://www.youtube.com/watch?v=b64_16K2e08

 

 

Wikitude AR Travel Guide
http://www.youtube.com/watch?v=8EA8xlicmT8&feature=related

 

Metaio Augmented Vision
http://venturebeat.com/2009/08/04/metaio-launches-augmented-reality-platform-for-mobile-sharing-marketing/

 

Nearest Tube Augmented Reality App for iPhone 3GS from acrossair
http://www.youtube.com/watch?v=U2uH-jrsSxs&feature=related

 

 

Sekai Camera
http://www.youtube.com/watch?v=XcdHGPnVUHU

 

iBufferfly = AR + GIS + Motion Sensor + Coupon
http://www.mobileart.jp/ibutterfly_en.html

Twitter Feed on an Augmented Reality Building
http://www.youtube.com/watch?v=n1ANVCDHYA4&feature=player_embedded

CES: Battling AR helicopter controlled by iPhone
http://www.youtube.com/watch?v=TSv2ca-IECc&NR=1&feature=fvwp

 

AR! Pirates – Augmented Reality Mobile Game
http://www.youtube.com/watch?v=al7StPimtRs

 

 

ARhrrrr – An Augmented Reality Shooter
http://www.youtube.com/watch?v=cNu4CluFOcw&feature=player_embedded

 

 

ARIS Mobile Media Learning Games
http://arisgames.org

 

 

Kweekies – mobile augmented reality game by int13 (IMGAwards demo)http://www.youtube.com/watch?v=Te9gj22M_aU&feature=related

 

 

Mobile AR Cooking Game “PAN MASTER”
http://www.youtube.com/watch?v=JuzVH7loGvo

 

 

Mobile AR Networking Game “AR FIGHTER”
http://www.youtube.com/watch?v=tGc6J7qDsGo&feature=related

 

 

Tagdis: The Virtual graffiti game you play in the real world
http://tagdis.com/

 

 

Art of Defense: a Mobile AR Game with Sketch-Based Interaction and Dynamic Multi-Marker Building Techniques
http://www.augmentedenvironments.org/lab/research/handheld-ar/artofdefense/

 

 

Mirror Worlds
http://www.augmentedenvironments.org/lab/2009/10/

DataStructureTest

//: Playground – noun: a place where people can play

// DataStructure (function, optional, enum, class, inheritance, struct)

// Kyoung Shin Park (2016 Fall)

import Cocoa

// function

func sayHello(personName: String = “World”) -> String {

let greeting = “Hello, ” + personName + “!”

return greeting

}

var delegate = sayHello()

print(sayHello())

print(sayHello(“Anna”))

print(delegate)

// Optional & Forced unwrapping & Optional binding

let planets = [“Mercury”:1, “Venus”:2, “Earth”:3] // assign dictionary

let planetID: Int? = planets[“Earth”]

if planetID != nil { // check if planetID is nil to prevent run-time error

print(“Earth = \(planetID!)”) // Forced unwrapping (using !) Earth = 3

} else {

print(“Earth is not found”)

}

// Optional binding (unwrapping an optional)

if let planetID = planets[“Earth”] { // return true if planetID has valid value

print(“Earth = \(planetID)”)       // Earth = 3

}

// ImplicitlyUnwrappedOptional

var w: Int! = 1 // same as var w: ImplicitlyUnwrappedOptional<Int> = 1

print(w) // you don’t need to put !

var z: Int! // same as var z: ImplicitlyUnwrappedOptional<Int> = nil

//print(z) // RUN-TIME ERROR (because z is nil)

w = nil // OK

//print(w) // RUN-TIME ERROR (because w is nil) while unwrapping

// Nil coalescing operator

let defaultColorName = “Red”

var userDefinedColorName: String? // set to nil

// colorNameToUse = “Red” (because userDefinedColorName = nil)

var colorNameToUse = userDefinedColorName ?? defaultColorName

// if planets[“Earth”] = nil then it will return the default value 0)

var ID : Int? = planets[“Earth”] ?? 0 // var earthID: Int? = 3

// Optional chaining

class Person {

var contact: Contact? // automatically set to nil

}

class Contact {

var address: String? // automatically set to nil

var telephone: String? // automatically set to nil

}

let p = Person()

//var phone = p.contact!.telephone! // run-time error(because contact=nil)

if let contact = p.contact { // optional binding to read optional property

if let phone = contact.telephone {

print(phone)

} else {

print(“phone is nil”)

}

} else {

print(“contact is nil”)

}

// optional chaining

var phone = p.contact?.telephone // phone=nil (because contact=nil)

print(phone)

// use optional chaining & optional binding together

p.contact = Contact()

p.contact?.telephone = “12345”

if let phone = p.contact?.telephone {

print(p.contact?.telephone)

}

// Enumeration

enum Gender {

case Female

case Male

init() { // initialization

self = .Female

}

init(_ name: String)

{

switch name {

case “Female”, “여자”: self = .Female

case “Male”, “남자”: self = .Male

default: self = .Female

}

}

var description: String {

switch self {

case .Female: return “FEMALE~”

case .Male: return “MALE~”

}

}

}

var gender = Gender()

print(gender.description)

gender = Gender(“남자”)

print(gender.description)

gender = Gender.Female

gender = .Male

print(Gender.Male.description)

switch gender {

case .Female: print(“FEMALE!!”)

case .Male: print(“MALE!!”)

}

// Enum, multiple member values can appear on a single line, separated by commas

// Enum rawValue

enum Planet: Int {

case Mercury=1, Venus, Earth, Mars, Jupiter, Saturn, Uranus, Neptune

}

let earthID = Planet.Earth.rawValue

let somePlanet = Planet.Earth

switch somePlanet {

case .Earth:

print(“Mostly harmless”)

default:

print(“Not a safe place for humans”)

}

let aPlanet = Planet(rawValue: 7)

switch aPlanet! {

case .Earth:

print(“Mostly harmless”)

default:

print(“Not a safe place for humans”)

}

if let possiblePlanet = Planet(rawValue: 9) {

switch possiblePlanet {

case .Earth:

print(“Mostly harmless”)

default:

print(“Not a safe place for humans”)

}

} else {

print(“There isn’t a planet at position 9”)

}

// Enum associated values

enum TrainStatus {

case OnTime

case Delayed(Int)

}

var status:TrainStatus = .Delayed(5)

status = .OnTime

switch status {

case .OnTime:

print(“Train is on time”)

case .Delayed(let minutes):

print(“Train is delayed by \(minutes) minutes”)

}

// class

class Vehicle {

// stored properties

var numberOfPassengers: Int = 2

var numberOfWheels: Int = 4

 

// computed properties

var NumberOfWheels: Int {

get { return numberOfWheels }

set { numberOfWheels = newValue }

}

var description: String {

return “\(numberOfWheels) number of wheels”

}

}

class Bicycle: Vehicle {

override init() {

super.init()

numberOfPassengers = 1

numberOfWheels = 2

}

}

class Car: Vehicle {

// stored properties

var minVelocity: Int = 30

var accelVelocity: Int = 10

// computed properties

var speed: Int {

get {

return minVelocity + accelVelocity

}

set(newVelocity) {

accelVelocity = newVelocity – minVelocity

}

}

}

// struct

struct Frame {

var x: Int, y: Int // stored property

var width: Int, height: Int // stored property

var area: Int { // computed property (don’t need to enclose getter)

return width * height

}

mutating func addWidth(width: Int) {// method

self.width += width // mutating modifies the value of a stored property

}

}

let f = Frame(x: 5, y: 10, width: 100, height: 100) // member-wise initializer

//f.width = 250 // invalid (can’t change the struct properties stored in a let)

var g = Frame(x: 5, y: 10, width: 100, height: 100)

g.addWidth(15) // use mutating func to modify the value of a stored property

print(g.width) // 15

let h = Frame(x: 5, y: 10, width: 100, height: 100)

//h.addWidth(15) // compile error (can’t call mutating func of struct stored in a let)