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 printData(){ | |
guard let path = NSBundle.mainBundle().pathForResource("contacts", ofType: "txt") else { | |
print("Error while reading data") | |
return | |
} | |
do { | |
let content = try String(contentsOfFile: path, encoding: NSUTF8StringEncoding) | |
print(content) |
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 printData(){ | |
guard let path = NSBundle.mainBundle().pathForResource("contacts", ofType: "txt") else { | |
print("Error while reading data") | |
return | |
} | |
do { | |
let content = try String(contentsOfFile: path, encoding: NSUTF8StringEncoding) | |
print(content) |
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
let firstTodoEndpoint: String = "http://jsonplaceholder.typicode.com/todos/1" | |
let firstTodoUrlRequest = NSMutableURLRequest(URL: NSURL(string: firstTodoEndpoint)!) firstTodoUrlRequest.HTTPMethod = "DELETE" | |
let session = NSURLSession.sharedSession() | |
let task = session.dataTaskWithRequest(firstTodoUrlRequest) { (data, response, error) in | |
guard let _ = data else { | |
print("error calling DELETE on /todos/1") | |
return | |
} | |
print("DELETE ok") |
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
// | |
// RW.swift | |
// Web | |
// | |
// Created by Mike Chirico on 10/15/15. | |
// Copyright © 2015 Mike Chirico. All rights reserved. | |
// | |
import UIKit |
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 | |
protocol Observer { | |
var id: String { get } | |
func update(_ string: String) | |
} | |
extension Observer { | |
func update(_ string: String) { | |
print("\(type(of: self)) に届いた新しい値は \(string) です。") |
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 | |
protocol Observer { | |
var id: String { get } | |
func update(_ string: String) | |
} | |
extension Observer { | |
func update(_ string: String) { | |
print("\(type(of: self)) に届いた新しい値は \(string) です。") |
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
#filename: kindlesplit.py | |
f=open('My Clippings.txt').read() | |
notes = f.split('==========\r\n') | |
lines = [] | |
booktitle = [] | |
lines = notes[:] | |
for i in range(len(lines)): | |
lines[i]=lines[i].split('\r\n') | |
booktitle.append(lines[i][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 Cocoa | |
import PlaygroundSupport | |
PlaygroundPage.current.needsIndefiniteExecution = true | |
if let url = URL(string: "https://api.github.com/users/octocat") { | |
URLSession.shared.dataTask(with: url){ data, response, error in |
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 Cocoa | |
import PlaygroundSupport | |
PlaygroundPage.current.needsIndefiniteExecution = true | |
struct iTunesRequestManager { | |
static func getSearchResult(_ query: String, results: Int, langString: String, completionHandler: @escaping ([[String: AnyObject]], NSError?) -> Void){ | |
var urlComponents = URLComponents.init(string: "https://itunes.apple.com/search") |
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 downloadFile(url: URL) { | |
let downloadRequest = URLRequest(url: url) | |
URLSession.shared.downloadTask(with: downloadRequest) { location, response, error in | |
// To do check resoponse before saving | |
guard let tempLocation = location, error == nil else { return } | |
let documentDirectory = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).last | |
do { | |
let fullURL = try documentDirectory?.appendingPathComponent((response?.suggestedFilename!)!) | |
try FileManager.default.moveItem(at: tempLocation, to: fullURL!) | |
print("saved at \(String(describing: fullURL)) ") |
OlderNewer