From 80a612d974707bd93ab7796aa9d261680d8c2d47 Mon Sep 17 00:00:00 2001 From: Jayant Sogikar Date: Thu, 1 Oct 2020 00:20:39 +0530 Subject: [PATCH 1/5] Created an extra file called 'Extras' --- Extras/README.md | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 Extras/README.md diff --git a/Extras/README.md b/Extras/README.md new file mode 100644 index 0000000..e2acc62 --- /dev/null +++ b/Extras/README.md @@ -0,0 +1,2 @@ +# Extras +Creating another folder as to hold extra cool code snippets and tricks that help us fellow swift coders easily and quickly get on track in solving problems and building apps in an instant. From bfd9e0702c21deaff92deb34b75295fec349259d Mon Sep 17 00:00:00 2001 From: Jayant Sogikar Date: Thu, 1 Oct 2020 00:25:17 +0530 Subject: [PATCH 2/5] Added a swift file to ease String/Int conversion Added a swift file to ease necessary String/Int conversion that might be required while dealing with ASCII or Binary related situations --- Extras/String<->Int Operations.swift | 31 ++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 Extras/String<->Int Operations.swift diff --git a/Extras/String<->Int Operations.swift b/Extras/String<->Int Operations.swift new file mode 100644 index 0000000..06a63ef --- /dev/null +++ b/Extras/String<->Int Operations.swift @@ -0,0 +1,31 @@ +import UIKit +extension String { + // a -> 10 + var hexToInt : Int{return Int(strtoul(self, nil, 16))} + // a -> 10.0 + var hexToDouble : Double{return Double(strtoul(self, nil, 16))} + // a -> 1010 + var hexToBin : String{return String(hexToInt, radix: 2)} + // 10 -> a + var intToHex : String{ return String(Int(self) ?? 0, radix: 16)} + // 10 -> 1010 + var intToBin : String{return String(Int(self) ?? 0, radix: 2)} + // 1010 -> 10 + var binToInt : Int{return Int(strtoul(self, nil, 2))} + // 1010 -> 10.0 + var binToDouble : Double{return Double(strtoul(self, nil, 2))} + // 1010 -> a + var binToHexa : String{return String(binToInt, radix: 16)} + // a -> 97 + var ascii : Int{return Int(self.unicodeScalars.first!.value)} +} +extension Int { + // 10 -> 1010 + var binString : String{return String(self, radix: 2)} + // 10 -> a + var hexString : String{return String(self, radix: 16)} + // 10 -> 10.0 + var double : Double{ return Double(self)} + // 97 -> a + var intToAscii : String{return String(Character(UnicodeScalar(self)!))} +} From 317f06de6f9c8063bfa068fe48bdf4d58e87109b Mon Sep 17 00:00:00 2001 From: Jayant Sogikar Date: Thu, 1 Oct 2020 00:26:49 +0530 Subject: [PATCH 3/5] Update String<->Int Operations.swift --- Extras/String<->Int Operations.swift | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Extras/String<->Int Operations.swift b/Extras/String<->Int Operations.swift index 06a63ef..035e3ae 100644 --- a/Extras/String<->Int Operations.swift +++ b/Extras/String<->Int Operations.swift @@ -1,4 +1,5 @@ import UIKit +//Converts Strings into respective Data type and requirement extension String { // a -> 10 var hexToInt : Int{return Int(strtoul(self, nil, 16))} @@ -19,6 +20,7 @@ extension String { // a -> 97 var ascii : Int{return Int(self.unicodeScalars.first!.value)} } +//Converts Int into respective Data type and requirement extension Int { // 10 -> 1010 var binString : String{return String(self, radix: 2)} From d0c5b7eecb5c9eac8f11ee180867a68941dc5471 Mon Sep 17 00:00:00 2001 From: Jayant Sogikar Date: Thu, 1 Oct 2020 00:29:33 +0530 Subject: [PATCH 4/5] Updated README.md of Extras --- Extras/README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Extras/README.md b/Extras/README.md index e2acc62..2d23d2c 100644 --- a/Extras/README.md +++ b/Extras/README.md @@ -1,2 +1,4 @@ # Extras Creating another folder as to hold extra cool code snippets and tricks that help us fellow swift coders easily and quickly get on track in solving problems and building apps in an instant. +## Links +* [String<->Int Operations](https://github.com/TheNova22/learn-swift/blob/master/Extras/String%3C-%3EInt%20Operations.swift) From 9d4e193605bd1ac7f8ba53212bfc86119807ae19 Mon Sep 17 00:00:00 2001 From: Jayant Sogikar Date: Thu, 1 Oct 2020 00:30:28 +0530 Subject: [PATCH 5/5] Updated README.md of the repo --- README.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index e5ddcf3..2be74c3 100644 --- a/README.md +++ b/README.md @@ -3,16 +3,16 @@ learn-swift Learn Apple's Swift programming language interactively through these playgrounds. -###Target Audience +### Target Audience Programmers familiar with C++ and/or Objective-C. -###What you'll need +### What you'll need You will need XCode 6.0 GM (or later) or 6.1 Beta 2 (or later) and probably a Mac to run it on. -###Purpose & Goal +### Purpose & Goal More than a primer, these playgrounds are intended to get programmers up to speed on Swift as fast as possible so they can begin using Swift productively. @@ -24,7 +24,7 @@ Learn Apple's Swift programming language interactively through these playgrounds along the way. Play the 'what-if' game. These are live playgrounds which offer near-realtime feedback of edits. -###Source of Content +### Source of Content I created these while working my way through the "Language Guide" section of Apple's book, "The Swift Programming Language". I feel the information from @@ -35,7 +35,7 @@ Learn Apple's Swift programming language interactively through these playgrounds If you don't already have the book, it's free. You should probably get it. -###Contributors +### Contributors Thanks to Rafał Wójcik for his quick work to update these playgrounds to incorporate the Swift language changes that came with XCode Beta 3.