This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Foundation | |
let jsonObject: [AnyObject] = [ | |
["name": "John", "age": 21], | |
["name": "Bob", "age": 35], | |
] | |
func JSONStringify(value: AnyObject,prettyPrinted:Bool = false) -> String{ | |
let options = prettyPrinted ? NSJSONWritingOptions.PrettyPrinted : NSJSONWritingOptions(rawValue: 0) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Foundation | |
let string = "[ {\"name\": \"John\", \"age\": 21}, {\"name\": \"Bob\", \"age\": 35} ]" | |
func JSONParseArray(string: String) -> [AnyObject]{ | |
if let data = string.dataUsingEncoding(NSUTF8StringEncoding){ | |
do{ | |
if let array = try NSJSONSerialization.JSONObjectWithData(data, options: NSJSONReadingOptions.MutableContainers) as? [AnyObject] { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Foundation | |
let string = "{\"name\": \"John\", \"age\": 35, \"children\": [\"Jack\", \"Jill\"]}" | |
func JSONParseDictionary(string: String) -> [String: AnyObject]{ | |
if let data = string.dataUsingEncoding(NSUTF8StringEncoding){ | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Foundation | |
func HTTPsendRequest(request: NSMutableURLRequest,callback: (String, String?) -> Void) { | |
let task = NSURLSession.sharedSession().dataTaskWithRequest(request,completionHandler : | |
{ | |
data, response, error in | |
if error != nil { | |
callback("", (error!.localizedDescription) as String) | |
} else { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Foundation | |
func JSONParseDict(jsonString:String) -> Dictionary<String, AnyObject> { | |
if let data: NSData = jsonString.dataUsingEncoding( | |
NSUTF8StringEncoding){ | |
do{ | |
if let jsonObj = try NSJSONSerialization.JSONObjectWithData( | |
data, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func jsonStringify(jsonObject: AnyObject) -> String { | |
var jsonString: String = "" | |
switch jsonObject { | |
case _ as [String: AnyObject] : | |
let tempObject: [String: AnyObject] = jsonObject as! [String: AnyObject] | |
jsonString += "{" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Mark:- Fake functions to show a loading bar when loading webView | |
func startedLoadingWebView() { | |
self.progressView.progress = 0.0 | |
self.finishedLoadingPage = false | |
//0.01667 is approximately 1/60 to lead at 60fps | |
self.timer = NSTimer.scheduledTimerWithTimeInterval(0.01667, target: self, selector: "timerCallback", userInfo: nil, repeats: true) | |
} | |
func timerCallback() { | |
if self.finishedLoadingPage { | |
if self.progressView.progress >= 1 { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/*For an input of 1, 2, 3, 4, 7, 6, 5, 9, 2, 1, 4, 11, 3 | |
Should print out -> (1,1),(2,2),(3,3),(4,4),(6,7),(9,11)*/ | |
import java.util.Collections; | |
public class PatternExtractor { | |
List<Integer> array = new ArrayList<>(Arrays.asList(1, 2, 3, 4, 7, 6, 5, 9, 2, 1, 4, 11, 3)); | |
public static void main(String[] args) { | |
for (int i = 0; i < array.size(); i++) { | |
int value1 = array.get(i); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class JSONStringValidator { | |
public static void main(String[] args) { | |
String jsonString = "{\"name\": \"John\",\"age\":\"23\"}"; | |
System.out.println("JSON: " + jsonString); | |
System.out.println("Validity: " + isJsonValid(jsonString)); | |
} | |
public static boolean isJsonValid(String jsonString) { | |
//Removing whitespaces | |
jsonString = jsonString.replaceAll("\\s+",""); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import UIKit | |
class AuthenticationViewController: UIViewController { | |
@IBOutlet weak var username: UITextField! | |
@IBOutlet weak var password: UITextField! | |
override func viewDidLoad() { | |
super.viewDidLoad() | |
} |
OlderNewer