iOS_Playground_課堂筆記



API website :
https://developer.apple.com/reference/swift/string



instance  用小寫開頭  

class 用大寫開頭

型態不同的程式語言


打印 表情符號  按法  Ctrl + Cmd + Space   顯示出   表情符號選擇



看官方文件說明
的按法

Apple Mac 電腦 上   按鈕   alt(option) + 滑鼠點擊該型態(會出現問號符號)



快速截圖  Alt + space + 3 (全螢幕)  /   4 (特定範圍)


右側  ---->  按小黑方塊   在底部顯示出
         ---->  按小眼睛  在彈出小匡中做顯示






//: Playground - noun: a place where people can play

import UIKit

var str = "Hello, playground"

var message1 = "start!"
var message2 = "END!"

message1.uppercased()
message2.lowercased() + " Okay 🙂 "

let messageLabel1 = UILabel(frame: CGRect(x: 0, y: 0, width: 300, height: 100))
messageLabel1.text = message1

messageLabel1

messageLabel1.backgroundColor = UIColor.orange
messageLabel1.textAlignment = NSTextAlignment.center
messageLabel1.layer.cornerRadius = 10.0
messageLabel1.clipsToBounds = true
messageLabel1

let name = "Rosa"
let personalizedGreeting = "Welcome, \(name)!" // \(字串變數)
let price = 2
let number = 3
let cookiePrice = "\(number) cookies: $\(price*number)." //一片2元,三片餅乾 6


//寫法1.
var length = message1.endIndex
//A string’s “past the end” position—that is, the position one greater than the last valid subscript argument.
let greeting = "Welcome!"
let longerGreeting = greeting + "We are glad you're here!"
print(longerGreeting) // prints "welcome! we're glad you're here!"(有換行)
//寫法2.
var size = 0
size = message1.characters.count

var mess:String

var lengthString = message1.endIndex




這裡  建議我們可以在  playground 先完成設計節省模擬器跑的時間


一個小地方



var mess:String     //String 大寫開頭的 屬於 Class
var lengthString = message1.endIndex   // 字串長度






具有問題的程式碼代測

binary operator '==' cannot be applied to operands of type 'String!' an ‘Character’ 


//: Playground - noun: a place where people can play

import UIKit

var str = "Hello, playground"

var message1 = "start!"
var message2 = "END!"

message1.uppercased()
message2.lowercased() + " Okay 🙂 "

let messageLabel1 = UILabel(frame: CGRect(x: 0, y: 0, width: 300, height: 100))
messageLabel1.text = message1

messageLabel1

messageLabel1.backgroundColor = UIColor.orange
messageLabel1.textAlignment = NSTextAlignment.center
messageLabel1.layer.cornerRadius = 10.0
messageLabel1.clipsToBounds = true
messageLabel1

let name = "Rosa"
let personalizedGreeting = "Welcome, \(name)!" // \(字串變數)
let price = 2
let number = 3
let cookiePrice = "\(number) cookies: $\(price*number)." //一片2元,三片餅乾 6


//寫法1.
var length = message1.endIndex
//A string’s “past the end” position—that is, the position one greater than the last valid subscript argument.
let greeting = "Welcome!"
let longerGreeting = greeting + "We are glad you're here!"
print(longerGreeting) // prints "welcome! we're glad you're here!"(有換行)
//寫法2.
var size = 0
size = message1.characters.count

var mess:String
var lengthString = message1.endIndex

let string1 = "Hello"
let string2 = " there"

let char1: Character = "!"
let char2: Character = "?"

let StringPlusString = string1 + string2

let StringPlusChar = string1 + char1


留言

這個網誌中的熱門文章

何謂淨重(Net Weight)、皮重(Tare Weight)與毛重(Gross Weight)

Architecture(架構) 和 Framework(框架) 有何不同?_軟體設計前的事前規劃的藍圖概念

經得起原始碼資安弱點掃描的程式設計習慣培養(五)_Missing HSTS Header