This file contains hidden or 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 | |
| import CoreBluetooth | |
| class ViewController: UIViewController, CBCentralManagerDelegate, CBPeripheralDelegate { | |
| let centralManager:CBCentralManager! | |
| var connectingPeripheral:CBPeripheral! | |
| required init(coder aDecoder: NSCoder) { | |
This file contains hidden or 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
| ```swift= | |
| func perform(operation:String, a:Double, b:Double) -> Double! { | |
| var result:Double? | |
| switch operation { | |
| case "+": | |
| result = a + b | |
| case "-": | |
| result = a - b | |
| case "/": | |
| result = a / b |
This file contains hidden or 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
| //inout類似C++傳遞引用 | |
| var image = [ | |
| [3, 7, 10], | |
| [6, 4, 2], | |
| [8, 5, 4] | |
| ] | |
| func raiseLowerValueOfImage(_ image:inout [[Int]]) { | |
| for row in 0..<image.count { | |
| for color in 0..<image[row].count { |
This file contains hidden or 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
| enum Geometry: Int { | |
| case triangle = 3 | |
| case square = 4 | |
| case pentagon = 5 | |
| case hexagon = 6 | |
| } | |
| func drawGeometry(stepsLabel: Int, sides: Geometry) { | |
| let count = sides.rawValue | |
| let exteriorAngle = 360 / count |
This file contains hidden or 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
| //: __Problem 4__ | |
| //: | |
| //: __4a.__ | |
| //: Write an instance method, bark(), that returns a different string based on the value of the stored property, size. | |
| enum Size: Int { | |
| case small | |
| case medium | |
| case large | |
| } |
This file contains hidden or 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 printer(mode: Int, size: Int) { | |
| guard size >= 2 else { return } | |
| switch mode { | |
| case 0: | |
| for i in 1...size { | |
| for _ in 1...i { | |
| print("*", terminator: "") | |
| } | |
| print("") | |
| } |
This file contains hidden or 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 | |
| @IBDesignable | |
| class FaceView: UIView { | |
| //Don't type infer | |
| @IBInspectable | |
| var scale: CGFloat = 0.9 | |
| @IBInspectable |
This file contains hidden or 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
| class FaceView: UIView { | |
| //MARK | |
| //Don't type infer | |
| @IBInspectable | |
| var scale: CGFloat = 0.9 { didSet{setNeedsDisplay()} } | |
| @IBInspectable | |
| var eyesOpen: Bool = true { didSet{setNeedsDisplay()} } |
This file contains hidden or 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 ViewController: UIViewController { | |
| //MART: 1. @IBOutlet weak var faceView: FaceView! | |
| //MART: 9. | |
| /* | |
| IBOutletweak var faceView: FaceView! { | |
| didSet { |
This file contains hidden or 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
| class ImageViewController: UIViewController | |
| { | |
| //1. model | |
| // var imageURL: URL? | |
| //5. | |
| var imageURL: URL? { | |
| didSet { | |
| image = nil | |
| //fetchImage() |
OlderNewer