StringTest

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

// Swift2 string blog

// https://developer.apple.com/swift/blog/?id=30

// Kyoung Shin Park (2016 Fall)

import Cocoa

var letters: [Character] = [“c”, “a”, “f”, “e”]

var cafe = String(letters)

print(letters.count)

print(cafe)

print(cafe.characters.count)

// print char of string “cafe”

for c in cafe.characters {

print(c)

}

let acuteAccent : Character = “\u{0301}”

cafe.append(acuteAccent)

print(cafe)

print(cafe.characters.count)

print(cafe.characters.last!)

cafe.characters.contains(“e”)

cafe.characters.contains(“´”)

cafe.characters.contains(“é”)

// In Swift, strings are considered equal regardless of whether they are constructed from decomposed or precomposed character sequences:

let decomposed = “\u{1100}\u{1161}” // ᄀ + ᅡ

let precomposed = “\u{AC00}” // 가

decomposed == precomposed // true

let string1 = “”

var string2: NSString = “Hello”

switch (string2) {

case let string2 as NSString:

print(“string2 is NSString”)

case let string2 as String:

print(“string2 is String”)

default:

print(“None of those”)

}

var len = string2.length

var string3 = String(“Hello”)

string3 += ” World”

string3.append(Character(“!”))

var string4 = String(count: 7, repeatedValue: Character(“A”))

var string5 = NSString()

var string9 = NSString(string: “Hello”)

var string6 = NSMutableString(capacity: 10)

var total = 100

var string7 = “\(string3)! total=\(total)”

var string8: NSString = string7

//var string10: String = string3.stringByAppendingFormat(” append %@”, total)

//print(string10)

string5 = string2.stringByAppendingFormat(” append %@”, string8)

print(string8)

print(string8.description)

var str = “Hello”

var world = ” World”

var smile = “?”

var mark = “!~”

var combined = str + mark

var combined2 = (str + world).stringByAppendingString(smile)

var len2 = combined2.characters.count

// length

var length = combined.characters.count

var len3 = combined.startIndex.distanceTo(combined.endIndex)

var len4 = (combined as NSString).length

// print char of string

for char in combined.characters {

print(char)

}

print(combined2.lowercaseString)

print(combined2.uppercaseString)

print(combined2.capitalizedString)

if let range = combined.rangeOfString(“ello”) { // contains

print(“ello”)

}

else {

print(“none”)

}

var trail = combined.substringWithRange(Range<String.Index>(start: str.endIndex, end: combined.endIndex))

print(“combined = \(combined)”)

let startIndex = combined.startIndex.advancedBy(2)

let endIndex = combined.startIndex.advancedBy(5)

//combined.insert(“^”, atIndex: combined.endIndex)

//let question : Character = “?”

//combined.append(question)

//print(combined)

combined.insert(“a”, atIndex: startIndex)

combined.insertContentsOf(“bc”.characters, at: startIndex.successor())

combined.removeAtIndex(combined.endIndex.predecessor())

print(combined)

let substring = combined[startIndex..<endIndex]

print(“substring = \(substring)”)

var sub2 = combined.substringWithRange(Range<String.Index>(start: startIndex, end: endIndex))

print(sub2)

var myString = “Seoul, New York, Tokyo LA”

var myArray = myString.componentsSeparatedByString(“,”)

for s in myArray {

print(s)

}

var myArray2 = myString.componentsSeparatedByCharactersInSet(NSCharacterSet(charactersInString: “, “))

for s in myArray2 {

print(s)

}

var num = “56.25”

if let range = num.rangeOfString(“.”) {

let wholeNum = num[num.startIndex..<range.startIndex]

print(“wholeNum=\(wholeNum)”)

num.replaceRange(num.startIndex..<range.startIndex, with: “32”)

print(“num=\(num)”)

num.removeRange(num.startIndex..<range.startIndex)

print(“num2=\(num)”)

}

let animals = [“Giraffe”, “Cow”, “Dog”, “Cat”]

//animals.append(“Bird”)

var animal = animals[2]

for (index, value) in animals.enumerate() {

print(“animals[\(index)]=\(value)”)

}

DataType

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

// Swift2 DataType (constant, variable)

// Swift2 DataType (int, float, double, char, string, tuple, type inference, type casting)

// Kyoung Shin Park (2016 Fall)

import Cocoa

// constant

let x = 16 // Int (type inference)

let y : Double = -2.3 // Double

let z = -1.2 // Double (type inference)

let w : Float = -1.7 // Float

let str = “Hello, playground” // String (type inference)

let c1 = “A” // String (type inference)

let c2 : Character = “A” // Character

print(“x=\(x) y=\(y) z=\(z) w=\(w) y+z=\(y+z)”)

print(“x+y+z+w=\(Double(x)+y+z+Double(w))”) // type casting

print(“str=\(str) c1=\(c1) c2=\(c2)”)

// tuple

let (s, t, r, u, v) = (“ABC”, “D”, 1, 3.5, true) // tuple

print(“s=\(s) t=\(t) r=\(r) u=\(u) v=\(v)”)

let tupleValues = (“ABC”, “D”, 1, 3.5, true) // tuple

print(“\(tupleValues.0) \(tupleValues.1) \(tupleValues.2) \(tupleValues.3) \(tupleValues.4)”)

// variable

var isUsed = true // Bool (type inference)

if isUsed {

print(“isUsed=\(isUsed)”)

}

var a = 10 // Int (type inference)

print(“a=\(a)”)

a = 20

print(“a=\(a)”)

var b : UInt // UInt declaration

b = 30 // initialization

print(“b=\(b)”)

print(“a+b=\(a+Int(b))”)

for i in a…Int(b) {

print(i)

}

for j in 0..<5 {

print(j)

}

var str1 = “Hello” // String (type inference)

print(“str1=\(str1)”)

str1 += ” World” // String += operator

print(“str1=\(str1)”)

for s in str1.characters { // using foreach

print(“\(s)”)

}

for i in 0..<str1.characters.count { // using String.Index & range

print(“str1[\(i)]=\(str1[str1.startIndex.advancedBy(i)])”)

}

var charView = str1.characters

for (index, value) in charView.enumerate() { // using array & tuple

print(“str1[\(index)]=\(value)”)

}

How to download Xcode dmg

http://stackoverflow.com/questions/10335747/how-to-download-xcode-4-5-6-7-8-and-get-the-dmg-file

You can find the DMGs for Xcode and other development tools on https://developer.apple.com/download/more/ (requires Apple ID to login).

You must login to have a valid session before downloading anything below.

*(Newest on top. For each minor version (6.3, 5.1, etc.) only the latest revision is kept in the list.)

Load apps on your iPhone using Xcode 7

https://developer.apple.com/xcode/

“Xcode 7 and Swift now make it easier for everyone to build apps and run them directly on their Apple devices. Simply sign in with your Apple ID, and turn your idea into an app that you can touch on your iPad, iPhone, or Apple Watch. Download Xcode 7 beta and try it yourself today. Program membership is not required.”

  1. Update OS X 10.10.5 (Yosemite) via App Store
  2. Download and Install Xcode 7

Download Xcode 7 beta 6 (Apple ID 로그인)

xcodeapp

3. Open Xcode 7, open Preferences and login to your Account

AppleID

4. Open the workspace/project in Xcode and build & run on the simulator

5. Plug in your iPhone and select it as the build Destination

Device

6. Make sure to set iOS Deployment Target (e.g. iOS 8.4) in Build Settings for both Project and Target

Project

Target

7.  Click on the Fix Issue for Failed to code sign xxxx

2015-09-02 20.50.25

8. If there’s no build errors, the app should now launch on your phone