Skip to content

Instantly share code, notes, and snippets.

@gitbricho
Last active January 11, 2016 04:07
Show Gist options
  • Save gitbricho/e416f1268f7eb118cee0 to your computer and use it in GitHub Desktop.
Save gitbricho/e416f1268f7eb118cee0 to your computer and use it in GitHub Desktop.
IOSSample101
import UIKit
class Comment {
// MARK: プロパティ
var id: Int
var text: String
// MARK: イニシャライザ
init(id:Int, text:String) {
self.id = id
self.text = text
}
}
import UIKit
class MovieT {
// MARK: プロパティ
var name:String
var photo:UIImage?
var rating: Int
// MARK: イニシャライザ
init?(name:String, photo:UIImage?, rating: Int) {
// プロパティの初期化
self.name = name
self.photo = photo
self.rating = rating
// name が空または rating が負の場合は初期化失敗
if name.isEmpty || rating < 0 {
return nil
}
}
}
import UIKit
class Product {
// MARK: プロパティ
var id: Int
var name: String
var price: Int
var inStock: String
var comments: [Comment]
// MARK: イニシャライザ
init(id:Int, name:String, price:Int, inStock: String, comments: [Comment]) {
self.id = id
self.name = name
self.price = price
self.inStock = inStock
self.comments = comments
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment