Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added a new folder, file and updated the repo's README.md #25

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions Extras/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +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)
33 changes: 33 additions & 0 deletions Extras/String<->Int Operations.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import UIKit
//Converts Strings into respective Data type and requirement
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)}
}
//Converts Int into respective Data type and requirement
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)!))}
}
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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
Expand All @@ -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.