ã¯ããã«
ãååã¯ãXcodeãã¤ã³ã¹ãã¼ã«ãã¦éçºç°å¢ãæ´ããã¨ããã¾ã§ãè¡ãã¾ãããä»åã¯ãSwiftã®åºæ¬çãªææ³ãç´¹ä»ãã¾ããæ°ããSwiftãå¦ã³å§ãã人ãç¥ã£ã¦ããã¹ãã«ã¼ã«ãä¸å¿ã«è§£èª¬ãã¦ããã¾ããããã¹ã¦ã®Swiftã®ææ³ãç¶²ç¾ ããããã§ã¯ãªãããããã®ç¹ã¯ã注æãã ããã
ãã¾ãã¯åºæ¬ããã£ããç解ãããã®å¾ã§ããã«ç¥èãæ·±ãã¦ãããã¨ããããããã¾ãã
ãä»åã¯ãXcodeã®æ©è½ã®Playgroundã使ç¨ãã¦Swiftã³ã¼ãã®ãã§ãã¯ãè¡ãã¾ããã¾ãã¯ããã®æºåããå§ãã¦ããã¾ãããã
éçºç°å¢
ããã®é£è¼ã§ã¯ã次ã®ç°å¢ã使ç¨ãã¦ãã¾ãã
- macOS Sequoia 15.1
- Xcode 16.1
Playgroundã®æºå
ãPlaygroundã¨ã¯ãèªç±ã«ã³ã¼ããå ¥åã§ããçµæãç°¡åã«ç¢ºèªãããã¨ãã§ããXcodeã®æ©è½ã®ã²ã¨ã¤ã§ããã·ã³ãã«ã§ä½¿ãããããSwiftãå¦ã³å§ããéã«ããããã§ãã
ãããã§ã¯ãPlaygroundãä½æãã¦ã¿ã¾ãããã
Playgroundã®ä½ææé
- Xcode ã¢ããªãéãã¾ãã ã
-
Xcode ã®ä¸é¨ã¡ãã¥ã¼ãã
File
>New
>Playground
ãé¸æãã¾ãã -
次ã®ç»é¢ã表示ããã¾ããâ
Blank
ãé¸æããâ¡Next
ãæ¼ãã¾ãã -
ä¿åå
ã®æå®ãæ±ãããã¾ããâ¢ã«å¥½ããªååãå
¥åããâ£
Create
ãæ¼ãã¾ãã - 次ã®ãããªç»é¢ã表示ãããã¨ä½æã¯å®äºã§ãã
ããã®Playgroundã使ç¨ããªãããSwiftã®åºæ¬ã®ææ³ãå¦ãã§ããã¾ãã
ãä»åã¯ä½¿ç¨ããªããããä½ææã«è¨è¿°ããã¦ãã次ã®ã³ã¼ãã¯åé¤ãã¦ããã¾ãã
import UIKit var greeting = "Hello, playground"
ãPlaygroundãããXcodeãã®åºæ¬äºé
ãPlaygroundãXcodeã使ç¨ããéã«å½¹ç«ã¤åºæ¬äºé ãäºåã«ãä¼ããã¾ãã
ã³ã³ã½ã¼ã«ã¸ã®åºåã«ã¤ãã¦
ãprinté¢æ°ã使ããã¨ã§ãããã°ã©ã ã®åºåããããã°ã¨ãªã¢ã«è¡¨ç¤ºã§ãã¾ããã³ã¼ãã®åä½ç¢ºèªãããæã«ä¾¿å©ã§ãã
ãé¢æ°ã«ã¤ãã¦ã¯ã¾ã å¦ç¿ããã¦ãã¾ããããä»ã¯ããããªãã¨ãåºæ¥ããã¨ããã ãã®ç解ã ãã§åé¡ããã¾ããã
ãPlaygroundã«æ¬¡ã®ã³ã¼ããè¨è¿°ãã¾ãã
print("Hello, playground")
ãâ ã®ãã¿ã³ã§ãããã°ã¨ãªã¢ã表示ããâ¡å®è¡ãã¿ã³ãæ¼ãã¦åºåçµæã確èªãã¦ã¿ã¾ãããã
ã次ã®ããã«Hello, playground
ã¨åºåã§ãããæåã§ãã
ã³ã¡ã³ãã®ä½¿ãæ¹
ãã³ã¡ã³ãã¯ããã°ã©ã ã¨ãã¦å®è¡ãããªããããã³ã¼ãã®ä¸æçãªç¡å¹åã«ä½¿ç¨ããããã³ã¼ãã®ç®çãæ確ã«ããããã«ä½¿ç¨ãã¾ãã
ãã³ã¡ã³ãã«ãããæåã®å
é ã«//
ãè¨è¿°ãããã¨ã§ãã³ã¡ã³ãã«ãããã¨ãã§ããããã°ã©ã ã®å®è¡ã«ã¯å½±é¿ããªããªãã¾ãã
ã次ã®ããã«ã³ã¡ã³ããè¨è¿°ãã¾ãã
// printé¢æ°ã§ã print("Hello, playground") // ãããã°ã¨ãªã¢ã確èª
ãå®è¡ãã¿ã³ãæ¼ãã¦ãå¤ãããHello, playground
ã¨åºåã§ãããæåã§ãã
ãããã«ãè¤æ°è¡ã®ã³ã¡ã³ããå¿
è¦ãªå ´åã¯ã/*
ã¨*/
ã使ç¨ãã¦ã³ã¡ã³ãç¯å²ãæå®ã§ãã¾ãã
ã次ã®ããã«å 容ãå¤æ´ãã¾ãã
/* åºåããã¾ãã print("Hello, playground") */
ãprinté¢æ°ãã³ã¡ã³ãã«ãªã£ããããå®è¡ãã¿ã³ãæ¼ãã¦ããããã°ã¨ãªã¢ã«ã¯åºåããã¾ããã
ãããã§æºåã¯æ´ãã¾ãããããã§ã¯ãSwiftã®å¦ç¿ã«é²ãã§ããã¾ãããã