Skip to content

Commit

Permalink
add string reversed task
Browse files Browse the repository at this point in the history
  • Loading branch information
danilovdev committed Sep 23, 2017
1 parent dd2b0ab commit 35e2d5d
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 1 deletion.
1 change: 0 additions & 1 deletion NSCodingExample/NSCodingExample/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,5 @@ class ViewController: UIViewController {
userDefaults.set(data, forKey: "appSettings")
}


}

22 changes: 22 additions & 0 deletions StringReverse.playground/Contents.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
//: Playground - noun: a place where people can play

import UIKit

var str = "Hello, playground"

// First way
print(String(str.reversed()))

//Second way
var charArray: [Character] = [Character]()
for ch in str {
charArray.append(ch)
}

var reversedArray: [Character] = [Character]()

for i in (0..<str.count).reversed() {
reversedArray.append(charArray[i])
}

print(String(reversedArray))
4 changes: 4 additions & 0 deletions StringReverse.playground/contents.xcplayground
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<playground version='5.0' target-platform='ios'>
<timeline fileName='timeline.xctimeline'/>
</playground>

0 comments on commit 35e2d5d

Please sign in to comment.