平成30年2月22日(木曜日)
セルに表示する画像の角丸化、以下サイトにより、OK!!
// 角丸にする cell.img.layer.cornerRadius = cell.img.frame.size.width * 0.2 cell.img.clipsToBounds = true
平成30年2月22日(木曜日)
セルに表示する画像の角丸化、以下サイトにより、OK!!
// 角丸にする cell.img.layer.cornerRadius = cell.img.frame.size.width * 0.2 cell.img.clipsToBounds = true
平成30年2月21日(水曜日)
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell: CustomCell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath) as! CustomCell
if let data = tabledata {
let urlString: NSString = data.results[indexPath.row].artworkUrl60 as NSString
let imgURL: URL = URL(string: urlString as String)!
do {
let imageData = try Data(contentsOf: imgURL as URL)
cell.img.image = UIImage(data: imageData)
} catch {
print("Unable to load data: \(error)")
}
}
return cell
}
平成30年2月21日(水曜日)
import UIKit
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {var window: UIWindow?
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.
return true
}
}
平成30年2月21日(水曜日)
import UIKit
class TableViewController: UITableViewController {
//配列fruitsを設定
let fruits = ["apple", "orange", "melon", "banana", "pineapple"]
override func viewDidLoad() {
super.viewDidLoad()
// Uncomment the following line to preserve selection between presentations
// self.clearsSelectionOnViewWillAppear = false
// Uncomment the following line to display an Edit button in the navigation bar for this view controller.
// self.navigationItem.rightBarButtonItem = self.editButtonItem
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
// MARK: - Table view data source
override func numberOfSections(in tableView: UITableView) -> Int {
// #warning Incomplete implementation, return the number of sections
return 1
}
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
// #warning Incomplete implementation, return the number of rows
return fruits.count
}
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath)
// セルに表示する値を設定する
cell.textLabel!.text = fruits[indexPath.row]
return cell
}
}
平成30年2月21日(水曜日)
BASIC -> AppDelegate
import UIKit
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
self.window = UIWindow(frame: UIScreen.main.bounds)
let storyboard = UIStoryboard(name: "Main", bundle: nil)
let initialViewController = storyboard.instantiateViewController(withIdentifier: "TableViewController")
self.window?.rootViewController = initialViewController
self.window?.makeKeyAndVisible()
return true
}
}
平成30年2月19日(火曜日)
var a = [1, 2, 3]
for value in a {
print(value) // 1, 2, 3
}
// インデックス付き
for (i, value) in a.enumerated() {
print(i) // 0, 1, 2
print(value) // 1, 2, 3
}
// nil 以外の要素をループ
var a: [String?] = ["1", nil, "2"]
for case let value? in a {
print(value) // "1", "2"
}
平成30年2月20日(火曜日)
Reachability.swiftをダウンロード、swift fileとしてプロジェクトに保存、
ViewControllerに、func()例えば、net_stat()を作成し、その内容は、
ダウンロードサイトにあるExample – closuresをそのままコピー、
viewDidLoadから、net_stat()をcallすれば、動作。
平成30年2月20日(火曜日)
Xcode9.2において、iphone実機での動作確認、
キーチェーンアクセスがパスワードを入力しても通らない件。
パスワードを入力して「常に許可」をクリックすると無事にビルドすること成功。
以下サイトに感謝!!
平成30年2月19日(月曜日)
//------------------------------------------
import UIKit
//: Playground - noun: a place where people can play
import UIKit
struct Itunes_lookup: Codable {
struct Data: Codable {
let formattedPrice: String
var trackName: String
var artworkUrl60: String
}
var resultCount: Int
var results: [Data]
}
let url = URL(string: "https://itunes.apple.com/jp/lookup?id=1135688400")!
let decoder: JSONDecoder = JSONDecoder()
do {
let data = try Data(contentsOf: url, options: [])
let rss = try decoder.decode(Itunes_lookup.self, from: data)
print(rss)
print(rss.results[0].artworkUrl60)
print(rss.results[0].trackName)
print(rss.results[0].formattedPrice)
} catch {
print(error)
}
//------------------------------------------
参考url
struct Codable
Swift Codable With Custom Dates
[iOS][Swift 4] CodableでJSONのパース
iTunes Search API