Swiftã®ã³ã³ãã¤ã«ã¨ã©ã¼å¯ãéã
Appleã2014å¹´6æã«åºãã¦ããæ°ããããã°ã©ãã³ã°è¨èªSwiftã®ã³ã³ãã¤ã«ã¨ã©ã¼ã®åé。ãããªããã°ã©ã ã§ãããªã¨ã©ã¼ãåºã¾ãã、ã¨ããä¾ãããã¤ãéãããã®ã§ã(ä»æ§ãèªã¿ãªããããã¨ã¨ã©ã¼ãåºãããã®ãããªãå«ã)。çæ³ãè¨ããªãã³ã³ãã¤ã«ã®å·¥ç¨ãç解ããä¸ã§ããããã®èª¬æããããã®ã ã、ããªãå°éçã«ãªãã®ã§ããã¾ã§ã¯åºæ¥ãªã。
var abc: Int ã var abc = 0 ãªãåã決ã¾ã(æ¨æ¸¬ã§ãã)ã®ã§OK。
var a, b, c: IntãªãOK。
å¤ãåæå¤ä»¥å¤ã«ãããªãvarã§å®£è¨ãããã¨。
æ°ããã¯ã©ã¹ãæ§é ä½ãå®ç¾©ãããã¨ããã、ãã®ã¯ã©ã¹åã¯ãã§ã«ããå ´å
【確èªver】Swift 3.0.2【èª】element (é åã®)è¦ç´
Superã®Sã¯ã¨ã©ã¼ã¡ãã»ã¼ã¸å ã§ã¯å¤§æåã§ãã、ããã°ã©ã ã«æ¸ãã¨ãã¯å°æåã«ãªãã¾ã。
Swiftã®åæåã¯åºæ¬çã«
・èªåã®ããããã£åæå¤
・superã®åæåã¡ã½ãããå¼ã¶
・superã®ããããã£ã®åæå¤ã®ä¸æ¸ã
ã®é çªã§ã
ã¡ãªã¿ã«Swift3.0.2ã®æç¹ã§ã®ä»æ§ã§ãã、å¼ã³åºããå¿ãã¦ããã¨åæåã¡ã½ããã®æå¾ã«è¦ªåæåã¡ã½ãããåæã«å¼ãã§ãããæ©è½ãããã¾ã。æ¡ä»¶ã¯superãinit()ã¨ããå¼æ°ãªãã®åæåã¡ã½ãããæã¡、ãããdesignatedã¤ãã·ã£ã©ã¤ã¶ã¼ã§、designatedã¤ãã·ã£ã©ã¤ã¶ã¼ãããã²ã¨ã¤ãããªãå ´åã§ã。以ä¸ã®å ´åã¯ã¨ã©ã¼ãåºã¾ãã。
èªåã®ã¯ã©ã¹ã§å®£è¨ãããã®ã®åæåã¨super.initå¼ã³åºãã«ã¯é çªããã、
1 èªåã®ã¯ã©ã¹ã§å®£è¨ãããã®ã®åæå
2 super.initç³»å¼ã³åºã
3 ä¸ã®ã¯ã©ã¹ããç¶æ¿ãããã®ã®åæå
ã®é çªã§å¼ã³åºããã¨。
ãã ã、convinienceã¤ãã·ã£ã©ã¤ã¶ã®å ´åã¯ããã¯å½ã¦ã¯ã¾ããªã。
Use of selfã¨ããã®ã¯「selfã使ã」ã¨ããå½ä»¤å½¢ã®æå³ã§ã¯ãªã、「self(ã®ããããã£ãªã©)ã使ã£ã¦ãããã¨ãåé¡ã§ã」ã¨ããæå³。
ãã ãselfã使ã£ã¦ãªãã¦ããã®ã¡ãã»ã¼ã¸ãåºããã¨ããã。ãã®å ´åselfãã¤ãã¦ãã¡ãã»ã¼ã¸ã¯å¤ãããªã。
Use of selfã¨ããã®ã¯「selfã使ã」ã¨ããå½ä»¤å½¢ã®æå³ã§ã¯ãªã、「selfã使ã£ã¦ãããã¨ãåé¡ã§ã」ã¨ããæå³。ãã ã、self.aãåã«aã¨æ¸ããæã§ããã®ã¡ãã»ã¼ã¸ãåºãã®ã§ãããããã。
Consecutive〜ã2ã¤ããã、ã¡ã½ããå ã§ã®å®£è¨ã«å¯¾ãã¦statementsã®ã»ããåºã¦、ã¯ã©ã¹ã¡ã³ãã®å®£è¨ã«å¯¾ãã¦declarationsã®ã»ããåºã。Expected declarationã¯ã©ã¡ãã§ãåºã。
ãã®å ´åããããããããä¿®æ£åè£ãé¸ãã§ãæ²»ãã¾ãã。
åæååºæ¥ç¡ããã®ã§ã¤ã³ã¹ã¿ã³ã¹ãä½ããã¨ãã。
å ¥ãåã¨ããã、ä¸è¡ã«è¤æ°ã®å®£è¨ãããã¨ãã«åºã。
ã¾ã、staticå¤(å®)æ°ã ã¨å¤§ä¸å¤«。
åæåã¡ã½ããã®å®è¡ã、åæå¤ã®ä»£å ¥ãå¿ è¦ã§ã
Variableã¨è¡¨ç¤ºããããConstantã¨è¡¨ç¤ºããããã¯varãletã«ãã。
used before being initializedã®ã¨ã©ã¼ã¡ãã»ã¼ã¸ã¨ã ãããåãããª
é¢ç½ãã®ã¯UIColorã®å®£è¨ã®éãã«ããã¨ã©ã¼æ±ãã¨ãããã©ãããå¤ãããã¨
ãããã®ãã¢ã¯ã»ã¹å¯è½ãªç¯å²å ã®2ç®æã§å®ç¾©ããã¦ãã¦、ã©ã¡ããå¼ã³åºãã°è¯ããããããªãã¨ããªã©ã«åºã。
ã¿ã¤ãå¤æ°ãã¤ã³ã¹ã¿ã³ã¹ã¡ã½ããå ã§ååãä»ããã«ä½¿ãã¨åºã。
class宣è¨ããå¤æ°ã«ããã®ã¡ãã»ã¼ã¸ãåºã。
readã¯ãªã¼ã?ã¬ãã?neverã®å¾ã«ããã®ã§ãªã¼ã?ã¬ãããªãbe readã?
宣è¨æã«var abcArray: [String] = []ã¨ãããã¨ã§åæååºæ¥ã。ããã§è¨ãåæåã¯ã¤ã³ã¹ã¿ã³ã¹åã®æå³ã§ä½¿ããã¦ãã。
é åã«ã¯「宣è¨ããã ãã§åæåãã¦ããªãç¶æ 」ã¨、「åæåããç¶æ 」ãããã®ã§、åæåæ¸ã¿ãæèãããã¨ãå¿ è¦。
対å¿ã¯、varå¤æ°ã«ããã、ä¸è¡ã§åæåãè¡ããã«ãã。
æ¼ ç¶ã¨ããã¡ãã»ã¼ã¸ãªã®ã§ããç¨åº¦ã¨ã©ã¼åå ãæ¨æ¸¬ãããã¨ãå¿ è¦ã。
***ã«ã¯[Any]ãå ¥ããã¨ãå¤ã。
ã§ãã¨ã©ã¼。
(myFontAttributes[NSParagraphStyleAttributeName] as? NSMutableParagraphStyle)?.alignment = .left
ã«ããã¨ã¨ã©ã¼ã¯åºãªãã、ããå°ãã·ã³ãã«ãªæ¹æ³ããããããªæ°ããã。
lunch.append("cheeseburger")ã使ãã¨å¯è½。
é¢æ°、ã¡ã½ããã®å®è¡æã§å¼æ°ãå¤ãããã¨ãã«åºã。
【確èªver】Swift 3.0.2
é¢æ°ã®å®ç¾©ãªã©ã§å¼æ°ã«ã©ãã«ãä»ãã¦ãã(è¦æ±ãã¦ãã)ã、å¼ã³åºãå´ã§ã¯æ¸ããã¦ããªã。ã³ã³ã¹ã¹ãã©ã¯ã¿å¼ã³åºãã§ãåæ§ã®ç¶æ³ã§åºã¾ã。
æ»ãå¤ã®åãéã。
é¢æ°/ã¡ã½ããå ã§ä¿æããå¤ãã©ã宣è¨ããã°ãããã¯è¦èª¿æ»。→ã©ãããCè¨èªã®é¢æ°å staticã«ããããã®ã¯ãªã模æ§。
çµæã使ããªãå ´åã¯
_ = abc()
ã¨ããã¨ã¯ã¼ãã³ã°ãæ¶ãã。
ã¾ã、ååã®å¾ãã«!ã?ãã¤ããã°ãã®ã¨ã©ã¼ã¯æ¶ãã¾ã。ãã®ããæ¹ã¯åæåããªãã·ã§ã³åãç解ãã¦ããªãã¨å±éº。
ã¡ã½ããããªã¼ãã¼ã©ã¤ããããã¨ããã¨ãã«、ã¹ã¼ãã¼ã¯ã©ã¹ã«ãã®ã¡ã½ããããªãã、å¼æ°ãæ»ãå¤ã®çµã¿åãããéãã、å¿ è¦ãªã¹ã¼ãã¼ã¯ã©ã¹ã®ç¶æ¿ãåºæ¥ã¦ããªã。
ããããã£ããªã¼ãã¼ã©ã¤ã(ã¤ã¾ãæ¼ç®ããããã£ã®get setã§ä¸æ¸ããããã¨ãã¦ãã)ãããã¨ããã¨ãã«、ã¹ã¼ãã¼ã¯ã©ã¹ã«ãã®ããããã£ããªãã、å¿ è¦ãªã¹ã¼ãã¼ã¯ã©ã¹ã®ç¶æ¿ãåºæ¥ã¦ããªã。
å®è¡ããã¯ã©ã¹ã¯ã«ã¼ãã¯ã©ã¹(親ã¯ã©ã¹ããããªã)ã«ãªã£ã¦ãã。
***ã®å¯¾è±¡ã¨ãªãã®ã¯override
æ¸ããã¦ããã¨ãããã¯ã©ã¹ã®å®ç¾©ã®å¤å´
***ã«å½ã¦ã¯ã¾ãã®ã¯super
å¼æ°ã®ãªã¹ãã¯()ã®ä¸ã«æ¸ã。å¼æ°ããªãã¦ã()ã¯æ¸ãäº。
æ¼ç®ããããã£ã®å ´åã¯classã§ããã、ã¹ãã¢ãããããã£ã®å ´åã¯staticãç¨ããã¹ã(classã¨staticã®éããçºçããªãã®ã§ä½¿ç¨ããã®ã¯staticã®ã¿)。
classComputedPropertyã¯getter/setterããªãã®ã§ã¹ãã¢ãããããã£ã®å¯è½æ§ãããã¨å¤æããã¦ã¨ã©ã¼
funcã®åã«mutatingãã¤ããã°OK
対å¿ã¯、宣è¨æã«=0ããã、init()ã®ä¸ã§abc = 0ãªã©ããã。
requiredãä»ããã¤ãã·ã£ã©ã¤ã¶ã¯ãµãã¯ã©ã¹ãä½ã£ãéã«å®è£ (ãªã¼ãã¼ã©ã¤ã)ããªãã¨ãããªã。ããã¦、次ã®ãµãã¯ã©ã¹ã§ãå®è£ ãããããã«ãããã¾ãrequiredãã¤ããªãã¨ã ã。
åãåã®ä¸ã§æå®ã¤ãã·ã£ã©ã¤ã¶ã¼ããæå®ã¤ãã·ã£ã©ã¤ã¶ã¼ãå¼ã¶ãã¨ã¯åºæ¥ãªã。
ã³ã³ããã¨ã³ã¹ã¤ãã·ã£ã©ã¤ã¶ã¼ããæå®ã¤ãã·ã£ã©ã¤ã¶ã¼ãå¼ã¶ãã¨ã¯åºæ¥ãã®ã§、ã³ã³ããã¨ã³ã¹ã¤ãã·ã£ã©ã¤ã¶ã¼ã«ãã¦ã¯ã©ããã¨ããããããã。
ã¨ããããã¤ã³ã¹ã¿ã³ã¹ãä½ãã ããªã、designatedã¤ãã·ã£ã©ã¤ã¶ã¼ããããã。super.init(frame: CGRect())ãªã©。
ãµãã¯ã©ã¹ã§initã¡ã½ãããã²ã¨ã¤ãæ¸ããªãå ´åã¯å é¤ããã模æ§
convenienceåæåã¡ã½ããããã¯designatedåæåã¡ã½ãããå¼ã°ãªãã¨ãããªã
superã®convenienceããªã¼ãã¼ã©ã¤ãããæã«åºã。
åæåã¡ã½ããã¯designatedã¨convenienceããã。ãªã¼ãã¼ã©ã¤ãããããã¨ãåºæ¥ãã®ã¯designatedã®ã¿。ãã®ã¨ãoverrideãä»ãã。ã¤ã¾ãinitã«overrideãã¤ããå ´åã¯ãã®initã¯designatedã§ããå¿ è¦ããã。ããã、ãããconvenienceã®å ´åã¯çç¾ããã®ã§ãã®ã¡ãã»ã¼ã¸ãåºã。
åæåãä¸å®å ¨ãªæã«åºã。
requiredãããã°åå。
Swift2.0ãããã®ä»æ§å¤æ´ã§Doubleã®ã¨ãã§ãIntã®æã¨åãããã«ããã©ã«ãå¤ãä¸ããããããã«ãªã£ãã®ã§ã¡ãã»ã¼ã¸ã¯ä¿®æ£ã®å¿ è¦ãããã¾ã。
Aomã¯æå®å¤1ã§、1.0ãè¨å®ããã。
Iwaã¯æå®å¤5ã§、5.0ãè¨å®ããã。
Akiã¯æå®å¤6ã§、6.0ãè¨å®ããã。
Miyã¯æå®å¤10.0ã§、10.0ãè¨å®ããã。
Yamã¯åã®æå®å¤ãæ´æ°ã§ã¯ãªãã®ã§ã¨ã©ã¼。
ããã¯enum宣è¨ä¸ã®caseã«ã³ãã³ãä»ãã¦ãã¾ã£ãã¨ãã«åºã¦ãã¾ã。
ãã®ã¡ãã»ã¼ã¸ã§ãã、ã©ãã«ã¨ããã®ã¯ã³ãã³ãä»ããç¶æ ã®ãã¨ãè¨ã£ã¦ãã¾ã。
å ·ä½çã«ã©ããªã®ããããããããªãã£ãã®ã§Characterã§ãµã³ãã«ã³ã¼ããä½ãã¾ãã。
親ã¯ã©ã¹ã§å®£è¨ãã¦ããããããã£(ã¹ãã¢ã、æ¼ç®åã®ä¸¡æ¹ãå«ã)ãã¹ãã¢ãããããã£ã§å宣è¨(ã¾ãã¯override)ãããã¨ãã。
finalãã¤ããã¯ã©ã¹ã¯ä¸ã¸ç¶æ¿åºæ¥ãªã。
finalã§å®£è¨ãã¦ããããããã£(ã¹ãã¢ã、æ¼ç®åã®ä¸¡æ¹ãå«ã)ããµãã¯ã©ã¹ã®æ¼ç®ããããã£ã§ãªã¼ãã¼ã©ã¤ããããã¨ãã。finalããã¦ããªã、letã§ãªããã®ãªããããæ¼ç®ããããã£ã§ãªã¼ãã¼ã©ã¤ããããã¨ã¯å¯è½。
let宣è¨ãããããããã£ã、æ¼ç®ããããã£ã§ãªã¼ãã¼ã©ã¤ããããã¨ããã¨ã。
æ¼ç®ããããã£ã¯varæ±ãã«ãªãã®ã§、è¦å¶ãç·©ããæ¹åã¸ã®å¤æ´ã«ãªã。ãããç¦æ¢ãã¦ããã®ãã¨æããã。
ãµãã¯ã©ã¹å´ãletã§å®£è¨ããã¨æ¼ç®ããããã£ã«åºæ¥ãªã(æ¼ç®ããããã£ã¯varã®ã¿)。æ¼ç®ããããã£ã«åºæ¥ãªããªããªã¼ãã¼ã©ã¤ãåºæ¥ãªã。ã¤ã¾ãlet宣è¨ãããããããã£ã¯ãªã¼ãã¼ã©ã¤ãåºæ¥ãªãã¨ãããã¨ã ããã。
finalã§å®£è¨ãã¦ããã¡ã½ããããµãã¯ã©ã¹ã§ãªã¼ãã¼ã©ã¤ããããã¨ãã。
ã¯ã©ã¹å ã§å®£è¨ãããã®ã«ã¯classã¨staticã使ãã。structã¨enumã¯staticã®ã¿ã使ãã。
classãä»ãããã®ã¯ä¸ã®ã¯ã©ã¹ã§ç¶æ¿åºæ¥ã。structã¨enumã¯ç¶æ¿ã®æ©è½ããªãã®ã§classã¯ä½¿ãéããªã。
ãããã³ã«å ã§ã¯staticã®ã¿。ãããã³ã«ã¯structãenumã«ä»ããããå¯è½æ§ããããã。ãããã³ã«å ã§å®£è¨ããstaticã¡ã½ããã、é©ç¨ã¯ã©ã¹å ã§classã§å®ç¾©ãã¦ãOK。
ãããã³ã«ã§ã¯staticã¨ãªã£ã¦ãã¦ã、ãããé©ç¨ããã¯ã©ã¹ã§、class func funcA(a: Int) {}ã¨åºæ¥ã。
ãããã³ã«ãä½ãç解ãã¦ããªãã¨ãã¯ç解ãå¿ è¦ã§ã。ããã¯å°ãæéããããã¾ã。
éã«ãããã³ã«ã§ã¯getã®ã¿ã®ãã®ã、å®è£ å´ã§èªã¿æ¸ãåºæ¥ãããã«ããã®ã¯OK。
ãããã³ã«ã®å®ç¾©å ã«ã¯ååã¨å¼æ°ã¨æ»ãå¤ã®ã¿ãæ¸ã。
getãsetã®ä¸èº«ã¯ãããªã。
var a: Int { get set }
ã§OK。
{ get }ã{ get set }ãæ£ãã
Swiftã®ã¨ã©ã¼ã¡ãã»ã¼ã¸ã§ã¯top lebelã¨è¡¨ç¾ããããã¨ããã
global scopeã§å®£è¨ããã¦ããå¤æ°/å®æ°ã¯globalå¤æ°/globalå®æ°
global scopeã§å®£è¨ããã¦ããfunctionã¯global function
é¢æ°ãã¡ã½ããå ãªã©ã§ããå®è¡ã§ããªãå½ä»¤ãé¢æ°ãã¡ã½ããã®å¤ã§è¡ã£ãæ
Bã«ã¯ããããããã®ãå ¥ããã¨ããã
++ã--ã¯å»æ¢ã«ãªã£ãã®ã§å¾æ¥ã®Cè¨èªã®ä½¿ãæ¹ãããã¨åºã。
ä¸èº«ã®åãåãçµã¿åããã¯æã¯ã¨ã©ã¼ãåºããSwift3.0ã§ã¯åºãªã。
2ã¤ãæ¯è¼ãã==ã¨===ã¯、ã¯ã©ã¹å士ãæ§é ä½å士ãã§æåãéã«ãªãã®ã§æ³¨æ。
æ§é ä½ã®ãªãã·ã§ãã«å士ã§ã===ã§ã¨ã©ã¼。==ã«ããã°ã¨ã©ã¼ã«ãªããªã。
ã¯ã©ã¹ã®ãªãã·ã§ãã«å士ã®å ´åã==ã§ã¨ã©ã¼ã«ãªã、===ã§ã¨ã©ã¼ã«ãªããªã。
ãã¾ã
&ã|ã*ãå¤ãªã¨ããã«å ¥ã£ã¦ãã
.ã®å¾ããæ¸ããã¦ããªã
宣è¨ãå¿ãã¦ããã¨ã。
宣è¨ã¨å®è£ ã§〜fixã®ä¸ä¸è´。preã¨postãªã©。
ä»ã«remainder(dividingBy:)ã¨ããã®ããã。
ææ°é¨ã®æ°åã¯10é²ã§è¡¨è¨ãã。ã¤ã¾ãp9ã¯OKã§paã¯NG。ä»åã®p-4ã¯OK。
ææ°é¨ã®æ°åã«ããå°æ°ç¹ç§»åã¯2é²ç¶æ ã«å¯¾ãã¦è¡ããã。ã¤ã¾ãä¸ã®ä¾ã¯、1.1010(2é²)ä¸ã§4ã¤ç§»åãã¦、0.0001101(2é²)ã¨ãªã。ããã16é²ã«ããã¨0.1a(16é²)。ããã10é²ã«ç´ãã¨、1/16 + 10/256 = 0.1015625。å人çã«ã¯、ãã®å°æ°ç¹ç§»åæä½ã2é²ãªã®ã¯ç²ç¹ã ã£ã。16é²è¡¨è¨ã®ã¾ã¾ã§4æ¡ã®å°æ°ç¹ç§»åæä½ãè¡ãã¨0.0001a(16é²)ã¨ãªã、ã ãã¶å°ããå¤ã«ãªã£ã¦ãã¾ã。
ä¸ã®ãªã¹ããåç §
å°æ°è¡¨ç¾16é²ã§ã¯e4ãªã©ã§çµããã¨ææ°ã®æå³ã§ä½¿ã£ã¦ãããã©ãã解éã«è¿·ããã¨ã«ãªãã®ã§、ææ°è¡¨ç¾ã«ç¨ããæåã¯pã使ãã¾ã。å°æ°è¡¨ç¾16é²ã¯ææ°è¡¨ç¾ãã¤ãããã¨ãå¿ é ã§ã。
10é²è¡¨ç¾ã«pã使ã£ãå ´åã¯pããå¥ã®æã¨è§£éããã
å°æ°ç¹ç´å¾ã®ææ°è¡¨ç¾ã¯ã ã
ã¡ãã£ã¨åå ããããã«ããã¨ã©ã¼
nestedã®æå³ãããããããªã。
【確èªver】Swift 4.0
let (ã©ãã«å: å¤æ°å , ã©ãã«å: å¤æ°å)ã¨è§£éããã
var (ã©ãã«å: å¤æ°å , ã©ãã«å: å¤æ°å): (ã©ãã«å: å, ã©ãã«å: å)
ãªã®ã§ã©ãã«åãéè¤ãã¦ãã
ã¡ãªã¿ã«isã«ãã¦ãã¨ã©ã¼ã«ãªã
å¤ããããnilãã®å¤å®ã¯!= nilã使ã
if let c = a, d = b where c && d {}
çãããã。
true/falseã®ã©ã£ã¡ã表示ããããã¯==ã!=ãã«ãã
returnãthrowãå¿ è¦。ã¡ãªã¿ã«breakã使ãã¨ã¨ã©ã¼。
ã«ã¦ã³ã¿ã¼ã¯(æã ãæä½åºæ¥ãªãã¨ããæå³ã§)å®æ°ã¨ããæ±ãããã
forã®æ¡ä»¶ã i in 0..<10ã®å½¢å¼ã®ã¨ãã¯()ãã¤ãã¦ã¯ãããªã
letãçãããã³ã³ãã¤ã«ã¨ã©ã¼ã¯ãªããªã
è¤æ°ã®"å ´å"ã§åãå¦çãããã«ã¯"å ´å"ã,(ã«ã³ã)ã§åºåã£ã¦è¨è¿°ãã。
fallthroughã®å¾ã«ã¯caseãããã¯ãdefaultãããã¯ãã¤ãããã¨
【確èªver】Swift 4.0.2
å ´ååãã«ãããããã¨ãã«åºã
Swiftã®ä»æ§ã«do-try-catchã追å ãããã¨ãã«do-whileã®doã¯ä½¿ç¨ç¦æ¢ã«ãªãã¾ãã。
cannot be declared publicã¨must be declared privateã¯åããããªãã®ã ãæé¢ã«éããããã®ã¯、"publicãã¤ãã¦ã¯ãããªã"ã¨è¨ãããã®ã、"privateãã¤ããªãã¨ãããªã"ã¨è¨ãããã®ãã®éã。
ã¢ã¯ã»ã¹ä¿®é£¾åããªã«ãä»ãã¦ããªããã®ã¯internal(ã¢ã¸ã¥ã¼ã«å ã®ã¿ããã¢ã¯ã»ã¹è¨±å¯)
ãããæé¢ã«éããããã®ã¯、"publicãã¤ãã¦ã¯ãããªã"ã¨è¨ãããã®ã、"privateãã¤ããªãã¨ãããªã"ã¨è¨ãããã®ãã®éã。
private(set) var a: Int {ãªãã¨ã©ã¼ãåºãªã。
private(set) var a: Int {ãªãã¨ã©ã¼ãåºãªã。
ãã£ã¦ãããã®ã¨ã©ã¼ã¯public(get)ã«å¯¾ãã¦、ããã¯setã®ééããªã®ã§ã¯ãªããã¨ææããã¨ã©ã¼ã¡ãã»ã¼ã¸ã¨æããã。getã«ãsetã«ãprivateãè¨å®ãã¦ãããã®ã¯、ããã§ãprivateã®setãè¦æ±ããã¡ãã»ã¼ã¸ãåºã。ãããä¸ã®çç±ã«ããprivate(get)ãæ¸ããããã¨ãåå ã§åºã¦ãããã®ã¨æ¨æ¸¬。
é¢æ°ã®æ»ãå¤ã«?ä»ãã§ãªããã®ã宣è¨ããã¦ããã®ã«nilãè¿ããã¨ãã
ãªãã·ã§ãã«åãã¢ã³ã©ããã®æå³ãããããªãå ´åã¯、ãªãã·ã§ãã«åã«ã¤ãã¦èª¿ã¹ã(å°ãæéããããã¾ã)
ãªãã·ã§ãã«åãã¢ã³ã©ããããªãã¾ã¾ã§ä½ãããã¨ããªã©
ä¿æã®æå³ãããããªãã¨ãã®æ¨è¦æ¤ç´¢ç¨èªã¯strong weak ARC åç §ã«ã¦ã³ã¿
ãªãã·ã§ãã«ã¯ã ã
Swift2.0ã§çºçããå°ãè¬ã«æããã³ã³ãã¤ã«ã¨ã©ã¼。
ã¡ãªã¿ã«Swift 2.0ã®æ®µéã§ã¯str.characters.countããããã。
ãã ãObjective-Cã¨ã«ã¦ã³ãçµæãæããããªãstr.utf16.countããããã。
ãã ãObjective-Cã¨ã«ã¦ã³ãçµæãæããããªãstr.utf16.countããããã。
ä¸ã®ãµã³ãã«ãåç §。
do catchã§å²ããªã、ä¸(å¼ã³åºãå )ã«æãããªããã。
ä¸ã®ãµã³ãã«ãåç §。
do catchã§å²ããªã、ä¸(å¼ã³åºãå )ã«æãããªããã。
try?ã使ã£ãã¨ãã«åºã。ä¸ã®ä¾ã§ã¯bã¸ã®ä»£å ¥ã®ã¨ããã§åºã¦ãã。try?ã®æã¯ã¨ã©ã¼ãçºçãã¦ã次ã®æã¸ç§»ã。ã¨ã©ã¼ãåºãã¨ãã¯bã«ã¯nilãå ¥ã£ã¦、ã¨ã©ã¼ã®çºçã®æç¡ã確èªã§ããããã«ãã。someThrowingFunction()ã¯Intãè¿ãã¡ã½ããã ã、nilã許容ããããã«bã¯Int?ã¨ããªããã°ãããªã。åæå®ããªããã°èªåã§Int?ã¨ãªã。
ã¾ãã¡ãã»ã¼ã¸ã®æå¾ã®chain with '?'ãè¬ã§ããã、次ã®æ§ã«ã¡ã½ããããªãã·ã§ãã«ãè¿ãã¨å®ç¾©ããã¦ããã¨ãã«try?ã®æ»ãå¤ã®åãInt??ã¨ãªãã、ããã®ãã¨ããªã¨ããæ°ããã。
ã¾ã、ãã®ã¡ã½ããã®å±éºåº¦ã5ã¨ããã、fix-itã§åºã¦ããtry!ãé¸ã¶ã¨ã¨ã©ã¼çºçã®ã¨ãã«å®è¡æã¨ã©ã¼ã¨ãªãã®ã§å±éº。
let b = abc(a: 0)ã§OK。
ãããã¯ã«ã¼ããswitchã§ããªãã¨ããã§æ¸ãããã¨ãã«åºã。
é£ã³å ã®ã©ãã«æå®ã«åé¡ãããã¨ãã«åºã。
println(å¤ãæ¹)ã使ã£ã¦è¤éãªå¼æ°ãä¸ããã¨åºã。printlnã使ã£ã¦ãããã¨ãã ããªã®ã§printã使ãã¨ããå 容ãåºãã¦æ¬²ãã。ãã¼ã¸ã§ã³ã¢ããã§ä¿®æ£ãããå¯è½æ§ãé«ã。
print(æ°ããæ¹)ã¸ã®å¼æ°ã®ä¸ãæ¹ã¨ãã¦ã¯OKãªãã®ã§ãåºã。
ä¸ã®ã¨åãããã«、println(å¤ãæ¹)ã使ã£ã¦è¤éãªå¼æ°ãä¸ããã¨åºã。printlnã使ã£ã¦ãããã¨ãã ããªã®ã§printã使ãã¨ããå 容ãåºãã¦æ¬²ãã。ãã¼ã¸ã§ã³ã¢ããã§ä¿®æ£ãããå¯è½æ§ãé«ã。
print(æ°ããæ¹)ã¸ã®å¼æ°ã®ä¸ãæ¹ã¨ãã¦ã¯OKãªãã®ã§ãåºã。
Fix-itãåºã¦ãã¾ãã、ãããé©ç¨ãã¦ãå¤ã«ãªãã¾ã。
"be+åã身"ã®beåè©ããªã?
Swift 2.1ã®ã¨ãã¯ååãå¤ãã£ã¦éããªãã®ã§ãã®è¦ªåãªã¨ã©ã¼ã¡ãã»ã¼ã¸ã ã£ãã、Swift3.1ã§ã¯Use of unresolved identifier 'println'ã¨ããå·ããã¡ãã»ã¼ã¸ã«ãªã£ã。
ä½ãã宣è¨ãããã¤ããã§éä¸ã§ãããã¨ã
宣è¨ãæ¸ããªãã¨ãããªãã¨ããã§ä½ãå¤ãªãã®ãæ¸ããã¨ãã«åºã
ããªããããããªç¶æ³ã§åºã。ã³ã³ãã¤ã©ãåæãã¦ããã¨ãã«äºæãã¦ããªããã®ãåºã¦ããå ´åã«å¤ã。
äºæ³ã ã、ãã®ã¨ã©ã¼ã¯ä½ã「æ¸ãããå¿ è¦ããããã®」ãæ¸ããã¦ããªãã¨ãã«åºãã®ã§ã¯ãªãã、ã¨æããã。ã¾ã、ãã®「æ¸ãããå¿ è¦ããããã®」ã¯ã¨ã©ã¼ç®æããåã®é¨åã«ãã³ãããããã¨ããã、ã¨æããã。
(ä¾1)ä½ããæ¸ãã¤ããã§éä¸ã§ããã
(ä¾2)å¥ã®è¨èªã®ææ³ã§æ¸ãã。ä¾ãã°Objective-Cãªã©
3é æ¼ç®åã«ããããªã?ã®åã«ã¹ãã¼ã¹ãå ¥ããã¨ã§ãã。var b = a ? 1:0
ããã¯å°éã®ã¨ã©ã¼ã¡ãã»ã¼ã¸ãä½ããã。
l-valueã¨ããã®ã¯ã³ã³ãã¤ã©ã®å é¨ã§ä½¿ãããå°éç¨èªã?
ã³ã¡ã³ãéå§è¨å·/*ã«æ¯ã¹ã¦éãè¨å·*/ãå¤ãã¨ã
ã©ããã§{ãæãã¦ããã、åç´ã«}ãå¤ã。
{}ãªã©ã§å²ã¾ããé¨åãä½ãã®åå ã§ç¡å¹ã«ãªã£ã?
{}ããåã§ä½ãåé¡ãããå ´åã«ãåºã
ã³ã³ãã¤ã©ãæ··ä¹±ããã¨ãã«åºãããã ã、ããªããããããªç¶æ³ã§åºã。åæã«åºã¦ãããã®ãä»ã«ããã¨ãã¯ä»ã®ãã®ã®æ¹ã«ãã³ãããããã¨ãå¤ã。
a * bã®ããã«æ¼ç®åã®åå¾ã®ç©ºç½ãæããã¨åºãªããªã。
ææ¡é ç®ãããã¨ãã«åºã。精度ã¯ã¾ãã¾ã。
{}ã§ã®åã®é¨åã«ä½ãåé¡ããããã¨ãå¤ã
varãletå¿ã
static var a:Int = 0ãªãOK
static let a:Int = 0ãªãOK
class varã¨ããããªãæ¼ç®ããããã£ã«ããã¨OK
class letã¯NG。classã«ãããªãæ¼ç®ããããã£ã«ããªãã¨ãããªãã、æ¼ç®ããããã£ã¯letã«åºæ¥ãªãã®ã§。
Swiftã®ãã¼ã¸ã§ã³ã¢ããã§A***ãB***ã«å¤æ´ãããæ
ä»ã®ã¡ãã»ã¼ã¸ã«å¤æ´ã«ãªã£ã。
éãªãã·ã§ãã«åã¯ã ãããã
Cè¨èªã®æå表ç¾ã¯ã ã。
Xcodeã®ãã¼ã¸ã§ã³ãä¸ãã¦ã¯ã¼ãã³ã°ã®åºãæ¹ãå¤ãã£ãå ´å、å¤ãããã¸ã§ã¯ããç«ã¡ä¸ããã¨åºããã¨ããã。ãã®æç« ã®ä¸ã«ç®æ¡æ¸ãã§æå¹ã«ããè¦åãå ·ä½çã«æ¸ããã。
Localizable.stringsã®;å¿ã
宣è¨、åæåã®å®è¡æ
Type annotation missing in pattern
åã®æå®ããªã(åãããããªã)
【確èªver】Swift 3.0.2【èª】annotation 注é//Swift 3.0.2
var abc //ã¨ã©ã¼
abcãä½ã®åãããããªã。var abc: Int ã var abc = 0 ãªãåã決ã¾ã(æ¨æ¸¬ã§ãã)ã®ã§OK。
//Swift 3.0.2
var a, b, c: Int = 0 //ã¨ã©ã¼
Intã¨=0ã¯cã®ã¿ã«å¯¾ãã¦é©ç¨ãããããã§、aã¨bãä¸ç¢ºå®ã«ãªã。var a, b, c: IntãªãOK。
//Swift 3.0.2
var a, b = 0, c: Int //ã¨ã©ã¼
aã«å¯¾ãã¦、= 0ã¯é©ç¨ãããªã(bã«å¯¾ãã¦é©ç¨)、Intãaã«å¯¾ãã¦é©ç¨ãããªã(éã«= 0ãé©ç¨ãããbããããã?)Cannot assign to value: '***' is a 'let' constant
å¤ã代å
¥ã§ãã¾ãã。***ã¯letã§å®ç¾©ãããå®æ°ã§ã。
【確èªver】Swift 3.0.2【èª】assign å²ãå½ã¦ãå¤ãåæå¤ä»¥å¤ã«ãããªãvarã§å®£è¨ãããã¨。
//Swift 3.0.2
let abc = 0
abc = 1 //ã¨ã©ã¼
//Swift 3.0.2
func funcA(a: Int) {
a = 0 //ã¨ã©ã¼
}
é¢æ°ã®å¼æ°ã§ä¸ãããããã®ãé¢æ°å
ã§å¤æ´ãããã¨ãã。é¢æ°ã®å¼æ°ã¯ããã©ã«ãã§å®æ°æ±ã。é¢æ°å
ã§å¤æ°ã¨ãã¦ä½¿ããããªãé¢æ°ã®é ã§var a = aãªã©ã¨ãã¦æ¸ãæãå¯è½ã«ãã。Cannot assign to value: '***' returns immutable value
å¤ã代å
¥ã§ãã¾ãã。***ã¯å¤æ´ã§ããªãå¤ã§ã。
【確èªver】Swift 3.1【èª】assign å²ãå½ã¦ã//Swift 3.1
let a = 1
if 0...10 = a { //ã¨ã©ã¼
print("a")
}
if caseã使ãã、ãã¿ã¼ã³ãããã®~=ã使ãç¶æ³ã§ä¸éå端ã«ãªã£ã。Cannot assign through subscript: '***' is a 'let' constant
subscriptãéãã¦ä»£å
¥ã§ãã¾ãã。***ã¯letã§å®ç¾©ãããå®æ°ã§ã。
【確èªver】Swift 3.0.2//Swift 3.0.2
let i = [0,1]
i[0] = 0 //ã¨ã©ã¼
é
åã¯letã§å®£è¨ããã¦ããã®ã§åè¦ç´ ãå¤æ´ä¸å¯。Variable used within its own initial value
åæå¤ãä¸ããã¨ãã«ãã®å¤ã使ããã¨ãã¦ãã(代å
¥ãããã¨ãã¦ãã)
【確èªver】Swift 3.0.2【èª】within ã®ä¸ã§//Swift 3.0.2
var abc = abc //ã¨ã©ã¼
//Swift 3.0.2
class SomeSpecial {
}
let someSpecial = someSpecial() //ã¨ã©ã¼
ã¤ã³ã¹ã¿ã³ã¹åã、ã¯ã©ã¹åã®é æåãå°æåã«ããã ãã¨ãããããããã¿ã¼ã³ã§、ã¯ã©ã¹åã®é æåãå°æåã«ãªã£ã¦ãã。Use of undeclared type '***'
'***'ã¨ããåã¯ããã¾ãã
【確èªver】Swift 3.0.2【èª】undeclared 宣è¨ããã¦ããªã//Swift 3.0.2
var abc: Int256 = 100 //ã¨ã©ã¼
//Swift 3.0.2
//import UIKit ã³ã¡ã³ãã¢ã¦ããã¦ã¿ã
class ViewController: UIViewController { //ã¨ã©ã¼
}
UIKitã®éimportã«ããUIViewControllerãä½ãããããªã。//Swift 3.0.2
println("ããããã") //ã¨ã©ã¼
printlnã¯å»æ¢ã«ãªã£ã。printã使ã。Invalid redeclaration of '***'
ç¡å¹ãªå宣è¨ã®***
【確èªver】Swift 3.0.2【èª】Invalid ç¡å¹ãª redeclaration å宣è¨æ°ããã¯ã©ã¹ãæ§é ä½ãå®ç¾©ãããã¨ããã、ãã®ã¯ã©ã¹åã¯ãã§ã«ããå ´å
//Swift 3.0.2
var abc = 0
var abc = 1 //ã¨ã©ã¼
//Swift 3.0.2
class A {
}
class A { //ã¨ã©ã¼
}
//Swift 3.0.2
class ClassExtensionTest {
func funcExtensionTest() {
}
}
extension ClassExtensionTest {
func funcExtensionTest() { //ã¨ã©ã¼
}
}
extensionã§ã¯æ¢åã®ãã®ãåå®ç¾©åºæ¥ãªã。//Swift 3.0.2
var a = 0
func a() -> Int { //ã¨ã©ã¼
return 0
}
å¤æ°ã¨å¼æ°ãªãã®é¢æ°ã®çµã¿åãããåä¸åç£è¦å¯¾è±¡Array types are now written with the brackets around the element type
ä»ã¯é
åã®åãã«ãã³ã®ä¸ã«æ¸ãã¾ã
æã¯ã«ãã³ã®åã«æ¸ãã®ã許ããããä»ã¯ã«ãã³ã®ä¸ã«æ¸ãããã«ãªã£ã¦ãã。【確èªver】Swift 3.0.2【èª】element (é åã®)è¦ç´
//Swift 3.0.2
var abc: Int[] //ã¨ã©ã¼
Int[]ã§ã¯ãªã[Int]ã¨ãããã¨。DidSet (WillSet) variable may not also have a set specifier
DidSet (WillSet)(ãå«ã)å¤æ°ã¯setããã£ã¦ã¯ãããªã
【確èªver】Swift 3.0.2【èª】specify ç´°ããæå®ãã//Swift 3.0.2
class classA {
var a: Int {
set {
a = newValue
}
get { //ã¨ã©ã¼ ãªããgetã®ã¨ããã§åºãããã
a
}
didSet {
//ä½ã
}
willSet {
//ä½ã
}
}
}
DidSet (WillSet)ã¨setãä½µç¨ãã¦ããComputed property must have accessors specified
æ¼ç®ããããã£(訳?)ã¯ã¢ã¯ã»ãµã¼(set get)ãæããªãã¨ãããªã
【確èªver】Swift 3.0.2//Swift 3.0.2
var abc: String {
} //ã¨ã©ã¼
Computed property must have an explicit type
æ¼ç®ããããã£(訳?)ã¯æ確ã«åãæããªãã¨ãããªã
【確èªver】Swift 3.0.2//Swift 3.0.2
class A {
var a { //ã¨ã©ã¼
set {
self.a = newValue
}
get {
return self.a
}
}
}
a: Intã®ããã«åãæè¨ãããã¨'let' declarations cannot be computed property
å®æ°ã¯æ¼ç®ããããã£(訳?)ã«ãªããªã
【確èªver】Swift 3.0.2【èª】compute è¨ç®ãã//Swift 3.0.2
let a: Int { //ã¨ã©ã¼
get {
return 100
}
}
//Swift 3.0.2
protocol protocolA {
let a: Int { get } //ã¨ã©ã¼
}
ãããã³ã«ã§å®æ°ã宣è¨ããã¨ãã¯var a: Int { get }ã¨ããã¨OK。ãããã³ã«ãæºæ ããåã®ã»ãã§letã«åºæ¥ã。Variable with a setter must also have a getter
ã»ãã¿ã¼ãæã¤å¤æ°ã¯ã²ãã¿ã¼ãå¿
è¦
【確èªver】Swift3.0.2//Swift 3.0.2
class SomeClass {
var a: Int {
set { //ã¨ã©ã¼
self.a = newValue
}
}
}
Immutable value '***' may only be initialized once
å¤æ´ä¸å¯ã®'***'ã¯ä¸åº¦ããåæååºæ¥ãªã
【確èªver】Swift3.0.2【èª】Immutable ä¸å¤ã®//Swift 3.0.2
class ABC {
let abc: Int
init() {
abc = 0
abc = 0 //ã¨ã©ã¼
}
}
initã¡ã½ããã®ä¸ã§2åletå®æ°ã«å¤ãè¨å®ãããã¨ãã//Swift 3.0.2
struct StructABC {
let a: Int = 0
init() {
a = 1 //ã¨ã©ã¼
}
}
åæå¤ãä¸ãããã¦ãããã®ã«initã®ä¸ã§å¤ãå
¥ãããã¨ãã。Immutable value '***' may not be assigned to
å¤æ´ä¸å¯ã®'***'ã«ä»£å
¥åºæ¥ãªã
【確èªver】Swift 3.0.2//Swift 3.0.2
class ABC {
let abcArray: [Int]
init() {
abcArray = [Int](repeating: 0, count: 5)
abcArray[0] = 1 //ã¨ã©ã¼
}
}
initã¡ã½ããã®ä¸ã§é
åãä¸æ°ã«åæåããå¾ã§åå¥ã«å¤ãè¨å®ãããã¨ããCannot invoke initializer for type 'A***' with an argument list of type '(B***)'
ä¸ããããå¼æ°(B***)ã®åã§ã¯、A***ã®ã¤ãã·ã£ã©ã¤ã¶ã¼ãå®è¡ã§ãã¾ãã。
【確èªver】Swift 3.0.2【èª】invoke ãèµ·åããã//Swift 3.0.2
struct StructABC {
var a: Int = 0
var b: Int = 0
let c: Int = 0
}
func testStruct() {
let a = StructABC(a: 0, b: 0, c: 0)//ã¨ã©ã¼
}
cã¯letã§å®£è¨ããã¦åæå¤ãè¨å®ããã¦ããã®ã§、ã¤ãã·ã£ã©ã¤ã¶ã®å¼æ°ã§æ¸¡ããã¨ãåºæ¥ãªã。Super.init isn't called on all paths before returning from initializer
åæåã¡ã½ããããæ»ã(ã¡ã½ãããçµäºãã)æç¹ããåã«、ã©ããªçµè·¯ã§ãsuper.initãå¼ã°ãã¦ãã¾ãã
【確èªver】Swift 3.0.2Superã®Sã¯ã¨ã©ã¼ã¡ãã»ã¼ã¸å ã§ã¯å¤§æåã§ãã、ããã°ã©ã ã«æ¸ãã¨ãã¯å°æåã«ãªãã¾ã。
Swiftã®åæåã¯åºæ¬çã«
・èªåã®ããããã£åæå¤
・superã®åæåã¡ã½ãããå¼ã¶
・superã®ããããã£ã®åæå¤ã®ä¸æ¸ã
ã®é çªã§ã
//Swift 3.0.2
class A {
var a: Int
init(aa: Int) {
a = aa
}
convenience init() {
self.init(aa: 0)
}
}
class B: A {
var b: Int
init(bb: Int) {
b = bb
} //ã¨ã©ã¼
}
ã¡ãªã¿ã«Swift3.0.2ã®æç¹ã§ã®ä»æ§ã§ãã、å¼ã³åºããå¿ãã¦ããã¨åæåã¡ã½ããã®æå¾ã«è¦ªåæåã¡ã½ãããåæã«å¼ãã§ãããæ©è½ãããã¾ã。æ¡ä»¶ã¯superãinit()ã¨ããå¼æ°ãªãã®åæåã¡ã½ãããæã¡、ãããdesignatedã¤ãã·ã£ã©ã¤ã¶ã¼ã§、designatedã¤ãã·ã£ã©ã¤ã¶ã¼ãããã²ã¨ã¤ãããªãå ´åã§ã。以ä¸ã®å ´åã¯ã¨ã©ã¼ãåºã¾ãã。
//Swift 3.0.2
class C {
var c: Int
init() {
c = 0
}
}
class D: C {
var d: Int
init(dd: Int) {
d = dd
} //ã¨ã©ã¼ã«ãªããªã
}
Property 'self.***' not initialized at super.init call
***ããããã£ã¯super.initãå®è¡ããæç¹ã§åæåããã¦ãã¾ãã
【確èªver】Swift 3.0.2èªåã®ã¯ã©ã¹ã§å®£è¨ãããã®ã®åæåã¨super.initå¼ã³åºãã«ã¯é çªããã、
1 èªåã®ã¯ã©ã¹ã§å®£è¨ãããã®ã®åæå
2 super.initç³»å¼ã³åºã
3 ä¸ã®ã¯ã©ã¹ããç¶æ¿ãããã®ã®åæå
ã®é çªã§å¼ã³åºããã¨。
ãã ã、convinienceã¤ãã·ã£ã©ã¤ã¶ã®å ´åã¯ããã¯å½ã¦ã¯ã¾ããªã。
//Swift 3.0.2
class Oya {
var a: Int
init() {
a = 0
}
}
class Ko: Oya {
var b: Int
override init(){
super.init() //ã¨ã©ã¼
a = 1
b = 0
}
}
//Swift 3.0.2 æ£ããä¾
class Oya {
var a: Int
init() {
a = 0
}
}
class Ko: Oya {
var b: Int
override init(){
b = 0
super.init() //bãåæåããã¦ããã®ã§ã¨ã©ã¼ãåºãªã
a = 1
}
}
Use of 'self' in property access '***' before super.init initializers self
super.initãå¼ã¶åã«'***'ã«ã¢ã¯ã»ã¹ããã®ã«selfã使ã£ã¦ãã
【確èªver】Swift 3.1Use of selfã¨ããã®ã¯「selfã使ã」ã¨ããå½ä»¤å½¢ã®æå³ã§ã¯ãªã、「self(ã®ããããã£ãªã©)ã使ã£ã¦ãããã¨ãåé¡ã§ã」ã¨ããæå³。
ãã ãselfã使ã£ã¦ãªãã¦ããã®ã¡ãã»ã¼ã¸ãåºããã¨ããã。ãã®å ´åselfãã¤ãã¦ãã¡ãã»ã¼ã¸ã¯å¤ãããªã。
//3.1
class Oya {
var a: Int
init() {
a = 0
}
}
class Ko: Oya {
var b: Int
override init(){
a = 1 //ã¨ã©ã¼
b = 0
super.init()
}
}
ãã®ä¾ã§ã¯è¦ªã®initãå¼ã¶åã«è¦ªã®ããããã£ã«å¤ãå
¥ãã¦ãããã¨ããããªããã¨ã ã、ã¨ã©ã¼ã¡ãã»ã¼ã¸ã«ã¯ãããæ¸ãã¦ããªãã®ã§ã¡ãã£ã¨å°ã。Use of 'self' in property access '***' before self.init initializers self
self.initãå¼ã³åºãåã«ããããã£***ã¸ã®ã¢ã¯ã»ã¹ã§selfã使ã£ã¦ãã
【確èªver】Swift 3.0.2Use of selfã¨ããã®ã¯「selfã使ã」ã¨ããå½ä»¤å½¢ã®æå³ã§ã¯ãªã、「selfã使ã£ã¦ãããã¨ãåé¡ã§ã」ã¨ããæå³。ãã ã、self.aãåã«aã¨æ¸ããæã§ããã®ã¡ãã»ã¼ã¸ãåºãã®ã§ãããããã。
//Swift 3.0.2
class A {
var a: Int
init(aa: Int) {
a = aa
}
convenience init() {
a = 0 //ã¨ã©ã¼
self.init(aa: 0)
}
}
Consecutive statements on a line must be separated by ';'
ä¸è¡ã«é£ç¶ãã¦æãæ¸ãæã¯;ã§åºåã£ã¦ä¸ãã
Consecutive declarations on a line must be separated by ';'
ä¸è¡ã«é£ç¶ãã¦å®£è¨ãæ¸ãæã¯;ã§åºåã£ã¦ä¸ãã
Expected declaration
æ³å®ããã宣è¨æ¹æ³(ã«ãªã£ã¦ããªã)
【確èªver】Swift 3.1【èª】Consecutive é£ç¶ããConsecutive〜ã2ã¤ããã、ã¡ã½ããå ã§ã®å®£è¨ã«å¯¾ãã¦statementsã®ã»ããåºã¦、ã¯ã©ã¹ã¡ã³ãã®å®£è¨ã«å¯¾ãã¦declarationsã®ã»ããåºã。Expected declarationã¯ã©ã¡ãã§ãåºã。
//3.1
var abc def: Int //ã¨ã©ã¼
ãã®ããã«ä¸è¡ã§è¤æ°ã®å¤æ°ã宣è¨ãããã¨ãã¦åºåããç¡ãã¨ãã«ãåºãã、ãã®å ´åã®æ£ããåºåãã¯,(ã«ã³ã)ã§ã。Fix-itã§ææ¡ããã;(ã»ãã³ãã³)ã®ä¿®æ£åè£ãé¸ãã§ãæ²»ãã¾ãã。//3.1
var abc = 0: Int //ã¨ã©ã¼
= 0ã¯ä¸çªæå¾ã«ãããã¨。ãã®å ´åããããããããä¿®æ£åè£ãé¸ãã§ãæ²»ãã¾ãã。
//3.1
b: Int = 0 //ã¨ã©ã¼
letãvarãåç´ã«å¿ãã¦ãã'***' cannot be constructed because it has no accessible initializers
***ã«ã¯ã¢ã¯ã»ã¹ã§ããåæåã¡ã½ããããªãã®ã§***ã¯ä½ããã¾ãã。
【確èªver】Swift 3.1åæååºæ¥ç¡ããã®ã§ã¤ã³ã¹ã¿ã³ã¹ãä½ããã¨ãã。
//3.1
protocol ABCProtocol {
func abc()
}
class ABCClass {
var myP = ABCProtocol() //ã¨ã©ã¼
}
ãããã³ã«åã§ã¤ã³ã¹ã¿ã³ã¹ãä½ããã¨ãã。//3.1
enum EnumTest {
}
func enumFunc() {
var a = EnumTest() //ã¨ã©ã¼
}
enumã§ã¤ã³ã¹ã¿ã³ã¹ãä½ããã¨ãã。Cannot call value of non-function type '***'
ãã¡ã³ã¯ã·ã§ã³ã§ã¯ãªã***ã¯å¼ã¹ã¾ãã
【確èªver】Swift 3.1//3.1
class A {
var a: Int = 0 { //ã¨ã©ã¼
get {
return self.a
}
set {
self.a = newValue
}
}
}
æ¼ç®åã¨ã¹ãã¢åã®ã©ã£ã¡ã«ãããã®ãä¸æãªã®ã§ã©ã¡ããã«ã¯ã£ãããããã¨//Swift 3.0.1
class A: UIView {
func funcA() {
let next = self.nextResponder() //ã¨ã©ã¼
}
}
nextResponder()ã¯nextResponderã«ãªã£ã(ããã«nextã«ãªã£ã。)。ãã®ãããªã¡ã½ãã→ããããã£ã®å¤æ´ãããããã®ã«åºã。//Swift 3.0.2
Bundle.mainBundle() //ã¨ã©ã¼ mainBundle()ã¯mainBundleã«ãªã£ã(ããã«mainã«ãªã£ã。)。
FileManager.defaultManager() //ã¨ã©ã¼ defaultManager()ã¯defaultã«ãªã£ã。
Inheritance from non-protocol, non-class type '***'
***ã¨ããéãããã³ã«ãã¤éã¯ã©ã¹ããç¶æ¿ã§ãã¾ãã
【確èªver】Swift 3.2//3.1
class A {
class a: Int { //ã¨ã©ã¼
set {
self.a = newValue
}
get {
return self.a
}
}
}
class varã®varãå¿ãã¦ããã®ã§Intããç¶æ¿ãããaã ã¨è§£éãã'***' cannot appear nested inside another 'var' or 'let' pattern
***ã¯ä»ã®varãletã®ãã¿ã¼ã³ã®ä¸ã«å
¥ãåã§ç¾ãããã¨ã¯åºæ¥ã¾ãã
【確èªver】Swift 3.0.1å ¥ãåã¨ããã、ä¸è¡ã«è¤æ°ã®å®£è¨ãããã¨ãã«åºã。
//Swift 3.0.1
//aã¨bã¯OK
var a = 0
var b = 0
//cã¨dã¯OK
var c = 0,
d = 0
var e = 0,
var f = 0 //ã¨ã©ã¼ ã²ã¨ã¤ç®ã®æå¾ã«ã«ã³ããæ®ã£ã¦ãã
var g = 0
h = 0 //ã¨ã©ã¼ varããªã
var i = 0; var j = 0 //OK
var k = 0, l = 0 //OK
var m = 0, var n = 0 //ã¨ã©ã¼ ,ã®ãããã«varããã
var o = 0; p = 0 //ã¨ã©ã¼ ;ã§åºåã£ãã®ã«varããªã
//Swift 3.0.1
var a = 0, b = 0
//ããã
var a = 0,
b = 0
//ãããã¦
var a = 0,
var b = 0
//ããããã¨ãã«ã¨ã©ã¼ãèµ·ãã
ä¸è¡ã«è¤æ°å®£è¨ãã¦ãããã®(var a = 0, b = 0 ãªã©)ãè¤æ°è¡ã«åããã¨ãCannot use instance member '***' within property initializer; property initializers run before 'self' is available
ããããã£ã¤ãã·ã£ã©ã¤ã¶ã§ã¤ã³ã¹ã¿ã³ã¹ã®ã¡ã³ã***ã¯ä½¿ãã¾ãã。ããããã£ã¤ãã·ã£ã©ã¤ã¶ã¯selfãå©ç¨å¯è½ã«ãªãåã«å®è¡ããã¾ã。
【確èªver】Swift 3.0.1//Swift 3.0.1
class A {
let number = 5
let testArray = [Int](repeating: 0, count: number) //ã¨ã©ã¼ numberã¯ä½¿ããªã
}
init(){}ã®ä¸ã§è¨å®ãããªãOK。ã¾ã、staticå¤(å®)æ°ã ã¨å¤§ä¸å¤«。
'init' is a member of the type; use 'type(of: ...)' to initialize a new object of the same dynamic type
initã¯ã¿ã¤ãã®ã¡ã³ãã§ã。åããã¤ãããã¯ã¿ã¤ãã®æ°ãããªãã¸ã§ã¯ããåæåããã«ã¯type(of: ...)ãç¨ãã¦ä¸ãã。
【確èªver】Swift 4.0//4.0
class A {
func abc() {
let a = self.init() //ã¨ã©ã¼
let b = type(of: self) //OK
}
}
initã¯ã¤ã³ã¹ã¿ã³ã¹ã¡ã½ããã§ã¯ãªã。type(of: ...)ã使ãã°OK。Constructing an object of class type '***' with a metatype value must use a 'required' initializer
ã¡ã¿ã¿ã¤ãã使ã£ã¦***ã¯ã©ã¹åã®ãªãã¸ã§ã¯ããä½ãã«ã¯、requiredãä»ããåæåã¡ã½ãããå¿
è¦ã§ã。
【確èªver】Swift 4.0//4.0
class A {
//required init() {} ãããããã°OK
static func abc() {
let a = self.init() //ã¨ã©ã¼
}
}
required init() {}ãããã°OKã«ãªã。'let' declarations cannot be computed properties
letã§å®£è¨ããããã®ã¯æ¼ç®åããããã£ã«åºæ¥ã¾ãã
【確èªver】Swift 4.0//4.0
class A {
var a: Int = 0
let b :Int {
get {
return -a
}
set {
self.a = -newValue
}
}
}
Variable '***' was never mutated, consider changing to 'let' constant
å¤æ°***ã¯、(ãã®å
)å¤æ´ããã¾ãã。let(ã§å®£è¨ãã)å®æ°ãæ¤è¨ãã¦ä¸ãã。
【確èªver】Swift 3.1//3.1
var abc = 0 //ã¯ã¼ãã³ã°
print(abc) //使ç¨ã¯ããã
//ãã®å
å¤æ´ãããªã
å¤æ°/å®æ°ã®ä½¿ç¨、代å
¥æä½
æ°å¤ã«ã¢ã³ãã¼ãã¼ãå
¥ãã表è¨æ³ã§ãã、ï¼æ¡ãã¨ã«ããã¦ãã¨ã©ã¼ã«ã¯ãªããªãã§ãvar abc = 100_0000 //ã¨ã©ã¼ã§ã¯ãªã
Variable/Constant '***' used before being initialized
***ã¯ä½¿ãåã«åæåããã¦ãã¾ãã
【確èªver】Swift 3.1åæåã¡ã½ããã®å®è¡ã、åæå¤ã®ä»£å ¥ãå¿ è¦ã§ã
Variableã¨è¡¨ç¤ºããããConstantã¨è¡¨ç¤ºããããã¯varãletã«ãã。
//3.1
var abc: CGPoint
var a = abc.x //ã¨ã©ã¼ Variable 'abc' 〜
abcãåæåããªãã§ä½¿ã£ã¦ãã//3.1
func testFunc(a a: Int) {
let b: Int
switch a {
case 0:
b = 1
case 1:
b = 10
default:
break
}
if b == 0 { //ã¨ã©ã¼ Constant 'b' 〜
}
}
switchãdefaultã§éã£ãã¨ãã«åæåãããªã。//3.1
var abcArray: [String]
var abcArray0 = abcArray[0] //ã¨ã©ã¼ Variable 'abcArray' 〜
é
åãåæååã«ä½¿ã£ã¦ãã//3.1
let abc2: Int
let abc3 = abc2 //ã¨ã©ã¼ Constant 'abc2' 〜
letå®æ°ã®åæåå¿ãã«å¯¾ãã¦ãåºã //3.1
class ClassA {
var a: String
init?(b: String?) { //ã¨ã©ã¼
if b == nil {
return nil
}
}
}
失æã®ããã¤ãã·ã£ã©ã¤ã¶ã§ã¹ãã¢ãããããã£(self.a)ã®åæåå¿ã。ããã失æã®ãªãã¤ãã·ã£ã©ã¤ã¶ã®å ´åã¯å¥ã®ã¡ãã»ã¼ã¸ã«ãªã。Struct '***' must be completely initialized before a member is stored to
æ§é ä½***ã¯å¤ãå
¥ããããåã«åæåããã¦ããªãã¨ããã¾ãã
【確èªver】Swift 3.1//3.1
struct StructA {
var aa = 0
}
var a: StructA
a.aa = 1 //ã¨ã©ã¼
Variable/Constant '***' captured by a closure before being initialized
***ã¯åæåããã¦ããªããã¡ã«ã¯ãã¼ã¸ã£ã«æããããã¾ãã(ã¡ã½ãããå®è¡ãããã¨ãã¾ãã)
【確èªver】Swift 3.1used before being initializedã®ã¨ã©ã¼ã¡ãã»ã¼ã¸ã¨ã ãããåãããª
//3.1
let fillColor: UIColor
fillColor.setFill() //ã¨ã©ã¼
fillColorãåæåããã¦ããªãé¢ç½ãã®ã¯UIColorã®å®£è¨ã®éãã«ããã¨ã©ã¼æ±ãã¨ãããã©ãããå¤ãããã¨
//3.1
let fillColor1: UIColor
fillColor1.setFill() //ã¨ã©ã¼
let fillColor2: UIColor!
fillColor2.setFill() //ã¨ã©ã¼
var fillColor3: UIColor
fillColor3.setFill() //ã¨ã©ã¼
var fillColor4: UIColor!
fillColor4.setFill() //ã¨ã©ã¼ãªã
Cannot assign a value of type 'A***' to type 'B***'
A***ãB***ã«ä»£å
¥ã§ãã¾ãã
【確èªver】Swift 3.1//3.1
var abc: Int = 1
var abc2: UInt = 1
abc = abc2 //ã¨ã©ã¼
Int8ã¨Uint8éã®ä»£å
¥ãInt16ãInt8ã«ä»£å
¥、ã¾ãInt8ãInt16ã«å
¥ããã¨ããåºãCannot assign a value of type '()' to type '***'
()(æªå®ãªãã®?)ã***ã«ä»£å
¥ã§ãã¾ãã
【確èªver】Swift 3.1//3.1
var abc: Int
var abc2: Int
abc = abc2 = 1 //ã¨ã©ã¼
代å
¥æ¼ç®ã§å¤ãè¿ããªããªã£ã¦ããã®ã§Cè¨èªã®æ¸ãæ¹ã¯NG//3.1
var abc: Int
var abc2: Int
abc =
abc2 = 1 //ã¨ã©ã¼
縦ã«ä¸¦ã¹ã¦ã¦ããã¨ã¨ã©ã¼ç®æã«æ°ãä»ãã«ããInteger literal 'A***' overflows when stored into 'B***'
å
¥ãããã¨ãã¦ããæ´æ°å¤A***ã¯'B***'ã®åã«ã¯å¤§ãããã
【確èªver】Swift 4.0//Swift 3.0.2
var abc: UInt8 = 1000 //ã¨ã©ã¼
//Swift 3.0.2 64bitç°å¢ã§
var a = 9999999999999999999 //ã¨ã©ã¼
Intã®ç¯å²(ãã®å ´å64bit)ãè¶
ãã//4.0
for i in 0..<10000000000000000000{ //ã¨ã©ã¼
}
ã ãããã。Int64ã®ç¯å²å
ãªãOK。è¶
ããã¨ã¨ã©ã¼。//4.0
let n: Int8 = 6
let nn = n | 0xf0 //ã¨ã©ã¼
ãããæ¼ç®ã§ãæ°å¤ã¨ãã¦ã¿ãã¨ãã«ç¯å²overãªãã ã。Negative integer 'A***' overflows when stored into unsigned type 'B***'
å
¥ãããã¨ãã¦ããè² ã®æ°A***ã¯'B***'ã®åã«ã¯å
¥ãã¾ãã
【確èªver】Swift 3.0.2//Swift 3.0.2
var abc: UInt8 = -1 //ã¨ã©ã¼
Expected expression in assignment
代å
¥å¦çã§(æ£ãã)å¼ãæå¾
ããã
【確èªver】Swift 3.1//3.1
var abc: Int = 0
if abc == 3 {
abc =
} //ã¨ã©ã¼
ã¤ã³ã¼ã«ã®å¾ã§ä½ãæ¸ããã¨ããæ(ãã®å ´åã¯éãã«ãã³})ã§çºçããAssigning a variable to itself
èªåã«ä»£å
¥ãã¦ãã
【確èªver】Swift 3.0.2//Swift 3.0.2
var abc = 0
abc = abc
Cannot assign value of type 'A***' to type 'B***'
A***ã®å¤ãB***åã«ä»£å
¥ã§ãã¾ãã
【確èªver】Swift 3.0.2//Swift 3.0.2
let aTuple = (first: 1, second: 2, third:3)
var bTuple = (ichi: 1, ni: 2, san:3)
bTuple = aTuple //ã¨ã©ã¼
åãåãã¿ãã«ã§ãååãéã£ã¦ããã代å
¥ã§ããªã。//Swift 3.0.2
var a = 0
var b = 0
a =
b = 1 //ã¨ã©ã¼ Cannot assign value of type '()' to type 'Int'
aã«å¯¾ãã¦ã= 1ãæ¸ããªãã¨ãããªã。Cè¨èªã®ãããªè¤æ°ã®å¤ã«ä¸åº¦ã«ä»£å
¥ãããã®ã¯NG。//Swift 3.0.2
var array1 = [1, 2, 3]
array1[0..<1] = 0 //ã¨ã©ã¼
array1[0..<1] = [0]ãªãOK。ãã®å ´å追å ãããã®ã¯é
åã«ããªãã¨ãããªã。'=' must have consistent whitespace on both sides
=ã®ä¸¡ãµã¤ãã®ã¹ãã¼ã¹ã¯çµ±ä¸ããã¦ããå¿
è¦ããã。éãããªãéãã。éããªããªãéããªã。
【確èªver】Swift 3.1//3.1
var abc =5 //ã¨ã©ã¼
var def= 10 //ã¨ã©ã¼
Ambiguous use of '***'
ä¸ç¢ºããª'***'ã®ä½¿ããæ¹
【確èªver】Swift 3.0.2【èª】ambiguous ææ§ãª ä¸ç¢ºããª【解決ã«ææ³ãããã度】★★★★★ãããã®ãã¢ã¯ã»ã¹å¯è½ãªç¯å²å ã®2ç®æã§å®ç¾©ããã¦ãã¦、ã©ã¡ããå¼ã³åºãã°è¯ããããããªãã¨ããªã©ã«åºã。
//Swift 3.0.2
func funcB() {
}
func funcB() -> String {
return "RETURN"
}
class A {
func funcA() {
funcB() //ã¨ã©ã¼
}
}
ã©ã£ã¡ã®funcB()ãããããªã//Swift 3.0.2
func abc() -> Int {
return 0
}
func abc() -> String {
return "abc"
}
abc()
ã©ã£ã¡ã®abc()ãããããªã//Swift 3.1
let a = Int(pow(2, 2)) //ã¨ã©ã¼
powã®å¼æ°ã¯Doubleã¨Floatã¨CGFloatãããã®ã§Static member 'A***' cannot be used on instance of type 'B***'
staticãªã¡ã³ãA***ã¯B***åã®ã¤ã³ã¹ã¿ã³ã¹ã¨ãã¦ä½¿ãã¾ãã
【確èªver】Swift 3.1【ã³ã³ãã¤ã©ãå¤æãã¦ããã¦ãããããããªãã度】★★★ã¿ã¤ãå¤æ°ãã¤ã³ã¹ã¿ã³ã¹ã¡ã½ããå ã§ååãä»ããã«ä½¿ãã¨åºã。
//3.1
class SomeClass {
static var a: Int = 0
func testFunc() {
a = 10 //ã¨ã©ã¼
print(a) //ã¨ã©ã¼
}
static func testStaticFunc() {
a = 10 //ã¨ã©ã¼ãªã
print(a) //ã¨ã©ã¼ãªã
}
}
ã¤ã³ã¹ã¿ã³ã¹ã¡ã½ããå
ã§ã¿ã¤ãå¤æ°aã使ãã¨ãã¯SomeClass.aã¨ããã¨OKclass宣è¨ããå¤æ°ã«ããã®ã¡ãã»ã¼ã¸ãåºã。
Instance member 'A***' cannot be used on type 'B***'
ã¤ã³ã¹ã¿ã³ã¹ã¡ã³ãã®A***ã¯B***å(ã®ã¯ã©ã¹ã¡ã½ããå
)ã§ã¯ä½¿ãã¾ãã
【確èªver】Swift 3.1//3.1
class SomeClass {
var b: Int = 0
static func testStaticFunc() {
print(b) //ã¨ã©ã¼
}
}
ã¯ã©ã¹ã¡ã½ããã§ã¯ã¤ã³ã¹ã¿ã³ã¹å¤æ°ã¯ä½¿ããªã。Use of local variable '〜' before its declaration
'〜'ã¨ãããã¼ã«ã«å¤æ°ã宣è¨åã«ä½¿ããã¨ãã¦ãã
【確èªver】Swift 3.0.1//Swift 3.0.1
class A {
static var a = 0
static func aFunc() {
a = 1 //ã¨ã©ã¼
var a = 0
}
}
static var aã使ããã¯ãã§ããã、ä¸ã«var aã宣è¨ããã¦ããã®ã§、使ããã¨ãã¦ããã®ã¯ä¸ã®aã§ã¯ãªããã¨å¤æãã¦ãã? é¢ç½ãã¨ã©ã¼。Nil cannot be assigned to type '***'
nilã***ã«ä»£å
¥ã§ãã¾ãã
【確èªver】Swift 3.1//3.1
var a = "abc"
a = nil //ã¨ã©ã¼
nilãå
¥ãããªãoptionalåã«ããªãã¨ã ãInitialization of variable '***' was never used; consider replacing with assignment to '_' or removing it
å¤æ°ã®åæå(ãããå¤)ã¯ä½¿ããã¾ãã。åé¤ããã_ã使ã£ã¦ã¿ãã®ã¯ã©ãã§ãã?
【確èªver】Swift 3.1//3.1
var a = 0
Variable '***' was never used: consider replacing with '_' or removing it
å¤æ°***ã¯ä½¿ããã¾ãã。åé¤ããã_ã使ã£ã¦ã¿ãã®ã¯ã©ãã§ãã?
【確èªver】Swift 3.1//3.1
for var i in 0...10 {
}
Variable '***' was written to, but never read
å¤æ°***ã¯æ¸ããã¾ãããèªãã§ãã¾ãã。
【確èªver】Swift 3.1readã¯ãªã¼ã?ã¬ãã?neverã®å¾ã«ããã®ã§ãªã¼ã?ã¬ãããªãbe readã?
//3.1
for var j in 0...10 {
j = 0
}
åã®äºææ§、ãããã³ã«ã¸ã®æºæ
Cannot convert value of type 'A***' to specified type 'B***'
Aåã¯、Båã§æå®ããã¦ãããã®ã«å¤æã§ãã¾ãã
【確èªver】Swift 3.0.2//Swift 3.0.2
var abc: Int16 = 100
var abc2: Int8 = abc //ã¨ã©ã¼
æ°å¤å士ã®ç°ãªãåã¸ã®ä»£å
¥。Int8(abc)ã使ãã°OK。Int8ã®ç¯å²ãè¶
ãã¦ããå ´åã¯å®è¡æã¨ã©ã¼。//Swift 3.0.2
var abc: Int8 = 100
var abc2: Int16 = abc //ã¨ã©ã¼
大ããæ¹ã¸ã®å¤æãä¸å¯。Int16(abc)ã使ãã°OK。//Swift 3.0.2
var abc: Int = 3.1415 //ã¨ã©ã¼ãã
var abc8: Int8 = 3.1415 //ã¨ã©ã¼ãã
var abc16: Int16 = 3.1415 //ã¨ã©ã¼ãã
var abc32: Int32 = 3.1415 //ã¨ã©ã¼ãã
var abc64: Int64 = 3.1415 //ã¨ã©ã¼ãã
doubleãªãã©ã«è¡¨ç¾ããIntç³»ã¸ã®ä»£å
¥ãã ã//Swift 3.0.2
var a: Character = "aa" //ã¨ã©ã¼
var b: Character = "" //ã¨ã©ã¼
var c: Character = "a" //OK
var d: Character = 'a' //Single-quoted string literal found, use '"' ('ã®ä»£ããã«"ã使ã£ã¦ãã ãã)
Stringã¨Characterã®å¤æ//Swift 3.0.2
var abc:(Int, String) = (1, "A", 10) //ã¨ã©ã¼
var abc:(Int, String) = (1, 5) //ã¨ã©ã¼
ã¿ãã«ã®è¦ç´ éã//Swift 3.1
let rangeTest: CountableRange = 1.2...3.4 //ã¨ã©ã¼
Doubleã¯ã«ã¦ã³ã¿ãã«ã§ã¯ãªã。//Swift 3.1
func abc(a: Int...) {
let b: Int = a //ã¨ã©ã¼ Cannot convert value of type '[Int]' to specified type 'Int'
let c: [Int] = a //ã¨ã©ã¼ãªã
abc2(a: a) //ã¨ã©ã¼ Cannot convert value of type '[Int]' to expressed argument type 'Int'
abc3(a: a) //ã¨ã©ã¼ãªã
}
func abc2(a: Int) {
}
func abc3(a: [Int]) {
}
å¯å¤é·å¼æ°ã®æ±ãã¯é
åã§è¡ã。Cannot convert value of type 'A***' to expected argument type 'B***'
Aåã¯、æå¾
ããã¦ããBåã®å¼æ°ã«å¤æã§ãã¾ãã
【確èªver】Swift 3.0.2//Swift 3.0.2
class Oya {
}
class Ko: Oya {
}
func funcA(a: Ko) {
}
funcA(Oya()) //ã¨ã©ã¼
//Swift 3.0.2
func abc<T>(a: T, b: T) -> T {
return a
}
let c = abc(a: 0, b: "ã") //ã¨ã©ã¼
0ãããã®ã§、Tã¯Intã¨å¤æããã¦ããCannot convert value of type 'A***' to type 'B***' in coercion
Aåã¯、Båã«å¼·å¶å¤æã§ãã¾ãã
【確èªver】Swift 3.1【èª】coercion å¼·å¶//3.1
var abc: Int8 = 100
var abc2 = abc as Int16 //ã¨ã©ã¼
asã使ã£ã¦ã大ããæ¹ã¸ã®å¤æã§ãä¸å¯。as!ã使ã£ã¦ãè¦å(always fails)。Int16(abc)ã使ãã°OK。//3.1
var a: Double = 2.0
var b = a as Int
DoubleããIntã¸ã®aså¤æãä¸å¯、Int(a)ã使ãã°OK。Cannot convert value of type 'A***' to expected element type 'B***'
Aåã¯、æ³å®ãããBåã®è¦ç´ ã«å¤æã§ãã¾ãã
【確èªver】Swift 3.1//3.1
var abc: Array<Int> = [1, 2, "abc"] //ã¨ã©ã¼
é
åã®è¦ç´ ã¸ã®ä»£å
¥æCannot convert value of type 'A***' to expected dictionary value type 'B***'
Aåã¯、è¾æ¸ã®æ³å®ãããBåã®è¦ç´ ã«å¤æã§ãã¾ãã
【確èªver】Swift 3.1//3.1
var abc: Dictionary<String, Int> = ["abc":3, "def":"a"] //ã¨ã©ã¼
è¾æ¸ã®è¦ç´ ã¸ã®ä»£å
¥æ'A***' is not convertible to 'B***'
A***ãB***ã«å¤æã§ãã¾ãã
【確èªver】Swift 3.1//3.1
class Oya {
}
class Ko: Oya {
}
var a = Oya()
var b = a as Ko //ã¨ã©ã¼ 'Oya' is not convertible to 'Ko'; did you mean to use 'as!' to force downcast?
var c = Oya()
var d: Ko = c //ã¨ã©ã¼ Cannot convert value of type 'Oya' to specified type 'Ko'
var e = Ko()
var f = e as Oya //ã¨ã©ã¼ãªã
var g = Ko()
var h: Oya = g //ã¨ã©ã¼ãªã
//4.0
var abc:String = "Hello"
if abc { //ã¨ã©ã¼ 'String' is not convertible to 'Bool'
}
//4.0
let i = 1
if i { //ã¨ã©ã¼ 'Int' is not convertible to 'Bool'
}
nil is not compatible with expected argument type '***'
nilãã、æ³å®ãããå¼æ°ã®Intã«äºææ§ãããã¾ãã
【確èªver】Swift 3.1//3.1
func funcA(a: Int) {
}
funcA(a: nil) //ã¨ã©ã¼
Cast from 'A***' to unrelated type 'B***' always fails
A***ããé¢é£æ§ã®ãªãB***ã¸ã®ãã£ã¹ãã¯å¸¸ã«å¤±æãã¾ã
【確èªver】Swift 3.1//3.1
var a: Int = 5
var b = a as? Double //è¦å
var c = a as! Double //è¦å
//3.1
var a = 5
if a is Double { //è¦å
}
ã³ã¬ã¯ã·ã§ã³(Array、Dictionary)(é
å、è¾æ¸)
Variable/Constant '***' passed by reference before being initialized
'***'ã¯åæååã«åç
§ããã¾ãã
【確èªver】Swift 4.0//4.0
var abcArray: [String]
abcArray.append("a") //ã¨ã©ã¼
åæååã«è¦ç´ ã追å ãããã¨ããå ´å宣è¨æã«var abcArray: [String] = []ã¨ãããã¨ã§åæååºæ¥ã。ããã§è¨ãåæåã¯ã¤ã³ã¹ã¿ã³ã¹åã®æå³ã§ä½¿ããã¦ãã。
é åã«ã¯「宣è¨ããã ãã§åæåãã¦ããªãç¶æ 」ã¨、「åæåããç¶æ 」ãããã®ã§、åæåæ¸ã¿ãæèãããã¨ãå¿ è¦。
Expected '>' to complete generic argument list
ã¸ã§ããªãã¯ã®æå®ãªã¹ãã決å®ããããã®>ãå¿
è¦
【確èªver】Swift 4.0//4.0
var abc: Dictionary<String: Int> = ["abc":3, "def":4] //ã¨ã©ã¼
<String: Int>ã§ãªã<String, Int>ãæ£ããGeneric type 'Dictionary' specialized with too few type parameters (got 1, but expected 2)
è¾æ¸åã®ã¸ã§ããªãã¯ãå°ãªããã©ã¡ã¼ã¿ã§æå®ããã¦ãã(2ã¤å¿
è¦ãªã®ã«1ã¤ãããªã)
【確èªver】Swift 4.0//4.0
var abc: Dictionary<Int> //ã¨ã©ã¼
Expected ':' in dictionary literal
è¾æ¸è¡¨ç¾ã§:ãå¿
è¦
【確èªver】Swift 4.0//4.0
var dict = [
"a": 1,
"b": 2,
3,4,5,6 //ã¨ã©ã¼
]//ã¨ã©ã¼
Mutating method 'append' may not be used on immutable value '***'
å¤æ´ããã¡ã½ããã®appendã¯å¤æ´ã§ããªãå¤ã«ã¯ä½¿ãã¾ãã
【確èªver】Swift 4.0//4.0
class ABC {
let abcArray: [Int]
init() {
abcArray = []
abcArray.append(5) //ã¨ã©ã¼
}
}
letå¤æ°ã®åæåè¨å®ãinit()ã®ä¸ã§2å以ä¸è¡ãããã©ããã¯ãã¼ã¸ã§ã³ã«ãã£ã¦è¿·ãããã、ãã®ä¾ã®ãããªæ¸ãæ¹ã許å¯ãããã¼ã¸ã§ã³ããã£ã。Swift1.2ã§ã¯ç¦æ¢ããã¦ãã。対å¿ã¯、varå¤æ°ã«ããã、ä¸è¡ã§åæåãè¡ããã«ãã。
Reference to generic type 'Array' requires arguments in <...>
ã¸ã§ããªãã¯ã¿ã¤ãã®Arrayã¸ã®åç
§ã¯<...>ã®ä¸èº«ãå¿
è¦
【確èªver】Swift 4.0//4.0
var contents: Array //ã¨ã©ã¼
var contents2: Array<String>// ã¨ã©ã¼åºãªã
Contextual type '***' cannot be used with array literal
é
å表ç¾ã¨æèä¸ã®***åã¯ä¸ç·ã«ä½¿ãã¾ãã
【確èªver】Swift 3.1【èª】Contextual æèä¸ã® æèããã® èæ¯ã® èæ¯çãªæ¼ ç¶ã¨ããã¡ãã»ã¼ã¸ãªã®ã§ããç¨åº¦ã¨ã©ã¼åå ãæ¨æ¸¬ãããã¨ãå¿ è¦ã。
//4.0
func variableFunc(a: Int, b: Int...) {
}
func testFunc() {
variableFunc(a: 4, b: [4, 4]) //ã¨ã©ã¼
}
b: 4, 4ã¨ããã¨OK//3.1
var a = [1,2,3]
a[1] = [10,11,12] //ã¨ã©ã¼
é
åã®è¦ç´ ã®ç½®ãæãã¯、左辺ã、é
åå[ç¯å²]ã§æå®ãããã¨。ãã®å ´å、a[1...1]ã¨ããã¨ãã。//3.1
func abc(a: Int...) {
print("a")
}
abc(a: [1,2,3,4,5]) //ã¨ã©ã¼
å¯å¤é·å¼æ°ã«æ¸¡ãã¨ãã¯é
åã«ããªãã§ãã©ã§æ¸¡ã。Heterogeneous collection literal could only be inferred to '***'; add explicit type annotation if this is intentional
ã³ã¬ã¯ã·ã§ã³ã®è¡¨ç¾ã、ç°ãªããã®ãæ··ãã£ããã®ã§ããå ´å、***ã¨æ¨æ¸¬ããã¾ã。ãããæå³ãããã®ã§ããå ´å、æ確ãªåã®æå®ãå ãã¦ãã ãã。
【確èªver】Swift 3.0.1【èª】Heterogeneous ç°ç¨®ã®***ã«ã¯[Any]ãå ¥ããã¨ãå¤ã。
//Swift 3.0.1
let a = [ //ã¨ã©ã¼
"first" : 1,
"second" : "ããã"
]
[String : Any]ãã¯ã£ããã¨æå®ããã¨OK。//3.1
let a = [1, "a"]
[Any]ãã¯ã£ããã¨æå®ããã¨OK。Ambiguous reference to member 'subscript'
subscriptã¨ããã¡ã³ãã¼ã¸ã®ææ§ãªåç
§
【確èªver】Swift 3.0.1【èª】Ambiguous ææ§ãª//Swift 3.0.1
let myParagraph = NSMutableParagraphStyle()
myParagraph.alignment = .center
let myFontAttributes: [String : AnyObject] = [
NSParagraphStyleAttributeName : myParagraph
]
myFontAttributes[NSParagraphStyleAttributeName].alignment = .left //ã¨ã©ã¼
myFontAttributes[NSParagraphStyleAttributeName]?.alignment = .leftã§ãã¨ã©ã¼。
(myFontAttributes[NSParagraphStyleAttributeName] as? NSMutableParagraphStyle)?.alignment = .left
ã«ããã¨ã¨ã©ã¼ã¯åºãªãã、ããå°ãã·ã³ãã«ãªæ¹æ³ããããããªæ°ããã。
'+' is unavailable: Operator '+' cannot be used to append a String to a sequence of strings
+ã¯ä½¿ãã¾ãã。+æ¼ç®åã¯StringãStringã·ã¼ã±ã³ã¹ã«è¿½å ããã®ã«ä½¿ãã¾ãã。
【確èªver】Swift 4.0//Swift 4.0
var lunch = ["hamburger", "potato", "cola"] + "cheeseburger" //ã¨ã©ã¼
ã»ããã«ååããã©ã¹ã¯åºæ¥ãªã。lunch.append("cheeseburger")ã使ãã¨å¯è½。
é¢æ°(function)、ã¡ã½ãã(method)
Extra argument in call
å¼æ°ãå¤ããã
【確èªver】Swift 3.0.2é¢æ°、ã¡ã½ããã®å®è¡æã§å¼æ°ãå¤ãããã¨ãã«åºã。
//Swift 3.0.2
func abc(a: Int) {
}
let a = 3
let b = 3
abc(a: a, b) //ã¨ã©ã¼
Expression resolves to an unused function
使ãããªãé¢æ°ã¨ãã¦å¤æãã¾ãã
【確èªver】Swift 3.0.2//Swift 3.0.2
print
//Swift 3.0.2
func testValArg(a: Int...) {
}
testValArg(a: ) //ã¨ã©ã¼
å¯å¤é·å¼æ°ã«æ¸¡ãå¼æ°ã0åã®ã¨ãã¯å¤é¨å¼æ°åããããªã。Missing argument for parameter '***' in call
ãã©ã¡ã¼ã¿'***'ã¨ããå¼æ°ãããã¾ãã
å¼ã³åºãæã§å¼æ°ã足ããªã。'***'ã¯#1ãªã©ã¨æ¸ããã。ããã¯1çªç®ã®å¼æ°ã®æå³ãã¨æããã。【確èªver】Swift 3.0.2
//Swift 3.0.2
class Oya {
init(a: Int) {
}
}
class Ko: Oya {
init() {
super.init()
}
}
親ã¯ã©ã¹ã§init(abc: Int)ããå®ç¾©ãã¦ããªãã®ã«åã¯ã©ã¹ããsuper.init()ã¨å¼ã³åºãã//Swift 3.0.2
func aFunc(a: Int) {
}
aFunc() //ã¨ã©ã¼
å¼æ°ãå¿
è¦ãªé¢æ°ã、å¼æ°ãä¸ããã«å¼ã³åºãã。//Swift 3.1
func aFunc(a: Int = 0) -> Bool {
return true
}
let a = aFunc() //OK
print(a) //true
let bFunc = aFunc
let b = bFunc() //ã¨ã©ã¼
print(b)
ããã©ã«ããå¹ããªã。Missing argument label '***':in call
å¼æ°ã©ãã«ã®'***'ãããã¾ãã
【確èªver】Swift 3.0.2é¢æ°ã®å®ç¾©ãªã©ã§å¼æ°ã«ã©ãã«ãä»ãã¦ãã(è¦æ±ãã¦ãã)ã、å¼ã³åºãå´ã§ã¯æ¸ããã¦ããªã。ã³ã³ã¹ã¹ãã©ã¯ã¿å¼ã³åºãã§ãåæ§ã®ç¶æ³ã§åºã¾ã。
//Swift 3.0.2
class ABC {
func abcFunc(a: Int, b: Int){
}
}
var abc: ABC = ABC()
abc.abcFunc(4, 1) //ã¨ã©ã¼
ã©ãã«ãå¿
è¦Extraneous argument label '***:' in call
å¼ã³åºãæã§ä½è¨ãªã©ãã«'***:'
【確èªver】Swift 3.0.2【èª】extraneous ç¡é¢ä¿ã®、ç°è³ªã®//Swift 3.0.2
func func123(a: Bool, _ b: Bool, _ c: Bool, _ d: Bool) {
//ä½ãã®å¦ç
}
func123(a:true, b: true, c: true, d: true) //ã¨ã©ã¼
ã©ãã«çç¥æ¹å¼ã§å®ç¾©ããã¦ãããã®//Swift 3.0.2
func testFunc(a: Int) {
print("a")
}
let delayFunc: (Int) -> Void = testFunc(a: )
delayFunc(a: 0) //ã¨ã©ã¼
let clo = {
(a: Int) -> Bool in
if a == 0 {
return true
} else {
return false
}
}
let result = clo(a: 1) //ã¨ã©ã¼
ãã®å ´åã¯delayFuncãcloã®å®è¡æã®å¤é¨å¼æ°åããããªããããª。Incorrect argument label in call (have '***', expected '***')
å¼æ°ã®ã©ãã«ãééã£ã¦ãã。expected以ä¸ãæ±ãããã¦ãããã®。
【確èªver】Swift 4.0//4.0
var a = ABC()
a.abcFunc(a: 3, b: 5) //ã¨ã©ã¼
class ABC {
func abcFunc(aa a: Int, bb b: Int){
}
}
aaã¨bbãæå®ãã¦ããã®ã§ããã使ããªãã¨ãããªã。'&' used with non-inout argument of type '***'
&ãéinoutã®***åã®å¼æ°ã«ä½¿ããã¦ãã¾ã
【確èªver】Swift 4.0//4.0
func abc(a: Int) {
}
let a = 3
abc(&a) //ã¨ã©ã¼
Single argument function types require parentheses
é¢æ°ã®å¼æ°ãã²ã¨ã¤ã®ã¨ãã§ã()ãå¿
è¦
【確èªver】Swift 3.1//3.1
func abc(a: Int -> Int) {
}
(Int) -> Intã«ãã¾ããã。Expected '{' in body of function declaration
é¢æ°ã®å®ç¾©ã«{ãããã¾ãã
【確èªver】Swift 4.0//4.0
public func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int //ã¨ã©ã¼
protocolã®å®ç¾©ããå®è£
é¨ã«ã³ãã¼ã¢ã³ããã¼ã¹ãããã ãã®ç¶æ
//4.0
func abc () String { //ã¨ã©ã¼
return "a"
}
Stringã®åã«->ããªãMissing return in a function expected to return '***'
***ãè¿ãé¢æ°ãªã®ã«、æ»ãå¤ããªã
【確èªver】Swift 4.0//4.0
func aFunc() -> Int {
} //ã¨ã©ã¼
Intåã®å¤ãreturnããªãã¨ãããªã//4.0
class A {
var a: Int {
get { b * b } //ã¨ã©ã¼
}
var b: Int = 0
}
returnãå¿
è¦。//4.0
class A {
var a: Int {
b * b
} //ã¨ã©ã¼
var b: Int = 0
}
returnãå¿
è¦。Unexpected non-void return value in void function
å¤ãè¿ããªãé¢æ°å
ã§æ»ãå¤ãæ¸ããã¦ãã
【確èªver】Swift 4.0//4.0
func aFunc() {
return 0 //ã¨ã©ã¼
}
//4.0
func abc() {
return nil //ã¨ã©ã¼
}
return nilãæ¸ããæããã®ã¨ã©ã¼ã¡ãã»ã¼ã¸ã«ãªãCannot convert return expression of type 'A***' to return type 'B***'
æ»ãå¤ã¨ãã¦æ¸ããã¦ããA***åã¯、æ¬æ¥ã®æ»ãå¤ã§ããB***åã«å¤æåºæ¥ã¾ãã
【確èªver】Swift 4.0æ»ãå¤ã®åãéã。
//4.0
func aFunc() -> Int {
return "ãã©ã" //ã¨ã©ã¼
}
Static properties may only be declared on a type
staticããããã£ã¯åã®ããããã£ã«ã®ã¿å®£è¨åºæ¥ã¾ã
【確èªver】Swift 3.0.2//Swift 3.0.2
func staticTestFunc() {
static var abc = 0 //ã¨ã©ã¼
}
é¢æ°/ã¡ã½ããå
ã®å¤æ°ã«staticãã¤ãã。é¢æ°/ã¡ã½ããå ã§ä¿æããå¤ãã©ã宣è¨ããã°ãããã¯è¦èª¿æ»。→ã©ãããCè¨èªã®é¢æ°å staticã«ããããã®ã¯ãªã模æ§。
//Swift 3.0.2
//ãããã¬ãã«ã§
static var abc: Int = 0 //ã¨ã©ã¼
Cannot invoke '***' with an argument list of type '(***, ***)'
ä¸ããããå¼æ°ã®çµã¿åããã§ã¯é¢æ°ãå®è¡åºæ¥ãªã
【確èªver】Swift 4.0【èª】invoke (ããã°ã©ã ãªã©ã)å¼ã³åºã//4.0
abs(1,2) //ã¨ã©ã¼
Cannot invoke '***' with no arguments
å¼æ°ãªãã§ã¯é¢æ°ãå®è¡åºæ¥ãªã
【確èªver】Swift 4.0【èª】invoke (ããã°ã©ã ãªã©ã)å¼ã³åºã//4.0
abs() //ã¨ã©ã¼
Argument passed to call that takes no arguments
å¼æ°ãæããªãé¢æ°/ã¡ã½ããã«å¼æ°ã渡ããã¾ãã
【確èªver】Swift 3.0//Swift 3.0
func testFuncA() {
}
testFuncA(a: 100)//ã¨ã©ã¼
Only a single variadic parameter '...' is permitted
å¯å¤é·å¼æ°ã«åºæ¥ãã®ã¯ã²ã¨ã¤ã ãã§ã
【確èªver】Swift 3.0.2//Swift 3.0
func testValArgFunc(a: Int..., b: Int...) { //ã¨ã©ã¼
}
2ã¤ãã£ã¦ã¯ã ã。Result of call to '***' is unused
***ãå¼ãã çµæã使ããã¦ãã¾ãã
【確èªver】Swift 3.0.2//Swift 3.0.2
abc() //ã¯ã¼ãã³ã°
func abc() -> Int {
return 1234
}
çµæã使ããã¦ããªã。çµæã¨ã¯ã¡ã½ããã®æ»ãå¤ã®ãã¨ã§、ãã®å ´åã¯Intã®1234çµæã使ããªãå ´åã¯
_ = abc()
ã¨ããã¨ã¯ã¼ãã³ã°ãæ¶ãã。
ã¯ã©ã¹ã¨æ§é ä½
Value of type 'A***' has no member 'B***'
Aã¯Bã¨ããã¡ã³ããæã£ã¦ãã¾ãã
【確èªver】Swift 3.1//3.1
//ã¯ã©ã¹ã®å®ç¾©
class ABC {
var a = 0
}
//å¼ã³åºãé¨
var a = ABC()
var b = a.b //ã¨ã©ã¼
åå¨ããªãã¡ã³ã(b)ã«ã¢ã¯ã»ã¹ããã¨ãã«åºã。//3.1
//ã¯ã©ã¹ã®å®ç¾©
class ABC {
var a = 0
}
//å¼ã³åºãé¨
var a = ABC()
a.someMethod() //ã¨ã©ã¼
åå¨ããªãã¡ã½ãããå¼ã³åºããã¨ããã¨ãã«ãåºã。Class '***' has no initializers
***ã¯ã¤ãã·ã£ã©ã¤ã¶ãæã£ã¦ãã¾ãã
【確èªver】Swift 3.1class ABC { //ã¨ã©ã¼
var a: Int
}
åæå¤ãä¸ããã°æ¶ãã¾ã。ã¾ã、ååã®å¾ãã«!ã?ãã¤ããã°ãã®ã¨ã©ã¼ã¯æ¶ãã¾ã。ãã®ããæ¹ã¯åæåããªãã·ã§ã³åãç解ãã¦ããªãã¨å±éº。
Method does not override any method from its superclass
(ãã®ããæ¹ã§ã¯)ã¹ã¼ãã¼ã¯ã©ã¹ã®ã¡ã½ããã«ãªã¼ãã¼ã©ã¤ãåºæ¥ããã®ã¯ããã¾ãã
【確èªver】Swift 3.1ã¡ã½ããããªã¼ãã¼ã©ã¤ããããã¨ããã¨ãã«、ã¹ã¼ãã¼ã¯ã©ã¹ã«ãã®ã¡ã½ããããªãã、å¼æ°ãæ»ãå¤ã®çµã¿åãããéãã、å¿ è¦ãªã¹ã¼ãã¼ã¯ã©ã¹ã®ç¶æ¿ãåºæ¥ã¦ããªã。
//3.1
class Oya {
func aFunc() {
}
}
class Ko: Oya {
override func aFunc(a: Int) { //ã¨ã©ã¼
}
}
//3.1
class ClassExtensionTest {
func funcExtensionTest() {
}
}
extension ClassExtensionTest {
override func funcExtensionTest() { //ã¨ã©ã¼
}
override func funcExtensionTest2() { //ã¨ã©ã¼
}
}
extensionã§ã¯æ¢åã®ãã®ãåå®ç¾©åºæ¥ãªãã、æ°è¦ã®ãã®ã¯overrideã¤ããªãã¦ãã。Property does not override any property from its superclass
(ãã®ããæ¹ã§ã¯)ã¹ã¼ãã¼ã¯ã©ã¹ã®ããããã£ã«ãªã¼ãã¼ã©ã¤ãåºæ¥ããã®ã¯ããã¾ãã
【確èªver】Swift 3.1ããããã£ããªã¼ãã¼ã©ã¤ã(ã¤ã¾ãæ¼ç®ããããã£ã®get setã§ä¸æ¸ããããã¨ãã¦ãã)ãããã¨ããã¨ãã«、ã¹ã¼ãã¼ã¯ã©ã¹ã«ãã®ããããã£ããªãã、å¿ è¦ãªã¹ã¼ãã¼ã¯ã©ã¹ã®ç¶æ¿ãåºæ¥ã¦ããªã。
//3.1
class Oya {
var a: Double = 0.0
}
class Ko: Oya {
override var b: Double {
get {
return a / 1000.0
}
set {
a = newValue * 1000.0
}
}
}
'super' members cannot be referenced in a root class
'super'ã¯ã«ã¼ãã¯ã©ã¹ã§ã¯åç
§ããã¾ãã
【確èªver】Swift 4.0å®è¡ããã¯ã©ã¹ã¯ã«ã¼ãã¯ã©ã¹(親ã¯ã©ã¹ããããªã)ã«ãªã£ã¦ãã。
//4.0
class Ichininmae {
func aFunc() {
super.aFunc() //ã¨ã©ã¼
}
}
'***' can only be specified on class members
***ã¯ã¯ã©ã¹ã¡ã³ãã«å¯¾ãã¦ã®ã¿、ã¤ãããã¨ãåºæ¥ã¾ã
【確èªver】Swift 3.1***ã®å¯¾è±¡ã¨ãªãã®ã¯override
//3.1
//ãããã¬ãã«ã§
override func aFunc() { //ã¨ã©ã¼
}
æ¸ããã¦ããã¨ãããã¯ã©ã¹ã®å®ç¾©ã®å¤å´'***' cannot be used outside of class members
***ã¯ã¯ã©ã¹ã¡ã³ãã®å¤ã§ã¯ä½¿ãã¾ãã
【確èªver】Swift 3.1æ¸ããã¦ããã¨ãããã¯ã©ã¹ã®å®ç¾©ã®å¤å´
***ã«å½ã¦ã¯ã¾ãã®ã¯super
//3.1
//ãããã¬ãã«ã§
func abc(a: Int) {
super.someFunc()
}
Keyword 'init' cannot be used as an identifier here
initãã¼ã¯ã¼ãã¯ããã§èå¥åã¨ãã¦ä½¿ãã¾ãã
【確èªver】Swift 4.0//4.0
class A {
func init() {
}
}
initã«funcãã¼ã¯ã¼ããã¤ãã。initã«ã¯funcã¯ãããªã。funcãã¤ããããã§funcã®å¾ã«init以å¤ã®ååãè¦æ±ãã¦ãã。Expected '(' in argument list of function declaration
é¢æ°ã®å®£è¨ã®å¼æ°ã®ãªã¹ãã§(ãæå¾
ããã
【確èªver】Swift 4.0å¼æ°ã®ãªã¹ãã¯()ã®ä¸ã«æ¸ã。å¼æ°ããªãã¦ã()ã¯æ¸ãäº。
//4.0
func aFunc { //ã¨ã©ã¼
}
()ãå¿ããFound an unexpected second identifier in function declaration; is there an accidental break?
é¢æ°ã®å®£è¨ã§2ã¤ãã®èå¥åãè¦ã¤ããã¾ãã。空ç½ãå
¥ã£ã¦ãã¾ããã?
【確èªver】Swift 4.0//4.0
func override abc() { //ã¨ã©ã¼
}
overrideã®å ´æãéã。overrideã¯ãã®å ´å、å
é ã«ãã。funcãããããã§overrideãé¢æ°åã¨è§£éãããã¨ãã。//4.0
func mutating change() { //ã¨ã©ã¼
}
mutatingã®å ´æãéã。mutatingã¯ãã®å ´å、å
é 。funcãããããã§mutatingãé¢æ°åã¨è§£éãããã¨ãã。Consecutive declarations on a line must be separated by ';'
Expected '{' in body of function declaration
Expected '(' in argument list of function declaration
ä¸è¡ã«é£ç¶ãã¦å®£è¨ãæ¸ãæã¯;ã§åºåã£ã¦ä¸ãã
é¢æ°ã®å®£è¨ã§{ãæå¾
ããã
é¢æ°ã®å®£è¨ã®å¼æ°ã®ãªã¹ãã§(ãæå¾
ããã
【確èªver】Swift 4.0func override init() {
}
init()ã«ã¯funcããããªã。funcãããããã§overrideãé¢æ°åã¨è§£éãããã¨ãã。'mutating' isn't valid on methods in classes or class-bound protocols
mutatingã¯ã¯ã©ã¹ã®ã¡ã½ããã«ä½¿ãã¾ãã(structãenumã®ã¡ã½ããã«ä½¿ããã®ã§ã)
【確èªver】Swift 4.0//4.0
class A {
mutating func aFunc() { //ã¨ã©ã¼
}
}
Cannot assign to property: '***' is a 'let' constant
ããããã£ã«ä»£å
¥ãããã¨ã¯åºæ¥ã¾ãã。***ã¯å®æ°ã§ã。
【確èªver】Swift 4.0//4.0
class A {
let a: Int = 0
func funcA() {
a = 0 //ã¨ã©ã¼
}
}
å¤ãå
¥ãããã¨ãã¦ããã¡ã³ããletã§å®£è¨ãã¦ãã//4.0
let abc = (1, "A")
abc.1 = "B" //ã¨ã©ã¼
abcãletãªã®ã§ãã®è¦ç´ ãå¤æ´ã¯ã ã//4.0
class Oya {
let a: Int
init() {
a = 0
}
}
class Ko: Oya {
override init() {
super.init()
a = 1
}
}
letã§å®£è¨ãã¦ããå®æ°ã®åæåããµãã¯ã©ã¹ã®ã¤ãã·ã£ã©ã¤ã¶ã¼ã§è¡ããã¨ãã¦ãã//4.0
struct AStruct {
var a: Int = 0
}
func testFunc() {
let aStruct = AStruct()
aStruct.a = 1 //ã¨ã©ã¼
}
æ§é ä½ãlet宣è¨ã®å ´å、ãã®ã¡ã³ãå¤æ°ãletæ±ã。(æ§é ä½ã§ãªãã¯ã©ã¹ã®let宣è¨ã®å ´åã¯ã¡ã³ãå¤æ°ã®å¤æ´ã¯å¯è½)Cannot assign to property: '***' is a get only property
ããããã£ã«ä»£å
¥ãããã¨ã¯åºæ¥ã¾ãã。***ã¯èªã¿è¾¼ã¿å°ç¨å¤æ°ã§ã。
【確èªver】Swift 4.0//4.0
class AAA {
var a: Int {
get {
return 5
}
}
}
var aaa = AAA()
aaa.a = 3//ã¨ã©ã¼
Cannot use mutating member on immutable value: '***' is a 'let' constant
å¤æ´åºæ¥ãªãå¤ã®***ã®mutatingã¡ã³ãã使ããã¨ã¯åºæ¥ã¾ãã。***ã¯letå®æ°ã§ã。
【確èªver】Swift 4.0//4.0
struct StructA {
var a: Int = 0
mutating func funcA() {
a = a + 1
}
}
let strA = StructA()
strA.funcA() //ã¨ã©ã¼
æ§é ä½Aãèªèº«ã®å¤ãå¤æ´ããmutatingä»ãã®ã¡ã½ããBãæã¤ã¨ã、let宣è¨ãããã®æ§é ä½Aã®ã¤ã³ã¹ã¿ã³ã¹ãããã®ã¡ã½ããBãå¼ã³åºãã¨åºã。Cannot use mutating member on immutable value of type '[***]'
å¤æ´åºæ¥ãªãå¤ã®[***]ã®mutatingã¡ã³ãã使ããã¨ã¯åºæ¥ã¾ãã
【確èªver】Swift 4.0//4.0
let lunch = ["hamburger", "potato", "cola"].append("cheeseburger") //ã¨ã©ã¼
//OK
var lunch = ["hamburger", "potato", "cola"]
lunch.append("cheeseburger")
'class var' declaration requires an initializer expression or getter/setter specifier
classä»ãã¯ã©ã¹å¤æ°ã®å®£è¨ã§ã¯åæåå¦çã、getter/setterãæ±ãããã¾ã
【確èªver】Swift 4.0æ¼ç®ããããã£ã®å ´åã¯classã§ããã、ã¹ãã¢ãããããã£ã®å ´åã¯staticãç¨ããã¹ã(classã¨staticã®éããçºçããªãã®ã§ä½¿ç¨ããã®ã¯staticã®ã¿)。
//4.0
class SomeClass {
class var classProperty: Int { //ã¨ã©ã¼
}
}
æ¼ç®ããããã£ãã¹ãã¢ãããããã£ãã©ã£ã¡ã«ãã¦ãä¸éå端ãªç¶æ
'static var' declaration requires an initializer expression or getter/setter specifier
staticä»ãã¯ã©ã¹å¤æ°ã®å®£è¨ã§ã¯åæåå¦çã、getter/setterãæ±ãããã¾ã
【確èªver】Swift 4.0//4.0
class SomeClass {
static var classProperty: Int //ã¨ã©ã¼
}
åæå¤ãä¸ããã°ã¨ã©ã¼ãæ¶ãã//4.0
class SomeClass {
static var classProperty: Int { //ã¨ã©ã¼
}
}
æ¼ç®ããããã£ãã¹ãã¢ãããããã£ãã©ã£ã¡ã«ãã¦ãä¸éå端ãªç¶æ
Class stored properties not supported in classes; did you mean 'static'?
class(æå®åãã¤ãã)ã¹ãã¢ãããããã£ã¯ãµãã¼ãããã¦ãã¾ãã。static(ããã¯ä½¿ç¨å¯)ã®ã¤ããã§ãã
【確èªver】Swift 4.0//4.0
class SomeClass {
class var classStoredProperty: Int = 0 //ã¨ã©ã¼、staticãªãOK
class var classComputedProperty: Int { //ã¨ã©ã¼、getãsetã®ä¸èº«ãæ¸ãã°OK
}
}
classStoredPropertyã¯ã¹ãã¢ãããããã£ã«classãä»ãã¦ããã®ã§ã¨ã©ã¼classComputedPropertyã¯getter/setterããªãã®ã§ã¹ãã¢ãããããã£ã®å¯è½æ§ãããã¨å¤æããã¦ã¨ã©ã¼
Cannot assign to 'self' in a method
ã¡ã½ããå
ã§selfã«ä»£å
¥ãããã¨ã¯åºæ¥ã¾ãã
【確èªver】Swift 4.0//4.0
class ClassA {
func funcA() {
self = ClassA() //ã¨ã©ã¼
}
}
Cannot assign to property: 'self' is immutable
ããããã£ã«ä»£å
¥ãããã¨ã¯åºæ¥ã¾ãã。selfã¯å¤æ´åºæ¥ã¾ãã。
【確èªver】Swift 4.0//4.0
struct ABC{
var a: Int
var b: Int
func change(){
let c = a
a = b //ã¨ã©ã¼
b = c //ã¨ã©ã¼
}
}
æ§é ä½ã®å®ç¾©ã®ä¸ã§æ§é ä½ã®è¦ç´ ã«ä»£å
¥ãã¦ããfuncã®åã«mutatingãã¤ããã°OK
Initializer åæåã¡ã½ãã
Return from initializer without initializing all stored properties
ãã¹ã¦ã®æ ¼ç´ããããã£ã®åæå¤è¨å®ãå®äºããªãã¾ã¾åæåã¡ã½ãããçµãããã¨ãã¦ãã¾ã(åºæ¥ã¦ããªããã®ãã²ã¨ã¤ã¯ãã)
【確èªver】Swift 3.1//3.1
class ABC {
var abc: Int
init(){
}
}
abcã®åæå¤ãå
¥ãã¦ããªã。対å¿ã¯、宣è¨æã«=0ããã、init()ã®ä¸ã§abc = 0ãªã©ããã。
Cannot use optional chaining on non-optional value of type '() -> ***?'
() -> ***?ã¨ããéãªãã·ã§ãã«ã¿ã¤ãã«ãªãã·ã§ãã«ãã§ã¤ãã³ã°ã使ããã¨ã¯åºæ¥ã¾ãã
【確èªver】Swift 3.1//3.1
class ABC {
init? () {
return nil
}
}
class DEF: ABC {
override init? () {
super.init?() //ã¨ã©ã¼
return nil
}
}
失æã®å¯è½æ§ã®ããã¤ãã·ã£ã©ã¤ã¶init?ãå®ç¾©ãã¦、ããããµãã¯ã©ã¹ããå¼ã¶ã¨ãã«init?ã®ããã«?ãã¤ãã¦å¼ãã§ãã¾ã£ãæã«åºã。å¼ã¶ã¨ãã«ã¯?ã¯ãããªã。Failable initializer 'init()' cannot override a non-failable initializer
失æã®å¯è½æ§ã®ããã¤ãã·ã£ã©ã¤ã¶'init()'ã§å¤±æã®å¯è½æ§ã®ç¡ãã¤ãã·ã£ã©ã¤ã¶ããªã¼ãã¼ã©ã¤ããããã¨ã¯åºæ¥ã¾ãã
【確èªver】Swift 3.1//3.1
class ABC {
init () {
}
}
class DEF: ABC {
override init?() { //ã¨ã©ã¼
super.init()
}
}
ã¡ãã»ã¼ã¸ã¯init?()ã¨?ä»ãã«ããã»ããããããããã§ããã©A non-failable initializer cannot chain to failable initializer 'init(***)' written with 'init?'
失æã®å¯è½æ§ã®ç¡ãã¤ãã·ã£ã©ã¤ã¶init(***)ãã、init?ã§æ¸ããã失æã®å¯è½æ§ã®ããã¤ãã·ã£ã©ã¤ã¶ãå¼ã¶ãã¨ã¯åºæ¥ã¾ãã
【確èªver】Swift 3.1//3.1
class ABC {
init? () {
return nil
}
}
class DEF: ABC {
override init () {
super.init() //ã¨ã©ã¼
}
}
'required' modifier must be present on all overrides of a required initializer
required initializerããªã¼ãã¼ã©ã¤ãããéã¯、'required'修飾èªãä»ããªãã¨ãããªã
【確èªver】Swift 4.0requiredãä»ããã¤ãã·ã£ã©ã¤ã¶ã¯ãµãã¯ã©ã¹ãä½ã£ãéã«å®è£ (ãªã¼ãã¼ã©ã¤ã)ããªãã¨ãããªã。ããã¦、次ã®ãµãã¯ã©ã¹ã§ãå®è£ ãããããã«ãããã¾ãrequiredãã¤ããªãã¨ã ã。
//4.0
class ABC {
required init() {
}
}
class DEF: ABC {
init() { //ã¨ã©ã¼
}
}
Use the 'required' modifier to override a required initializer
requiredãä»ããã¤ãã·ã£ã©ã¤ã¶ããªã¼ãã©ã¤ãããã¨ãã¯requiredãä»ãããã¨
【確èªver】Swift 4.0//4.0
class ABC {
required init() {
}
}
class DEF: ABC {
override init () { //ã¨ã©ã¼
}
}
overrideãä»ããã¨ãã«åºã。overrideã§ã¯ãªãrequiredãä»ããªãã¨ã ã。'required' may only be used on 'init' declarations
requiredã¯initã«ãã使ãã¾ãã
【確èªver】Swift 4.0//4.0
class ABC {
required func abcFunc() { //ã¨ã©ã¼
}
}
'self' used before all stored properties are initialized
å
¨ã¦ã®ã¹ãã¢ãããããã£ãåæåãããåã«、selfã使ããã¦ãã¾ã
【確èªver】Swift 4.0//4.0
class A {
let aa: AA!
init() {
self.aa = AA(a: self) //ã¨ã©ã¼
}
}
class AA {
unowned let a: A
init(a: A) {
self.a = a
}
}
Initializers may only be declared within a type
åæåã¡ã½ããã¯åã®ä¸ã«ã®ã¿ã§å®£è¨åºæ¥ã¾ã
【確èªver】Swift 4.0//4.0
init() {
}
ãããã¬ãã«ã«init(){}ãæ¸ãã//4.0
class A {
func abc() {
init() {
}
}
}
é¢æ°ã®ä¸ãªã©æ¸ãã¹ãã§ãªãã¨ããã§init(){}ãæ¸ããMissing 'self.' at initializer invocation
ä»ã®åæåã¡ã½ããå¼ã³åºãã§self.ãæãã¦ãã
【確èªver】Swift 4.0//4.0
class A {
convenience init(a: Int) {
init()
}
init() {
}
}
self.init()ã®self.ãæãã¦ããå ´åMissing 'super.' at initializer invocation
ä»ã®åæåã¡ã½ããå¼ã³åºãã§super.ãæãã¦ãã
【確èªver】Swift 4.0//4.0
class A {
init(a: Int) {
init() //ã¨ã©ã¼
}
init() {
}
}
super.init()ã®super.ãæãã¦ããå ´åã、convenienceã¨self.ãæãã¦ããå ´å。Designated initializer for 'A***' cannot delegate (with 'self.init'); did you mean this to be a convenience initializer?
A***åã®æå®ã¤ãã·ã£ã©ã¤ã¶ã¼ã¯self.initãå¼ã¶ãã¨ãåºæ¥ã¾ãã。ãããããã¨ã¯ã³ã³ããã¨ã³ã¹ã¤ãã·ã£ã©ã¤ã¶ã¼ã«ãããã¨ã§åºæ¥ã¾ããã?
【確èªver】Swift 4.0åãåã®ä¸ã§æå®ã¤ãã·ã£ã©ã¤ã¶ã¼ããæå®ã¤ãã·ã£ã©ã¤ã¶ã¼ãå¼ã¶ãã¨ã¯åºæ¥ãªã。
ã³ã³ããã¨ã³ã¹ã¤ãã·ã£ã©ã¤ã¶ã¼ããæå®ã¤ãã·ã£ã©ã¤ã¶ã¼ãå¼ã¶ãã¨ã¯åºæ¥ãã®ã§、ã³ã³ããã¨ã³ã¹ã¤ãã·ã£ã©ã¤ã¶ã¼ã«ãã¦ã¯ã©ããã¨ããããããã。
//4.0
class A {
init() { //ã¨ã©ã¼
self.init(a: 0)
}
init(a: Int) {
}
}
Must call a designated initializer of the superclasss '***'
ã¹ã¼ãã¼ã¯ã©ã¹***ã®designatedã¤ãã·ã£ã©ã¤ã¶ã¼ãå¼ã°ãªãã¨ããã¾ãã
【確èªver】Swift 4.0//4.0
class TestView: UIView {
init() {
super.init()
}
}
UIViewã®init()ã¯designatedã¤ãã·ã£ã©ã¤ã¶ã¼ã§ã¯ãªã。ã¨ããããã¤ã³ã¹ã¿ã³ã¹ãä½ãã ããªã、designatedã¤ãã·ã£ã©ã¤ã¶ã¼ããããã。super.init(frame: CGRect())ãªã©。
'required' initializer 'A***' must be provided by subclass of 'B***'
requiredã¤ãã·ã£ã©ã¤ã¶ã¼'A***'ã¯ãµãã¯ã©ã¹'B***'ã§æä¾ãããªãã¨(å®è£
ããªãã¨)ãããªã
【確èªver】Swift 4.0ãµãã¯ã©ã¹ã§initã¡ã½ãããã²ã¨ã¤ãæ¸ããªãå ´åã¯å é¤ããã模æ§
//4.0
class TestView: UIView {
init() {
super.init()
}
} //ã¨ã©ã¼
UIViewã¯init(coder:)ãrequiredãªã®ã§ãããæ¸ããªãã¨ãããªã。Use of 'self' in method call '***' before all stored properties are initialized
***ãå¼ã³åºãæã«selfã使ã£ã¦ããã、ãã¹ã¦ã®æ ¼ç´ããããã£ãåæåãããåã§ãã
【確èªver】Swift 4.0//4.0
class A {
let a: Int
init() {
self.aFunc() //ã¨ã©ã¼
a = 0
}
func aFunc() {
}
}
Self.init isn't called on all paths before returning from initializer
åæåã®çµè·¯ã®ä¸ã«self.initãå¼ã°ããªãçµè·¯ãããã¾ã
【確èªver】Swift 4.0convenienceåæåã¡ã½ããããã¯designatedåæåã¡ã½ãããå¼ã°ãªãã¨ãããªã
//4.0
class A {
var a: Int
init(aa: Int) {
a = aa
}
convenience init() {
} //ã¨ã©ã¼
}
Iinitializer does not override a designated initializer from its superclass
親ã®designatedåæåã¡ã½ããããªã¼ãã¼ã©ã¤ããã¦ãã¾ãã
【確èªver】Swift 4.0superã®convenienceããªã¼ãã¼ã©ã¤ãããæã«åºã。
åæåã¡ã½ããã¯designatedã¨convenienceããã。ãªã¼ãã¼ã©ã¤ãããããã¨ãåºæ¥ãã®ã¯designatedã®ã¿。ãã®ã¨ãoverrideãä»ãã。ã¤ã¾ãinitã«overrideãã¤ããå ´åã¯ãã®initã¯designatedã§ããå¿ è¦ããã。ããã、ãããconvenienceã®å ´åã¯çç¾ããã®ã§ãã®ã¡ãã»ã¼ã¸ãåºã。
//4.0
class Oya {
var a: Int
convenience init() {
self.init(a: 0)
}
init(a: Int) {
self.a = a
}
}
class Ko: Oya {
override init() { //ã¨ã©ã¼
}
override init(a: Int) { //ã¨ã©ã¼ãªã
super.init(a: a)
}
}
Unexpected initializer in pattern: did you mean to use '='
æ³å®ãããªãåæåã®ãã¿ã¼ã³、=ã使ã£ã¦ã¯ã©ãã
【確èªver】Swift 3.0.1åæåãä¸å®å ¨ãªæã«åºã。
//Swift 3.0.1
let a:
DispatchQueue.main.asyncAfter(deadline: .now() + 1.0) { //ã¨ã©ã¼
}
let a:ã¨æ¸ãã¦ããã®ã§ã³ã³ãã¤ã©ã¯aã®åãè¦æ±ãã¦ããã、ããã°ã©ã ã¯æ¬¡ã®ããã°ã©ã ã«è¡ã£ã¦ãã。'override' is implied when overriding a required initializer
requiredã¤ãã·ã£ã©ã¤ã¶ã¼ããªã¼ãã¼ã©ã¤ãããã¨ãã«ã¯overrideã¯æ¸ããªãã¦ããã
【確èªver】Swift 4.0requiredãããã°åå。
//Swift 4.0
class Oya {
required init() {
}
}
class Ko: Oya {
override required init() {
}
}
enum
Expected identifier in enum 'case' declaration
enumã®caseã®å®£è¨ãæ£ãããªã
【確èªver】Swift 4.0//4.0
enum BloodType {
case //ã¨ã©ã¼
}
Extraneous '.' in enum 'case' declaration
enumã®caseå®ç¾©ã«ä½è¨ãª.(ããã)
【確èªver】Swift 4.0【èª】Extraneous ä½è¨ãª//4.0
enum BloodType {
case .A //ã¨ã©ã¼
case .B //ã¨ã©ã¼
case .AB //ã¨ã©ã¼
case .O //ã¨ã©ã¼
}
enumä¸ã®caseã®æ¬¡ã«ã¯.(ããã)ããããªã(switchä¸ã®caseã®å¾ã«enumã®åè¦ç´ ãæ¸ãã¨ãã«ã¯å¿
è¦ã§ã)Enum case cannot have a raw value if the enum does not have a raw type
çãã¼ã¿æã¡ã¨ãã¦å®ç¾©ãã¦ããªãenumã®caseã§ã¯çãã¼ã¿ãæã¤ãã¨ã¯åºæ¥ã¾ãã
【確èªver】Swift 4.0【èª】raw çã®//4.0
enum BloodType {
case A = 0 //ã¨ã©ã¼
case B
case AB
case O
}
=0ããªããã、enum BloodType: Intã¨ããã°OKEnum with raw type cannot have cases with arguments
çãã¼ã¿æã¡ã®Enumã¯å¼æ°ä»ãã®è¦ç´ ãæã¤ãã¨ãåºæ¥ãªã。
【確èªver】Swift 4.0//4.0
enum TestEnum: Int { //å¥ã¨ã©ã¼
case testUnionS(String) //ã¨ã©ã¼
case testUnionI(Int) //ã¨ã©ã¼
}
Enum case must declare a raw value when the preceding raw value is not an integer
åã®è¦ç´ ã®çãã¼ã¿ãæ´æ°ã§ç¡ãå ´åã¯çãã¼ã¿ã宣è¨ããå¿
è¦ãããã¾ã
【確èªver】Swift 4.0【èª】preceding åã®Swift2.0ãããã®ä»æ§å¤æ´ã§Doubleã®ã¨ãã§ãIntã®æã¨åãããã«ããã©ã«ãå¤ãä¸ããããããã«ãªã£ãã®ã§ã¡ãã»ã¼ã¸ã¯ä¿®æ£ã®å¿ è¦ãããã¾ã。
//4.0
enum TDFK: Double { //å¥ã¨ã©ã¼
case Hok //ã¨ã©ã¼ã§ã¯ãªã
case Aom //ã¨ã©ã¼ã§ã¯ãªã
case Iwa = 5 //ã¨ã©ã¼ã§ã¯ãªã
case Aki //ã¨ã©ã¼ã§ã¯ãªã
case Miy = 10.0 //ã¨ã©ã¼ã§ã¯ãªã
case Yam //ã¨ã©ã¼
case Fuk
}
Hokã¯æå®å¤0ã§、0.0ãè¨å®ããã。Aomã¯æå®å¤1ã§、1.0ãè¨å®ããã。
Iwaã¯æå®å¤5ã§、5.0ãè¨å®ããã。
Akiã¯æå®å¤6ã§、6.0ãè¨å®ããã。
Miyã¯æå®å¤10.0ã§、10.0ãè¨å®ããã。
Yamã¯åã®æå®å¤ãæ´æ°ã§ã¯ãªãã®ã§ã¨ã©ã¼。
enum BloodType: String {
case A = "abc"
case B //ã¨ã©ã¼ã§ã¯ãªã。çãã¼ã¿ã¯"B"ã«ãªã
case AB
case O
}
Stringã®å ´åã¯ã¨ã©ã¼ã§ã¯ãªã。è¦ç´ åãçãã¼ã¿ã¨ãã¦æ¡ç¨ããã。ãã®å ´åã¯"B" "AB" "O"。'case' label can only appear inside a 'switch' statement
caseã©ãã«ã¯switchæã®ä¸ã ãã«æ¸ããã¨ãå¯è½ã§ã
【確èªver】Swift 4.0ããã¯enum宣è¨ä¸ã®caseã«ã³ãã³ãä»ãã¦ãã¾ã£ãã¨ãã«åºã¦ãã¾ã。
//4.0
enum BloodType {
case A: //ã¨ã©ã¼
case B: //ã¨ã©ã¼
case AB: //ã¨ã©ã¼
case O: //ã¨ã©ã¼
}
ãã®å ´åã³ãã³ãå¤ãã ãã§OKã§ã。ã³ãã³ãªãã®caseè¡ãæ£ããã§ã。ãã®ã¡ãã»ã¼ã¸ã§ãã、ã©ãã«ã¨ããã®ã¯ã³ãã³ãä»ããç¶æ ã®ãã¨ãè¨ã£ã¦ãã¾ã。
Raw value for enum case is not unique
enumã®çãã¼ã¿ã«éè¤ãããã¾ã
【確èªver】Swift 4.0//4.0
enum TestEnum: Int {
case test1 = 0
case test2 = 0 //ã¨ã©ã¼
}
2ã¤ã®è¦ç´ ã«0ãä¸ãã¦ããã®ã§ã¨ã©ã¼。'default' label can only appear inside a 'switch' statement
defaultã©ãã«ã¯switchã®ä¸ã§ã®ã¿ä½¿ãã¾ã
【確èªver】Swift 4.0//4.0
switch myBlood {
case A:
//ä½ã
case B:
//ä½ã
}
default: //ã¨ã©ã¼
Enums may not contain stored properties
Enumã¯ã¹ãã¢ãããããã£ãå«ãã¹ãã§ãªã
【確èªver】Swift 4.0//4.0
enum BloodType {
let A: Int = 0 //ã¨ã©ã¼
let B: Int = 1 //ã¨ã©ã¼
let AB: Int = 2 //ã¨ã©ã¼
let O: Int = 3 //ã¨ã©ã¼
}
ãããã宣è¨æ¹æ³ãéã。letã§ã¯ãªãcaseã使ãã®ãæ£ãã。Raw type '***' must appear first in the enum inheritance clause
enumã®ç¶æ¿ç¯ã§çãã¼ã¿***ã¯åãã«ç¾ããªãã¨ãããªã
【確èªver】Swift 4.0//4.0
enum TestEnumUnion: CustomStringConvertible, Int { //4.0
case a = 0
var description: String {
return "test"
}
}
An enum with no cases cannot declare a raw type
caseãæããªãenumã¯rawã®åã宣è¨ã§ãã¾ãã
【確èªver】Swift 4.0//4.0
enum TestEnumUnion: Int {
}
ã¾ã caseãæ¸ãã¦ããªã。Recursive enum '***' is not marked 'indirect'
å帰çãªenum***ã«indirectãä»ãã¦ãªã
【確èªver】Swift 4.0//4.0
//æªãä¾
enum TestEnumRe { //ã¨ã©ã¼
case TestEnumRe1(Int)
case TestEnumRe2(TestEnumRe)
}
//æ£ããä¾
enum TestEnumRe {
case TestEnumRe1(Int)
indirect case TestEnumRe2(TestEnumRe) //OK
}
'A***' declares raw type 'B***', but does not conform to RawRepresentable and conformance could not be synthesized
Aã¯rawã®åã¨ãã¦Bã宣è¨ãã¦ãã¾ã。ãããBã¯RawRepresentableã«æºæ ãã¦ã¾ãã。rawã®è¨å®ã¯åºæ¥ã¾ãã。
【確èªver】Swift 4.0//4.0
enum BloodType: Character { //ã¨ã©ã¼
case A //å¥ã¨ã©ã¼
case B
case AB
case O
}
//4.0
enum TestEnum: Int { //ã¨ã©ã¼
case testUnionS(String) //å¥ã¨ã©ã¼
case testUnionI(Int) //å¥ã¨ã©ã¼
}
//4.0
enum TDFK: Double { //ã¨ã©ã¼
case Hok //ã¨ã©ã¼ã§ã¯ãªã
case Aom //ã¨ã©ã¼ã§ã¯ãªã
case Iwa = 5 //ã¨ã©ã¼ã§ã¯ãªã
case Aki //ã¨ã©ã¼ã§ã¯ãªã
case Miy = 10.0 //ã¨ã©ã¼ã§ã¯ãªã
case Yam //å¥ã¨ã©ã¼ Enum case must declare a raw value when the preceding raw value is not an integer
case Fuk
}
//4.0
enum TestEnumUnion: Int { //ã¨ã©ã¼
}
ä¸èº«ãä½ãæ¸ãã¦ããªã。Enum cases require explicit raw values when the raw type is not expressible by integer or string literal
rawå¤ã®åãæ´æ°ãæååã§ã¯ãªãå ´å、Enumã®caseã¯æ確ãªrawå¤ã®è¨å®ãå¿
è¦ã§ã。
【確èªver】Swift 4.0//4.0
enum BloodType: Character { //å¥ã¨ã©ã¼
case A //ã¨ã©ã¼
case B
case AB
case O
}
æ´æ°ãæåå以å¤ã§ã¯æ確ã«rawã®å¤ãæå®ãããã¨。å ·ä½çã«ã©ããªã®ããããããããªãã£ãã®ã§Characterã§ãµã³ãã«ã³ã¼ããä½ãã¾ãã。
ç¶æ¿
Overriding declaration requires an 'override' keyword
(親ã§å®£è¨ãã¦ãããã®ã)ãªã¼ãã¼ã©ã¤ããã宣è¨ã¯overrideãä»ãããã¨ãå¿
è¦
【確èªver】Swift 4.0//4.0
class A {
func aFunc() {
}
}
class B: A {
func aFunc() { //ã¨ã©ã¼
}
}
Cannot override with a stored property '***'
***ã¨ããã¹ãã¢ãããããã£ã¯ãªã¼ãã¼ã©ã¤ãåºæ¥ã¾ãã
【確èªver】Swift 4.0親ã¯ã©ã¹ã§å®£è¨ãã¦ããããããã£(ã¹ãã¢ã、æ¼ç®åã®ä¸¡æ¹ãå«ã)ãã¹ãã¢ãããããã£ã§å宣è¨(ã¾ãã¯override)ãããã¨ãã。
//4.0
class Oya {
var a: Int = 0
var b: Int {
get {
return a + 10
}
set {
self.a = newValue - 10
}
}
}
class Ko: Oya {
var a: Int = 0 //ã¨ã©ã¼ overrideãã¤ãã¦ãåãã¨ã©ã¼
var b: Int = 0 //ã¨ã©ã¼ overrideãã¤ãã¦ãåãã¨ã©ã¼
}
overrideãããªãæ¼ç®åã§è¡ããã¨。Inheritance from a final class '***'
finalãã¤ããã¯ã©ã¹ããç¶æ¿ãããã¨ãã¦ãã
【確èªver】Swift 4.0finalãã¤ããã¯ã©ã¹ã¯ä¸ã¸ç¶æ¿åºæ¥ãªã。
//4.0
final class ClassA {
}
class ClassAA: ClassA { //ã¨ã©ã¼
}
Var overrides a 'final' var
finalã®varã¯ãªã¼ãã¼ã©ã¤ãåºæ¥ã¾ãã
【確èªver】Swift 4.0finalã§å®£è¨ãã¦ããããããã£(ã¹ãã¢ã、æ¼ç®åã®ä¸¡æ¹ãå«ã)ããµãã¯ã©ã¹ã®æ¼ç®ããããã£ã§ãªã¼ãã¼ã©ã¤ããããã¨ãã。finalããã¦ããªã、letã§ãªããã®ãªããããæ¼ç®ããããã£ã§ãªã¼ãã¼ã©ã¤ããããã¨ã¯å¯è½。
//4.0
class Oya {
final var a: Int = 0
final var b: Int {
get {
return self.a + 1
}
set {
self.a = newValue - 1
}
}
}
class Ko: Oya {
var base: Int = 0
override var a: Int { //ã¨ã©ã¼
get {
return self.base + 1
}
set {
self.base = newValue - 1
}
}
override var b: Int { //ã¨ã©ã¼
get {
return self.base + 2
}
set {
self.base = newValue - 2
}
}
}
Cannot override immutable 'let' property '***' with the getter of a 'var'
let宣è¨ãããå¤æ´ã§ããªãããããã£***ãvarå¤æ°ã®getterã§ãªã¼ãã¼ã©ã¤ããããã¨ã¯åºæ¥ã¾ãã
【確èªver】Swift 4.0let宣è¨ãããããããã£ã、æ¼ç®ããããã£ã§ãªã¼ãã¼ã©ã¤ããããã¨ããã¨ã。
æ¼ç®ããããã£ã¯varæ±ãã«ãªãã®ã§、è¦å¶ãç·©ããæ¹åã¸ã®å¤æ´ã«ãªã。ãããç¦æ¢ãã¦ããã®ãã¨æããã。
ãµãã¯ã©ã¹å´ãletã§å®£è¨ããã¨æ¼ç®ããããã£ã«åºæ¥ãªã(æ¼ç®ããããã£ã¯varã®ã¿)。æ¼ç®ããããã£ã«åºæ¥ãªããªããªã¼ãã¼ã©ã¤ãåºæ¥ãªã。ã¤ã¾ãlet宣è¨ãããããããã£ã¯ãªã¼ãã¼ã©ã¤ãåºæ¥ãªãã¨ãããã¨ã ããã。
//4.0
class Oya {
let a: Int = 0
}
class Ko: Oya {
var base: Int = 0
override var a: Int { //ã¨ã©ã¼
get {
return self.base + 1
}
set {
self.base = newValue - 1
}
}
}
Instance method overrides a 'final' instance method
ã¤ã³ã¹ã¿ã³ã¹ã¡ã½ãããfinalã§å®£è¨ãã¦ããã¡ã½ããããªã¼ãã©ã¼ããããã¨ãã¦ãã
【確èªver】Swift 4.0finalã§å®£è¨ãã¦ããã¡ã½ããããµãã¯ã©ã¹ã§ãªã¼ãã¼ã©ã¤ããããã¨ãã。
//4.0
class Oya {
final func funcA() {
}
}
class Ko: Oya {
override func funcA() { //ã¨ã©ã¼
}
}
Cannot override static method
staticãªã¡ã½ããã¯ãªã¼ãã¼ã©ã¤ãåºæ¥ãªã
【確èªver】Swift 4.0//4.0
class Oya {
static func funcStatic() {
}
}
class Ko: Oya {
override static func funcStatic() { //ã¨ã©ã¼
}
}
親ã¯ã©ã¹ã§ã¯staticã§å®£è¨ãã¦ãã。ããã¯æå³çã«ã¯final。Class methods are only allowed within classes; use 'static' to declare a static method
ã¯ã©ã¹ã¡ã½ããã¯ã¯ã©ã¹ã®ã¿ã«ä½¿ç¨ã§ãã¾ã。ã¹ã¿ãã£ãã¯ã¡ã½ããã«ã¯staticã使ã£ã¦å®£è¨ãã¦ãã ãã。
【確èªver】Swift 4.0ã¯ã©ã¹å ã§å®£è¨ãããã®ã«ã¯classã¨staticã使ãã。structã¨enumã¯staticã®ã¿ã使ãã。
classãä»ãããã®ã¯ä¸ã®ã¯ã©ã¹ã§ç¶æ¿åºæ¥ã。structã¨enumã¯ç¶æ¿ã®æ©è½ããªãã®ã§classã¯ä½¿ãéããªã。
ãããã³ã«å ã§ã¯staticã®ã¿。ãããã³ã«ã¯structãenumã«ä»ããããå¯è½æ§ããããã。ãããã³ã«å ã§å®£è¨ããstaticã¡ã½ããã、é©ç¨ã¯ã©ã¹å ã§classã§å®ç¾©ãã¦ãOK。
//4.0
struct A {
class func methodA() { //ã¨ã©ã¼
}
}
staticã«å¤ããã¨OK//4.0
protocol A {
class func funcA(a: Int) //ã¨ã©ã¼
}
staticã«å¤ããã¨OKãããã³ã«ã§ã¯staticã¨ãªã£ã¦ãã¦ã、ãããé©ç¨ããã¯ã©ã¹ã§、class func funcA(a: Int) {}ã¨åºæ¥ã。
Cannot override static var
staticã®varã¯ãªã¼ãã¼ã©ã¤ãåºæ¥ã¾ãã
【確èªver】Swift 3.0.1//Swift 3.0.1
class A {
static var daihyo: A {
return A()
}
}
class B: A {
override static var daihyo: B { //ã¨ã©ã¼
return B()
}
}
Aã®æ¹ã®staticãclassã«ããã¨OKCannot override mutable property '***' of type 'A***' with covariant type 'B***'
Aåã®ããããã£***ã¯å
±å¤ã®(?)Båã§ãªã¼ãã¼ã©ã¤ãåºæ¥ã¾ãã
【確èªver】Swift 3.0.1【èª】covariant å
±å¤ã®//Swift 3.0.1
class A {
static var daihyo = A()
}
class B: A {
override static var daihyo: B {
return B()
}
}
Aã®daihyoãclassã®æ¼ç®ããããã£ã«ããã¨OKã«ãªã。protocol ãããã³ã«
Type 'A***' does not conform to protocol 'B***'
A***ã¨ããåã¯B***ã¨ãããããã³ã«ã«é©åãã¦ãã¾ãã
【確èªver】Swift 3.0.2【èª】conform é©åãããããã³ã«ãä½ãç解ãã¦ããªãã¨ãã¯ç解ãå¿ è¦ã§ã。ããã¯å°ãæéããããã¾ã。
//Swift 3.0.2
class ViewController: UIViewController, UIPickerViewDataSource {
//å¿
è¦ãªã¡ã½ãããæ¸ããã¦ããªã
}
classã®å®ç¾©ã«UIPickerViewDataSourceãããã³ã«ãä»ããã、å¿
è¦ãªã¡ã½ãããå®è£
ãã¦ããªã。//Swift 3.0.2
protocol ProtocolA {
func funcA()
}
struct StructA: ProtocolA { //ã¨ã©ã¼
mutating func funcA() {
//å®è£
}
}
ãããã³ã«å®è£
å´ã§åæã«mutatingã«ãã¦ã¯ã ã。éã¯è¨±ãããã。//Swift 3.0.2
protocol protocolA {
var a: Int { get set }
}
class ClassA: protocolA { //ã¨ã©ã¼
let a: Int = 0
}
class ClassAA: protocolA { //ã¨ã©ã¼
var a: Int {
get { return self.a }
}
}
ãããã³ã«ã§get setã§å®£è¨ããããã®ãå®è£
å´ã§letãèªã¿åãå°ç¨ã«ãã¦ã¯ã ã。éã«ãããã³ã«ã§ã¯getã®ã¿ã®ãã®ã、å®è£ å´ã§èªã¿æ¸ãåºæ¥ãããã«ããã®ã¯OK。
//Swift 3.0.2
protocol A {
}
protocol B: A {
associatedtype ASO: Equatable
}
class C: B { //ã¨ã©ã¼
typealias ASO = A
}
associatedtype ASO: Equatableã®æ¡ä»¶ãæºãããã¦ããªã。//Swift 3.0.2
func abc<T>(a: Any) -> T? {
return a as? T
}
let aaa = abc(a: 0) //ã¨ã©ã¼ Type 'Any' does not conform to protocol 'ExpressibleByIntegerLiteral'
let bbb = abc(a: "a") //ã¨ã©ã¼Type 'Any' does not conform to protocol 'ExpressibleByUnicodeScalarLiteral'
let ccc = abc(a: "abc") //ã¨ã©ã¼Type 'Any' does not conform to protocol 'ExpressibleByStringLiteral'
æ»ãå¤ããæ¨è«ããã¿ã¤ãã®ã¸ã§ããªãã¯ãã¡ã³ã¯ã·ã§ã³ã§、æ»ãå¤ããæ¨è«ãåºæ¥ãªãã¨ãã«、ãã¡ã³ã¯ã·ã§ã³ã®å¼æ°å´ã«å¯¾ãã¦ã¨ã©ã¼ãåºã。//Swift 3.1
var rangeTest: CountableRange<Double> //ã¨ã©ã¼
Doubleã¯ã«ã¦ã³ã¿ãã«ã§ã¯ãªã。Protocol methods may not have bodies
ãããã³ã«ã®å®ç¾©å
ã«æ¸ããã¦ããã¡ã½ããã¯ä¸èº«ãæã£ã¦ã¯ã ã
【確èªver】Swift 3.0.2ãããã³ã«ã®å®ç¾©å ã«ã¯ååã¨å¼æ°ã¨æ»ãå¤ã®ã¿ãæ¸ã。
//Swift 3.0.2
protocol ABCProtocol {
func abc() { //ã¨ã©ã¼
}
}
Initial value is not allowed here
åæå¤ã¯ããã«æ¸ãããã¹ãã§ãªã
【確èªver】Swift 3.0.2【èª】allow 許ã//Swift 3.0.2
protocol AProtocol {
var a: Int = 0 //ã¨ã©ã¼
}
ãããã³ã«ã§åæå¤ã¯åä»ãªã。Property in protocol must have explicit { get } or { get set } specifier
ãããã³ã«å
ã®ããããã£ã¯æ確ã«{ get } ã { get set }ãã¤ããªãã¨ã ã
【確èªver】Swift 3.0.2【èª】explicit æ確ãªgetãsetã®ä¸èº«ã¯ãããªã。
//Swift 3.0.2
protocol AProtocol {
var a: Int //ã¨ã©ã¼
}
var a: Int { get }ãvar a: Int { get set }
ã§OK。
Expected get or set in a protocol property
ãããã³ã«å®ç¾©å
ã®ããããã£ã«ã¯getãsetã®æ³å®ãããæ¸ãæ¹ããã
【確èªver】Swift 3.0.2{ get }ã{ get set }ãæ£ãã
//Swift 3.0.2
protocol AProtocol {
var a: Int {
get { //ã¨ã©ã¼
}
}
}
getã®ä¸èº«ãæ¸ããã¨ãã¦ããã、ä¸èº«ã¯ãããã³ã«ãã¤ããã¯ã©ã¹å
ã§æ¸ããã¨。Redundant conformance of 'A***' to protocol 'B***'
A***ã®B***ãããã³ã«ã®ä½åãªæºæ
【確èªver】Swift 3.0.2【èª】redundant ä½å°ã§//Swift 3.0.2
class MyTableViewController: UITableViewController, UITableViewDataSource, UITableViewDelegate { //ã¨ã©ã¼
}
UITableViewControllerãUITableViewDelegateã¨UITableViewDataSourceãæã£ã¦ããã®ã§ä½åã«ä»ããªãã¦ãã。Immutable property requirement must be declared as 'var' with a '{ get }' specifier
å¤æ´åºæ¥ãªãããããã£ã¯varã¨{ get }ã使ã£ã¦å®£è¨ãããå¿
è¦ããã
【確èªver】Swift 3.0.2//Swift 3.0.2
protocol protocolA {
let a: Int
}
ãããã³ã«ã§let宣è¨ããã¨ãã¯var a: Int { get }ã¨ããã¨OK。å®è£
å´ã§letã«ãã。Default argument not permitted in a protocol method
ãããã³ã«ã§å®£è¨ãããã¡ã½ããã§ã¯ããã©ã«ãå¤ã¯èªãããã¾ãã
【確èªver】Swift 3.0.2//Swift 3.0.2
protocol A {
func funcA(a: Int = 0) //ã¨ã©ã¼
}
Global scope ã°ãã¼ãã«ã¹ã³ã¼ã
classãstructã®å®ç¾©ç¯å²ã®å¤ã®ãããªä½ã«ãå²ã¾ãã¦ãªãã®ã¨ãããglobal scopeã¨ãã(「å ´æ」ã¨ãããã「ã¢ã¯ã»ã¹è¨å®」ã®æ¦å¿µã®ã»ããå®ç¾©ã«è¿ããããããªã)Swiftã®ã¨ã©ã¼ã¡ãã»ã¼ã¸ã§ã¯top lebelã¨è¡¨ç¾ããããã¨ããã
global scopeã§å®£è¨ããã¦ããå¤æ°/å®æ°ã¯globalå¤æ°/globalå®æ°
global scopeã§å®£è¨ããã¦ããfunctionã¯global function
Global 'var' declaration requires an initializer expression or getter/setter specifier
ã°ãã¼ãã«ã®varå¤æ°å®£è¨ã¯åæåãgetter/setterãå¿
è¦
【確èªver】Swift 4.0//4.0
//ã°ãã¼ãã«ã§
var a: Int //ã¨ã©ã¼
Global 'let' declaration requires an initializer expression
ã°ãã¼ãã«ã®'letå®æ°å®£è¨ã¯åæåãå¿
è¦
【確èªver】Swift 4.0//4.0
//ã°ãã¼ãã«ã§
let b: Int //ã¨ã©ã¼
Expressions are not allowed at the top level
ãããã¬ãã«ã§ã¯è¨±å¯ããã¦ããªãå¼ã§ã
【確èªver】Swift 4.0é¢æ°ãã¡ã½ããå ãªã©ã§ããå®è¡ã§ããªãå½ä»¤ãé¢æ°ãã¡ã½ããã®å¤ã§è¡ã£ãæ
//4.0
//ãããã¬ãã«ã§
self.init() //ã¨ã©ã¼
abs(1) //ã¨ã©ã¼
//4.0
//ãããã¬ãã«ã§
SomeClass {} //ã¨ã©ã¼
classãã¼ã¯ã¼ãå¿ã//4.0
//ãããã¬ãã«ã§
someFunc() { //ã¨ã©ã¼
}
funcãã¼ã¯ã¼ãå¿ãclass methods may only be declared on a type
static methods may only be declared on a type
ã¯ã©ã¹ã¡ã½ããã¯åã®ä¸ã§ã®ã¿å®ç¾©ã§ãã¾ã
ã¹ã¿ãã£ãã¯ã¡ã½ããã¯åã®ä¸ã§ã®ã¿å®ç¾©ã§ãã¾ã
【確èªver】Swift 3.0.2//Swift 3.0.2
//ãããã¬ãã«ã§
class func abc() { //ã¨ã©ã¼
}
static func abc() { //ã¨ã©ã¼
}
Operator æ¼ç®å
'***' is not a prefix(postfix) unary operator
***ã¯åç½®(å¾ç½®)åé
æ¼ç®åã§ã¯ããã¾ãã
【確èªver】Swift 4.0【èª】unary operator åé
æ¼ç®å//4.0
var abc = 0
abc+
'***' is not a binary operator
'***'ã¯2é
æ¼ç®åã§ã¯ããã¾ãã
【確èªver】Swift 4.0//4.0
var a: Int = 0
var b: Int = 0
b = a ++ a //ã¨ã©ã¼
ä¼¼ã¦ããååã®2é
æ¼ç®åã¨ééãã¦ãã¾ã£ãå ´åUnary operator 'A***' cannot be applied to an operand of type 'B***'
åé
æ¼ç®åAã¯Båã«é©ç¨åºæ¥ã¾ãã
【確èªver】Swift 4.0Bã«ã¯ããããããã®ãå ¥ããã¨ããã
++ã--ã¯å»æ¢ã«ãªã£ãã®ã§å¾æ¥ã®Cè¨èªã®ä½¿ãæ¹ãããã¨åºã。
//4.0
var a: Int = 0
++a //ã¨ã©ã¼
++ã¯å»æ¢//4.0
var nums: [Int] = [1,2]
nums++ //ã¨ã©ã¼
é
åãã¤ã³ã¯ãªã¡ã³ããããã¨ãã¦ããããããã++ã¯å»æ¢Binary operator 'A***' cannot be applied to operands of type 'B***' and 'C***'
2é
æ¼ç®åAã¯Båã¨Cåã®æ¼ç®ã«é©ç¨åºæ¥ã¾ãã
【確èªver】Swift 4.0//4.0
var abc: String
var def = abc + 0 //ã¨ã©ã¼
Stringã¨0ã¨ã®è¶³ãç®ããããã¨ãã¦ãã//4.0
var abc8: Int8 = 0
var abc16: Int16 = 0
var abc = abc8 | abc16
Int8ã¨Int16ã®ãããæ¼ç®ã¯ä¸å¯。Int16(abc8)ã«ããã¨åãä»ãã。//4.0
var abc: Character = "a"
var abc2: String = "abc"
var abc3 = abc + abc2 //ã¨ã©ã¼
Stringã¨Characterã+ããããã¨ããã¨ã//4.0
let range = 0...10
if 5 ~= range { //ã¨ã©ã¼
}
~=æ¼ç®åã®å·¦å³ãé//Swift3.0.1
let aTuple = (1.0,2.0,3.0)
let bTuple = (2,3,4)
if aTuple == bTuple { //ã¨ã©ã¼
}
ã¿ãã«ã®æ¯è¼ã¯ä¸èº«ã®åãéãã¨åºæ¥ãªãä¸èº«ã®åãåãçµã¿åããã¯æã¯ã¨ã©ã¼ãåºããSwift3.0ã§ã¯åºãªã。
Binary operator 'A***' cannot be applied to two 'B***' operands
2é
æ¼ç®åAã¯2ã¤ã®Båã®æ¼ç®ã«é©ç¨åºæ¥ã¾ãã
【確èªver】Swift 3.0.12ã¤ãæ¯è¼ãã==ã¨===ã¯、ã¯ã©ã¹å士ãæ§é ä½å士ãã§æåãéã«ãªãã®ã§æ³¨æ。
//Swift 3.0.1
var a: String = "ABC"
var b: String = "ABC"
if a === b { //ã¨ã©ã¼
}
var c: String? = "ABC"
var d: String? = "ABC"
if c === d { //ã¨ã©ã¼
}
===ã¯ã¯ã©ã¹å士ãªã、åãã¤ã³ã¹ã¿ã³ã¹ãã©ããå¤å¥ããæ©è½ãæã¤ã、Stringã¯æ§é ä½ã ãããªã®ãã¨ã©ã¼ã«ãªã。==ã«ããã°ã¨ã©ã¼ã«ãªããªã。æ§é ä½ã®ãªãã·ã§ãã«å士ã§ã===ã§ã¨ã©ã¼。==ã«ããã°ã¨ã©ã¼ã«ãªããªã。
//Swift 3.0.1
class ABC {
}
let a = ABC()
let b = ABC()
if a == b { //ã¨ã©ã¼
}
let c: ABC? = ABC()
let d: ABC? = ABC()
if c == d { //ã¨ã©ã¼
}
ã¯ã©ã¹å士ã®å ´åã¯==ã§ã¨ã©ã¼ã«ãªã、===ã§ã¨ã©ã¼ã«ãªããªã。ã¯ã©ã¹ã®ãªãã·ã§ãã«å士ã®å ´åã==ã§ã¨ã©ã¼ã«ãªã、===ã§ã¨ã©ã¼ã«ãªããªã。
ãã¾ã
//Swift 3.0.1
let e: ABC? = ABC()
if e == nil { //OK
}
if e === nil { //OK
}
ã¯ã©ã¹ã®ãªãã·ã§ãã«åã¨nilã®æ¯è¼ã¯==ã§ã===ã§ãå¯è½。//Swift 3.0.1
let aDouble: Double = 2.0
let bDouble: Double = 3.0
let c: CGFloat = a + b //ã¨ã©ã¼ Doubleå士ã§è¶³ãç®ã§ããªãã¨è¨ããã
let d: CGFloat = CGFloat(a + b) //ããã¯OK
let e: CGFloat = CGFloat(a) + CGFloat(b) //ããã¯OK
左辺ã§æå®ãã¦ããåãå³è¾ºã®æ¼ç®ã«å£åºããã¦ãã//Swift 3.0.2
enum RST {
case rr(Int)
case ss(String)
case tt(Double)
}
let r = RST.rr(1)
let s = RST.ss("ããã«ã¡ã¯")
if r == s { //ã¨ã©ã¼
}
enumã®ãã®ã¿ã¤ãã®å ´åã¯==æ¯è¼ã§ã¨ã©ã¼ã«ãªã。enumã®å®ç¾©ã«æ¯è¼ã®ã¡ã½ãããæ¸ã対å¿æ¹æ³ããã。Left side of mutating operator isn't mutable: '***' is a 'let' constant
å¤ãå¤æ´ããæ¼ç®åã®å·¦å´ãå¤æ´åºæ¥ãå¤æ°ã§ã¯ãªã。***ã¯letã§å®ç¾©ãããå®æ°ã§ã
【確èªver】Swift 4.0//4.0
let abc = "abc"
abc += " def" //ã¨ã©ã¼
letã§å®£è¨ããå®æ°ãæä½ãããã¨ãã。Unary operator cannot be separated from its operand
åè¡æ¼ç®åã¯ãªãã©ã³ã(æ¼ç®ãé©ç¨ããããã®)ãé¢ããã¨ã¯åºæ¥ã¾ãã
【確èªver】Swift 4.0【èª】Unary operator åé
æ¼ç®å//4.0
var a: Int = 0
var b = - a //ã¨ã©ã¼
-ã&ãªã©ã®åé
æ¼ç®åã¨ãªãã©ã³ãã¨ã®éã«ã¹ãã¼ã¹ããã。ã¹ãã¼ã¹ã¯ãããªã。&ã|ã*ãå¤ãªã¨ããã«å ¥ã£ã¦ãã
Expected member name following '.'
.ã®å¾ãã«ã¡ã³ãåãæå¾
ããã
【確èªver】Swift 4.0.ã®å¾ããæ¸ããã¦ããªã
//4.0
//å®ç¾©
enum BloodType: String {
case A
case B
case AB
case O
}
//使ç¨
BloodType. //ã¨ã©ã¼ AãBãOãABãå¿
è¦
Expected expression after operator
æ¼ç®åã®å¾ãã«ä½ãå¼ãæå¾
ããã
【確èªver】Swift 4.0//4.0
print("There are " + ) //ã¨ã©ã¼
//4.0.2
let a = 1 + //ã¨ã©ã¼
Operator should no longer be declared with body
(èªä½)æ¼ç®åã®å®£è¨ã§ã¯{}ã®ã«ãã³ããããªããªãã¾ãã
【確èªver】Swift 4.0//4.0
prefix operator √ {} //ã¨ã©ã¼
prefix func √(x:Double)->Double {
return sqrt(x)
}
'***' is considered to be an identifier, not an operator
***ã¯å¤æ°ãªã©ã®åå(identifier)ã«ã¯ä½¿ç¨ã§ããã、æ¼ç®åã®ååã«ã¯ä½¿ç¨ã§ããªã
【確èªver】Swift 4.0//4.0
infix operator ããã© //ã¨ã©ã¼
infix operator andand //ã¨ã©ã¼
Operator must be declared as 'prefix', 'postfix', or 'infix'
æ¼ç®åã¯prefixãpostfixãinfixãä»ãã¦å®£è¨ããªãã¨ãããªã
【確èªver】Swift 4.0
operator +- //ã¨ã©ã¼
Operator implementation without matching operator declaration
æ¼ç®åã®å®è£
ã宣è¨ã¨åããªã
【確èªver】Swift 4.0宣è¨ãå¿ãã¦ããã¨ã。
宣è¨ã¨å®è£ ã§〜fixã®ä¸ä¸è´。preã¨postãªã©。
//4.0
//宣è¨ããªã prefix operator √
prefix func √(x:Double)->Double { //ã¨ã©ã¼
return sqrt(x)
}
宣è¨ããªã//4.0
infix operator √
prefix func √(x:Double)->Double { //ã¨ã©ã¼
return sqrt(x)
}
infixã¨prefixã®ä¸ä¸è´'infix' modifier is not required or allowed on func declarations
infixã¯func宣è¨é¨ã«ãããªã
【確èªver】Swift 4.0//4.0
infix operator ++++
infix func ++++(l: Double, r: Double) -> Double { //ã¨ã©ã¼
return sqrt(l + r)
}
'%' is unavailable: Use truncatingRemainder instead
%ã¯ä½¿ãã¾ãã。代ããã«truncatingRemainderã使ã£ã¦ãã ãã
【確èªver】Swift 3.0.1//Swift 3.0.1
let a = 4.0 % 3.0 //ã¨ã©ã¼
let b = 4.0.truncatingRemainder(dividingBy: 3.0) //OK
%ã®ä»£ããã«ãªãã®ã¯truncatingRemainder(dividingBy:)ä»ã«remainder(dividingBy:)ã¨ããã®ããã。
æ°å¤ã®è¡¨ç¾/æ¼ç®
Doubleã®0.0ã§å²ã£ã¦ãå®è¡æã¨ã©ã¼ã«ãªããªã。ã¾ã0.0ã«æ£è² ããã£ã¦、ä¸ã®ä¾ã§ã¯ãã¤ãã¹ç¡é大ãå®è¡çµæã«ãªã。//3.1
let a = -0.0
let b = 5.0
b/a //çµæã¯-inf
16é²æ°è¡¨è¨ã®ææ°é¨éå§ã®æåã¯pã§ææ°é¨æ°åã¯10é²(0〜9)ã§è¡¨è¨、å°æ°ç¹ç§»åä½ç¨ã¯2é²æ°ç¶æ
ã«å¯¾ãã¦è¡ããã//3.1
let a = 0x1.ap-4 //10é²ã®0.1ã¨ã ãããåãå¤ã16é²ã§è¡¨è¨
ä¸ã®ä¾ã¯16é²ã®1.aã«ææ°é¨p-4ãä»ãããã®。ææ°é¨ã®æ°åã¯10é²ã§è¡¨è¨ãã。ã¤ã¾ãp9ã¯OKã§paã¯NG。ä»åã®p-4ã¯OK。
ææ°é¨ã®æ°åã«ããå°æ°ç¹ç§»åã¯2é²ç¶æ ã«å¯¾ãã¦è¡ããã。ã¤ã¾ãä¸ã®ä¾ã¯、1.1010(2é²)ä¸ã§4ã¤ç§»åãã¦、0.0001101(2é²)ã¨ãªã。ããã16é²ã«ããã¨0.1a(16é²)。ããã10é²ã«ç´ãã¨、1/16 + 10/256 = 0.1015625。å人çã«ã¯、ãã®å°æ°ç¹ç§»åæä½ã2é²ãªã®ã¯ç²ç¹ã ã£ã。16é²è¡¨è¨ã®ã¾ã¾ã§4æ¡ã®å°æ°ç¹ç§»åæä½ãè¡ãã¨0.0001a(16é²)ã¨ãªã、ã ãã¶å°ããå¤ã«ãªã£ã¦ãã¾ã。
Expected a digit after integer literal prefix
æ´æ°è¡¨ç¾ã§å§ã¾ã£ããã®ã®å¾ã«æ³å®ããããã®ããªã、æ³å®ãããªããã®ããã
【確èªver】Swift 3.0.2ä¸ã®ãªã¹ããåç §
Hexadecimal floating point literal must end with an exponent
16é²è¡¨ç¾ã®å°æ°ã¯ææ°ã§çµãããªãã¨ãããªã
【確èªver】Swift 4.0【èª】Hexadecimal 16é²æ³ã® exponent ææ°å°æ°è¡¨ç¾16é²ã§ã¯e4ãªã©ã§çµããã¨ææ°ã®æå³ã§ä½¿ã£ã¦ãããã©ãã解éã«è¿·ããã¨ã«ãªãã®ã§、ææ°è¡¨ç¾ã«ç¨ããæåã¯pã使ãã¾ã。å°æ°è¡¨ç¾16é²ã¯ææ°è¡¨ç¾ãã¤ãããã¨ãå¿ é ã§ã。
//4.0
var a = 0x123456 //ã¨ã©ã¼ãªã
var b = 0x123456.789 //ã¨ã©ã¼ p4ãªã©ããªã
var c = 0x1.2e10 //ã¨ã©ã¼ eã§ã¯ãªãã¦pã使ã
var d = 1.2p10 //ã¨ã©ã¼ Consecutive statements on a line must be separated by ';'
10é²è¡¨ç¾ã«ã¯eã使ãã、16é²è¡¨ç¾(0x〜)ã§ã¯eãæ°å¤ã表ãã®ã§ææ°é¨ã®è¡¨ç¾ã¨ãã¦pã使ã10é²è¡¨ç¾ã«pã使ã£ãå ´åã¯pããå¥ã®æã¨è§£éããã
'A***' is not a valid floating point literal; it must be written 'B***'
A***ã¯æ£ããå°æ°è¡¨ç¾ã§ã¯ããã¾ãã。B***ã¨æ¸ãããã¹ãã§ã。
【確èªver】Swift 4.0//4.0
var a: Double = .45 //ã¨ã©ã¼
0.45ã®å ´åã¯0ãå¿
è¦Value of type 'Int' has no member '***'
Intã«ã¯***ã¨ããã¡ã³ãã¯ããã¾ãã
【確èªver】Swift 4.0//4.0
var a = 1._0 //ã¨ã©ã¼
var b = 0x1._0p1 //ã¨ã©ã¼
var c = 1.e1 //ã¨ã©ã¼
var d = 0x1.p1 //ã¨ã©ã¼
å°æ°ç¹ç´å¾ã®_ã¯ä½¿ããªãå°æ°ç¹ç´å¾ã®ææ°è¡¨ç¾ã¯ã ã
//Swift 3.0.2
//æ£ããä¾
var rightNumber10i = 1234
var rightNumber10f = 1234.5678
var rightNumber10e = 1234.5678e10
var rightNumber16i = 0x1234
var rightNumber16e = 0x1234.5678p10
var rightNumber2i = 0b1010
var rightNumber8i = 0o7070
//ééã£ãä¾
var wrong_int_10_a = 45c2d34 //ã¨ã©ã¼ Expected a digit after integer literal prefix
//cã¨dã¯æ±ããªã。10é²æ°è¡¨è¨ãªã®ã§prefixã¯ãªããã©ä»ã®é²æ°ã¨ã¡ãã»ã¼ã¸ãå
±é。
var wrong_int_2_a = 0b4 //ã¨ã©ã¼ Expected a digit after integer literal prefix
//æ±ããæ°å¤ã®ç¯å²ãè¶
ãã¦ãã。2é²æ°ãªã®ã§4ã¯æ³å®ãã¦ããªã。
var wrong_int_2_b = 0b0123 //ã¨ã©ã¼ Consecutive statements on a line must be separated by ';'
//2é²æ°ã§1ã¾ã§ã¯æ£å¸¸ã«è§£éã§ãã。ãªã®ã§(;ã§åºåã£ã¦ãã ãã)ãåºã。
var wrong_int_16_a = 0X11 //ã¨ã©ã¼ Expected a digit after integer literal prefix
//xã®å¤§æåã¯ãã¡
var wrong_int_16_b = 0x1234p //ã¨ã©ã¼ Expected a digit in floating point exponenent
//pã®å¾ã«ææ°ã®å¤ãå¿
è¦
var wrong_int_16_c = 0x123paa //ã¨ã©ã¼
//Consecutive statements on a line must be separated by ';'
//Expected a digit in floating point exponent
//16é²æ°ã®å°æ°ã®ææ°ã¯10é²ã§è¡¨è¨ãã
var wrong_float_10_a = .1234 //ã¨ã©ã¼ '.1234' is not a valid floating point literal; it must be written '0.1234'
//0.1234ãªãOK
var wrong_float_10_b = 1234. //ã¨ã©ã¼ Expected member name following '.'
//.ãæ¸ããããã®å¾ããæ¸ããªãã¨ãããªã
var wrong_float_10_c = 1234.5678p10 //ã¨ã©ã¼ Consecutive statements on a line must be separated by ';'
//10é²æ°ã®å°æ°ã®å ´å、ææ°ã¯eã§è¡¨ã。8ã¾ã§ã¯æ£å¸¸ã«è§£éã§ãã。ãªã®ã§(;ã§åºåã£ã¦ãã ãã)ãåºã。
var wrong_float_16_a = 0x123456.789 //ã¨ã©ã¼ Hexadecimal floating point literal must end with an exponent
//p4ãªã©ã®ææ°è¡¨è¨ãã¤ããªãã¨ãããªã
var wrong_float_16_b = 0x123.456e10 //ã¨ã©ã¼ Hexadecimal floating point literal must end with an exponent
//16é²æ°ã®å°æ°ã®ææ°ã¯eã§ã¯ãªãpã使ã
var wrong_float_16_c = 0x.123p4 //ã¨ã©ã¼
//Consecutive statements on a line must be separated by ';'
//Expected a digit after integer literal prefix
//Expected identifier after '.' expression
//0x0.123p4ãªãOK
var wrong_float_16_d = 0x123.p4 //ã¨ã©ã¼ Value of type 'Int' has no member 'p1'
//.ãæ¸ãããå¾ãã«æ°å¤ãå¿
è¦。.ã®å¾ãã®æ°å¤ããªããªã0x123p4ã§ãã
var wrong_float_2_8_a = 0b10.10 //ã¨ã©ã¼ Expected named member of numeric literal
var wrong_float_2_8_b = 0o40.40 //ã¨ã©ã¼ Expected named member of numeric literal
//2é²æ°ã¨8é²æ°ã§ã¯å°æ°ã¯è¡¨è¨ã§ããªã
var wrong_float_2_8_c = 0b1e1//ã¨ã©ã¼ Consecutive statements on a line must be separated by ';'
var wrong_float_2_8_d = 0o1p1//ã¨ã©ã¼ Consecutive statements on a line must be separated by ';'
//2é²æ°ã¨8é²æ°ã§ã¯ææ°è¡¨ç¾ã§ããªã
var wrong_float_2_8_e = 0b10.1e10 //ã¨ã©ã¼
//Consecutive statements on a line must be separated by ';'
//Expected named member of numeric literal
//0bã®2é²æ°è¡¨ç¾ã¨0oã®8é²æ°è¡¨ç¾ã¯å°æ°ãæ±ããªã
var wrong_float_2_8_f = 0b12.5p10 //ã¨ã©ã¼
//Expected member name following '.'
//Expected a digit after integer literal prefix
//0oã®8é²æ°è¡¨ç¾ã¯å°æ°ã«ä½¿ããªã
ãã¤ã³ã¿ç³» inoutç³»
Passing value of type '***' to an inout parameter requires explicit '&'
&ãå¿
è¦ã¨ããinoutãã©ã¡ã¼ã¿ã«***åã渡ãã¦ãã¾ã
【確èªver】Swift 4.0//4.0
func thePFunc(arg: inout Int){
}
var a = 0
thePFunc(arg: a) //ã¨ã©ã¼
å®ç¾©ã§ã¯inoutã§å®ç¾©ããã¦ããã®ã§å¼ã³åºãé¨ã§ã¯&aã¨ããªãã¨ãããªãCannot pass immutable value as inout argument: '***' is a 'let' constant
inoutå¼æ°ã«å¤æ´åºæ¥ãªãå¤ã渡ããã¨ã¯åºæ¥ã¾ãã。***ã¯letå®æ°ã§ã。
//4.0
func thePFunc(arg: inout Int){
}
let b = 0
thePFunc(arg: b) //ã¨ã©ã¼
//4.0
postfix operator ++
postfix func ++(arg: inout Int) -> Int {
let returnArg = arg
arg += 1
return returnArg
}
let b = 0
b++ //ã¨ã©ã¼
bã«1足ããã¨ãã¦ããã、bãletãªã®ã§ã¨ã©ã¼Cannot pass immutable value of type '***' as inout argument
inoutå¼æ°ã«***åã®å¤æ´åºæ¥ãªãå¤ã渡ããã¨ã¯åºæ¥ã¾ãã
【確èªver】Swift 4.0【éæ¹ã«ããã度】★★★★ã¡ãã£ã¨åå ããããã«ããã¨ã©ã¼
//4.0
func ioFunc(a: inout Int){
}
var a: Int! = 0
ioFunc(a: &a) //ã¨ã©ã¼
aãå¼·å¶ã¢ã³ã©ããã®ãªãã·ã§ãã«ã§å®£è¨ããã¦ã。ioFunc(a: &a!)ãªãOK'inout' before a parameter name is not allowed, place it before the parameter type instead
ãã©ã¡ã¼ã¿åã®åã®inoutã¯è¨±ããã¦ãã¾ãã。代ããã«åã®åã«ç½®ãã¦ãã ãã。
【確èªver】Swift 3.1//3.1
func abc(inout a: Int) { //ã¨ã©ã¼
a = 0
}
Variable has type 'inout ***' which includes nested inout parameters
'&' can only appear immediately in a call argument list
å¤æ°ã¯inout ***åãæã£ã¦ãã¾ã。ããã¯å
¥ãåã®(?)inoutãã©ã¡ã¼ã¿ãæã£ã¦ãã¾ã。
amp;ã¯ã¡ã½ããã¸ã®å¼æ°ã§ãã使ããªã
【確èªver】Swift 4.0nestedã®æå³ãããããããªã。
//4.0
var a = 0
let b = &a //ã¨ã©ã¼
Tuple ã¿ãã«
Value of tuple type '(A1,A2***)' has no member 'B***'
(A1,A2...)ã¨ããã¿ãã«ã«ã¯Bã¨ããååã®ã¡ã³ãã¼ã¯ããã¾ãã
Bãè¦ç´ çªå·ã«ãªããã¨ããã【確èªver】Swift 4.0
//4.0
let abc: (a: String, b: Int) = ("ã", 1)
print(abc.c) //ã¨ã©ã¼
cã¯ãªã//4.0
let abc = ("Hello","world")
print(abc.3) //ã¨ã©ã¼
abcã¯0ã¨1ããæã£ã¦ãªãã®ã§3ã«ã¢ã¯ã»ã¹ããããã¦ã¨ã©ã¼Default argument not permitted in a tuple type
ããã©ã«ãå¼æ°ã¯ã¿ãã«ã®åã«è¨±ããã¾ãã
【確èªver】Swift 4.0//4.0
let abc: (a: String = "ã", b: Int = 1) //ã¨ã©ã¼
Use of unresolved identifier '***'
***ã¯è§£æ±ºåºæ¥ã¾ãã。
【確èªver】Swift 4.0//4.0
func abc() -> (Int, String) {
return (1, "ã")
}
let (a: Int , b: String) = abc()
print(a)
print(b)
let (a: Int , b: String)ã®ã¨ããã¯let (ã©ãã«å: å¤æ°å , ã©ãã«å: å¤æ°å)ã¨è§£éããã
Tuple pattern element label 'A***' must be 'B***'
ã¿ãã«ã®ã©ãã«Aã¯Bã¨æ¸ãããã¹ã
【確èªver】Swift 4.0//4.0
var (aa: a , bb: b): (a: Int, b: String) //ã¨ã©ã¼
ã³ã³ãã¤ã©ã®è§£éã¯var (ã©ãã«å: å¤æ°å , ã©ãã«å: å¤æ°å): (ã©ãã«å: å, ã©ãã«å: å)
ãªã®ã§ã©ãã«åãéè¤ãã¦ãã
Tuple type '(ã©ãã«å: å, ã©ãã«å: å)' is not convertible to tuple '(ã©ãã«åA: _, ã©ãã«åB: _)'
ã¿ãã«ã®ã©ãã«ã¯、ã©ãã«Aã¨ã©ãã«Bã¨æ¸ãããã¹ã
【確èªver】Swift 4.0//4.0
func abc() -> (a: Int, b: String) {
return (1, "ã")
}
var (aa: a , bb: b) = abc()
é¢æ°ã®æ»ãå¤ã§ã©ãã«ãå®ç¾©ãã¦ããã®ã§、ããã«å¾ããã¨。if
Use of '=' in a boolean context. did you mean '=='?
è«çå¤ãæ±ããããç®æã§=ã使ã£ã¦ãã¾ã。ãããããã¨ã¯==ã使ã£ããåºæ¥ã¾ããã?
【確èªver】Swift 4.0//4.0
var abc: Bool
var abc2 = true
if (abc = abc2) {
}
åç´ãªä»£å
¥ã§ã¯å¤å®ãåºæ¥ãªã。Cè¨èªã®ããã«å¤ãè¿ããã¨ã¯ãªã。abc == abc2ã§OK。Expected '{' after 'if' condition
ifã®å¾ã®{ãæå¾
ããã
【確èªver】Swift 4.0//4.0
let i = 0
if i == 0 print("abc")
Cè¨èªã§ã¯OKãªææ³ã ã、Swiftã§ã¯å®è¡æã{}ã§å²ãå¿
è¦ãããOptional type '***' cannot be used as a boolean; test for '!= nil' instead
ãªãã·ã§ãã«ã¿ã¤ãã®'***'ã¯ãã¼ãªã¢ã³ã¨ãã¦ä½¿ãã¾ãã。!= nilã代ããã«è©¦ãã¦ä¸ãã
【確èªver】Swift 3.0.1//Swift 3.0.1
var abc :Bool? = false
if abc { //ã¨ã©ã¼
}
å¤ããããnilãã®å¤å®ã¯abc != nilã使ãvar abc :Bool? = false
if abc as? Bool { //ã¨ã©ã¼
}
as?ã®çµæã¯ãªãã·ã§ãã«ãªã®ã§ä¸ã®ä¾ã¨åãã¡ãªã¿ã«isã«ãã¦ãã¨ã©ã¼ã«ãªã
å¤ããããnilãã®å¤å®ã¯!= nilã使ã
let a: Bool? = true
let b: Bool? = true
if let c = a && b { //ã¨ã©ã¼
}
aã¨bã¯ãªãã·ã§ãã«ãªã®ã§&&ãåºæ¥ç¡ã。if let c = a, d = b where c && d {}
çãããã。
'is' test is always true
iså¤å®ã¯å¸¸ã«trueã¨ãªãã¾ã
【確èªver】Swift 4.0//4.0
var a = 5
if a is Int { //è¦å
}
常ã«tureãªãå¤å®ã®å¿
è¦ããªãã®ã§è¦åã¨ãããã¨ãªã®ã§ããã。Comparing non-optional value of type 'Any' to nil always returns true/false
Anyã¨ããéãªãã·ã§ãã«ã¨nilã®æ¯è¼ã¯å¸¸ã«true/false
【確èªver】Swift 3.1true/falseã®ã©ã£ã¡ã表示ããããã¯==ã!=ãã«ãã
//3.1
var intOpt: Int? = nil
var anyInt: Any = intOpt
if anyInt == nil { //ã¯ã¼ãã³ã° always false
}
if let
2ã¤ãif letãããã¨ãã¯,ã§åºåã。æ®éã®è«ç(ture or false)ãå ãããæã¯whereã§ç¶ãã。let a: Bool? = true
let b: Bool? = true
if let c = a, d = b where c == d {
}
Initializer for conditional binding must have Optional type,not '***'
æ¡ä»¶ãã¤ã³ãã£ã³ã°ã¸ã®åæå(ã«ä¸ãããã®)ã¯ãªãã·ã§ãã«åã§ããå¿
è¦ãããã¾ã。***ã¯ã ãã§ã。
【確èªver】Swift 3.1//3.1
var abc: String = "aaa"
if let abc2 = abc { //ã¨ã©ã¼
}
abcã¯?ä»ãã§ã¯ãªãã®ã§ãã®å¤å®ãããå¿
è¦ããªã。//3.1
let a: Int? = 5
if let aa = a! { //ã¨ã©ã¼
}
ãã§ã«!ã§ã¢ã³ã©ãããã¦ãããã®ãã¢ã³ã©ãããããã¨ãã//3.1
var anyDeGozaru: Any = UIImage(named: "aaa")
if let any_uw = anyDeGozaru { //ã¨ã©ã¼
}
ãªãã·ã§ãã«åãAnyã«å
¥ãã。Variable binding in a condition requires an initializer
æ¡ä»¶é¨ã§ä½¿ãããå¤ã¯åæåãããå¿
è¦ããã
【確èªver】Swift 4.0//4.0
if let abc {
}
=ã¨ãã®å¾ããªã//4.0
if let abc2 == abc {
}
=ãå¤ã//4.0
var abc :Bool? = false
if let abc as? Bool {
}
=ããªãguard
使ãæ¹guard æ¡ä»¶ else {}
Expected 'else' after 'guard' condition
guardã®æ¡ä»¶é¨ã®å¾ã«elseãå¿
è¦ã§ã
【確èªver】Swift 4.0//4.0
guard condition { //ã¨ã©ã¼ elseãªã
return
}
'guard' body may not fall through, consider using 'return' or 'throw' to exit the scope
guardã¯ä¸ã«æããã¹ãã§ã¯ããã¾ãã。æããããã«returnãthrowãæ¤è¨ãã¦ãã ãã。
【確èªver】Swift 4.0returnãthrowãå¿ è¦。ã¡ãªã¿ã«breakã使ãã¨ã¨ã©ã¼。
//4.0
func testFunc(condition: Bool) {
guard condition else {
} //ã¨ã©ã¼
}
'break' is only allowed inside a loop, if, do, or switch
breakã¯æ¬¡ã®å ´æã§è¨±ããã¾ã。ã«ã¼ãå
、if、do、switch
【確èªver】Swift 4.0//4.0
func testFunc(condition: Bool) {
guard condition else {
break //ã¨ã©ã¼
}
}
for
Cannot assign to value: '***' is a 'let' constant
代å
¥ã§ãã¾ãã。***ã¯letã§å®£è¨ãããå®æ°ã§ã。
【確èªver】Swift 4.0ã«ã¦ã³ã¿ã¼ã¯(æã ãæä½åºæ¥ãªãã¨ããæå³ã§)å®æ°ã¨ããæ±ãããã
//4.0
for i in 1...5 {
i = 10 //ã¨ã©ã¼
}
//4.0
var counter = 0
for counter in 1...5 { //ããã§ã¯ã¨ã©ã¼ãåºãªã
counter = 10 //ã¨ã©ã¼
}
counterãvarã§å®£è¨ãã¦ãforã®æ¡ä»¶è¨å®é¨åã§ã¯ã¨ã©ã¼ã«ãªããªã。ã¨ã©ã¼ã¯ä»£å
¥é¨ã§åºã。å¥ã®counterå®æ°ãçæããã¦ããã®ãããããªã。Use of unresolved identifier '***'
æ£ä½ä¸æã§ãã'***'ã使ç¨ãã¦ãã
【確èªver】Swift 4.0.2//4.0.2
for counter in 1..5 { //ã¨ã©ã¼
}
'..'ã§ã¯ãªã'..<'ãæ£ãã//4.0.2
let a = 5 &/ 3 //ã¨ã©ã¼
let b = 5 &% 3 //ã¨ã©ã¼
ãããã®æ¼ç®åã¯å»æ¢ã«ãªã£ã。//4.0.2
for counter in 1..=5 { //ã¨ã©ã¼ Expected expression after operatorãåºã
}
'..='ã§ã¯ãªã'...'ãæ£ããType '***' does not conform to protocol 'Sequence'
***ã¯'Sequence'ãããã³ã«ã«è¨å®ããã¦ãã¾ãã
【確èªver】Swift 4.0.2//4.0.2
let today = NSDate()
for i in today { //ã¨ã©ã¼
}
ã«ããã¦、inã®å¾ãã«æã£ã¦ããã«ã¯ãµãããããªããã®ã®æ//4.0.2
let interval: ClosedInterval = 0...10
for i in interval { //ã¨ã©ã¼
}
ClosedIntervalãHalfOpenIntervalã¯ã ãExpexted ',' separator
Expected pattern
Expected Sequence Type expression for for-each loop
Expected 'in' after for-each pattern
','åå²åãæ³å®ããã
ãã¿ã¼ã³ãæ³å®ããã
for-eachã«ã¼ãã®é çªå¼ãæ³å®ããã
for-eachãã¿ã¼ã³ã®å¾ã«inãæ³å®ããã
【確èªver】Swift 4.0.2forã®æ¡ä»¶ã i in 0..<10ã®å½¢å¼ã®ã¨ãã¯()ãã¤ãã¦ã¯ãããªã
//4.0.2
for (i in 0..<10) { //ã¨ã©ã¼
}
C-style for statement has been removed in Swift 3
Cã¹ã¿ã¤ã«ã®foræã¯Swift 3ã§åãé¤ããã¾ãã
【確èªver】Swift 4.0.2//4.0.2
for (var i=0;i<10;i++) { //ã¨ã©ã¼
}
'let' pattern cannot appear nested in an already immutable context
æèããå¤æãã¦å®æ°ã«ãªãã¨ããã«、letã®ãã¿ã¼ã³ã¯ç¾ãã¦ã¯ãããªã
【確èªver】Swift 4.0.2 【èª】nest éãåããã 【ææ³】S appear nestedã¯SVC?//4.0.2
for let i in 0...10 { //ã¨ã©ã¼
}
letã¯ãããªã//Swift 3.0
let opInt: [Int?] = [2, 5, nil, 6]
for let a in opInt { //ã¨ã©ã¼ ã¢ã³ã©ãããããã¨ãã¦ããã...
}
åæã«ææ³ãä½ã£ã¦ã¯ã ãletãçãããã³ã³ãã¤ã«ã¨ã©ã¼ã¯ãªããªã
switch
説æã«ä½¿ãenumenum BloodType {
case A
case B
case O
case AB
}
'switch' statement body must have at least one 'case' or 'default' block; do you want to add a default case?
switchã¯æä½ã²ã¨ã¤ã®caseãdefaultãå¿
è¦。defaultãã¤ãããã?
【確èªver】Swift 4.0.2/4.0.2
let a = 1
switch a {
}
All statements inside a switch must be covered by a 'case' or 'default'
switchä¸ã®ãã¹ã¦ã®æã¯caseãdefaultã®ä¸ã«æ¸ããªãã¨ãããªã
【確èªver】Swift 4.0.2//4.0.2
let a = 1
switch a {
var b = 0 //ã¨ã©ã¼
}
Expected ':' after 'case'
caseã®å¾ã«ã¯:(ã³ãã³)ãå¿
è¦
【確èªver】Swift 4.0.2//4.0.2
switch bloodType {
case A //ã¨ã©ã¼
case B //ã¨ã©ã¼
case O //ã¨ã©ã¼
case AB //ã¨ã©ã¼
}
'case' label in a 'switch' should have at least one executable statement
switchä¸ã®caseãããã¯ã®ä¸ã¯æä½ï¼ã¤ã®å®è¡æãå¿
è¦
'default' label in a 'switch' should have at least one executable statement
switchä¸ã®defaultãããã¯ã®ä¸ã¯æä½ï¼ã¤ã®å®è¡æãå¿
è¦
【確èªver】Swift 4.0.2
var a = 5
switch a {
case 0: //ã¨ã©ã¼
default:
a += 5
}
switch a {
default: //ã¨ã©ã¼
}
breakãfallthroughãã¤ããã¨ã¨ã©ã¼ãæ¶ããè¤æ°ã®"å ´å"ã§åãå¦çãããã«ã¯"å ´å"ã,(ã«ã³ã)ã§åºåã£ã¦è¨è¿°ãã。
'fallthrough' without a following 'case' or 'default' block
fallthroughã®å¾ã«caseãdefaultããªã
【確èªver】Swift 4.0.2fallthroughã®å¾ã«ã¯caseãããã¯ãdefaultãããã¯ãã¤ãããã¨
//4.0.2
let a = 1
switch a {
default: fallthrough //ã¨ã©ã¼
}
ãã®å ´åã¯ãã§ã«defaultã¯ããã®ã§defaultãä»ããã¨ããææ¡ã¯ééãã ã、ã¨ã©ã¼ã¡ãã»ã¼ã¸ã®æç« ã¯ã¾ãããã§å¥ã«ããããªã¨ããæ°ã¯ãã。Additional 'case' blocks cannot appear after the 'default' block of a 'switch'
switchã®ä¸ã§defaultãããã¯ã®å¾ã«caseãæ¸ããã¨ã¯åºæ¥ã¾ãã
【確èªver】Swift 4.0.2//4.0.2
let a = 5
switch a {
default:
fallthrough
case 0: //ã¨ã©ã¼
//å¦ç
case 1:
//å¦ç
case 2:
//å¦ç
}
ããã¯åºæ¥ãããã«ãã¦ã»ããã、ä¸ããé ã«æ¡ä»¶ã«ãã¦ã¯ã¾ããã©ãã確ããã¦、ã©ãã«ããã¦ã¯ã¾ããªãã£ããæå¾ã«defaultãå®è¡ã¨ããå¦çãã³ã³ãã¤ã«ããããããããã«ç¦æ¢ããã¦ããã®ã ããã。Expected ':' after 'default'
defaultã®å¾ã«:ãå¿
è¦
defaultã§ã:ãå¿
è¦ã§ã。【確èªver】Swift 4.0.2
//4.0.2
switch a {
default //ã¨ã©ã¼
}
Expected pattern
Expected ':' after 'case'
æ³å®ããããã¿ã¼ã³(ãæ±ãããã)
caseã®å¾ã«:ãæ³å®ããã
【確èªver】Swift 3.0//Swift 3.0
switch a {
case default: //ã¨ã©ã¼
}
defaultã®åã«caseã¯ãããªãSwitch must be exhaustive
Switchã«ããå ´ååãã«ã¯ããããªããã¨ãå¿
è¦
【確èªver】Swift 4.0.2【èª】exhaustive ãã¾ãã¨ããã®ãªãå ´ååãã«ãããããã¨ãã«åºã
//4.0.2
switch bloodType {
case .A:
print("Aåã§ã")
case .B:
print("Båã§ã")
} //ã¨ã©ã¼ Oã¨ABããªã
//4.0.2
//ããã¯OK
var a = false
//å¦ç
switch a {
case true:
print("true")
case false:
print("false")
}
ããã¯Swift1.2ã§ã¯ãã¡ã ã£ãã、Swift2.1ã§ã¯OKã«ãªã£ã模æ§。'***' must be bound in every pattern
***ã¯å
¨ã¦ã®ãã¿ã¼ã³ã網ç¾
ããªãã¨ãããªã
【確èªver】Swift 4.0.2//4.0.2
var a = (1, 2)
switch a {
case (1, let b), (2, 2): //ã¨ã©ã¼
print(b)
default:
break
}
(2, 2)ã ã£ãã¨ãã«bã確å®ããªãã®ã§ã¨ã©ã¼'fallthrough' cannot transfer control to a case label that declares variables
ä¸ã«å¤æ°(å®æ°ã)宣è¨ãããcaseãããã¨ãã¯fallthroughã§ä¸ã«è¡ããªã
【確èªver】Swift 4.0.2//4.0.2
var a = (1, 2)
switch a {
case (1, 1):
fallthrough
case (1, let b):
print(b)
default:
break
}
(1, 1)ããä¸ã«æããã¨bã確å®ããªã。ãã®ä»ã®å¶å¾¡æ
'do-while' statement is not allowed; use 'repeat-while' instead
do-whileæã¯è¨±å¯ããã¾ãã。代ããã«repeat-whileã使ã£ã¦ãã ãã。
【確èªver】Swift 4.0.2 【èª】allow 許å¯ãã instead 代ããã«Swiftã®ä»æ§ã«do-try-catchã追å ãããã¨ãã«do-whileã®doã¯ä½¿ç¨ç¦æ¢ã«ãªãã¾ãã。
//4.0.2
do { //ã¨ã©ã¼
} while *****
//æ£ããä¾
repeat { //ã¨ã©ã¼åºã
} while *****
ã¢ã¯ã»ã¹ä¿®é£¾å
Function/Method cannot be declared public because its parameter/result uses an internal/private type
é¢æ°/ã¡ã½ããã¯publicã§å®£è¨åºæ¥ã¾ãã。å¼æ°/çµæ(æ»ãå¤)ã«internal/privateã®åã使ã£ã¦ããããã§ã
Function/Method must be declared private because its parameter/result uses a private type
é¢æ°/ã¡ã½ããã¯privateã§å®£è¨ãããªããã°ãããªã。å¼æ°/æ»ãå¤ãprivateãªãã®ã使ã£ã¦ãããã
【確èªver】Swift 2.0cannot be declared publicã¨must be declared privateã¯åããããªãã®ã ãæé¢ã«éããããã®ã¯、"publicãã¤ãã¦ã¯ãããªã"ã¨è¨ãããã®ã、"privateãã¤ããªãã¨ãããªã"ã¨è¨ãããã®ãã®éã。
ã¢ã¯ã»ã¹ä¿®é£¾åããªã«ãä»ãã¦ããªããã®ã¯internal(ã¢ã¸ã¥ã¼ã«å ã®ã¿ããã¢ã¯ã»ã¹è¨±å¯)
class AAA {
}
public func useAAA() -> AAA {//Function cannot be declared public
return AAA()
}
internalãªAAAãpublicãªfuncã§æ»ãå¤ã§ä½¿ç¨ãããã¨ããclass AAA {
}
public func useAAA(aaa: AAA) {//Function cannot be declared public
}
internalãªAAAãpublicãªfuncã§å¼æ°ã§ä½¿ç¨ãããã¨ããprivate class PrivateABC {
}
func theFunc(a: PrivateABC, b: PrivateABC) -> PrivateABC{//Function must be declared private
//å¦ç
return PrivateABC()
}
class InternalABC {
func theFunc(a: PrivateABC, b: PrivateABC) -> PrivateABC{//Function must be declared private
//å¦ç
return PrivateABC()
}
}
é¢æ°/ã¡ã½ããã®å¼æ°/æ»ãå¤ã®åãprivateã§ãã®é¢æ°/ã¡ã½ãããinternalã®ã¨ãProperty cannot be declared public because its type uses an internal type
ããããã£ã¯publicã§å®£è¨åºæ¥ã¾ãã。privateãªãã®ã使ã£ã¦ãããã
Property must be declared fileprivate because its type uses a private type
ããããã£ã¯fileprivateã§å®£è¨ãããªããã°ãããªã。privateãªãã®ã使ã£ã¦ãããã
【確èªver】Swift 4.0.2ãããæé¢ã«éããããã®ã¯、"publicãã¤ãã¦ã¯ãããªã"ã¨è¨ãããã®ã、"privateãã¤ããªãã¨ãããªã"ã¨è¨ãããã®ãã®éã。
//4.0.2
private class PrivateABC {
}
class InternalABC {
//Property must be declared fileprivate because its type uses a private type
var a: PrivateABC = PrivateABC() //ã¨ã©ã¼
}
public class PublicABC {
//Property cannot be declared public because its type uses an internal type
public var a: InternalABC = InternalABC() //ã¨ã©ã¼
}
Expected 'get', 'set', 'willSet', or 'didSet' keyword to start an accessor definition
ã¢ã¯ã»ãµå®ç¾©ã®éå§ã«ã¯'get', 'set', 'willSet', 'didSet'ãã¼ã¯ã¼ããè¦æ±ããã¾ã
【確èªver】Swift 4.0.2//4.0.2
class SomeInternalClass {
var a: Int {
get {
return self.a
}
private set { //ã¨ã©ã¼
self.a = newValue
}
}
}
privateã®ä½ç½®ãéã。private(set) var a: Int {ãªãã¨ã©ã¼ãåºãªã。
Attribute 'private' can only be used in a non-local scope
privateã¯ãã¼ã«ã«ãªã¨ããã§ã®ã¿ä½¿ãã
【確èªver】Swift 4.0.2//4.0.2
class SomeInternalClass {
var a: Int {
private set { //ã¨ã©ã¼
self.a = newValue
}
get {
return self.a
}
}
}
privateã®ä½ç½®ãéã。private(set) var a: Int {ãªãã¨ã©ã¼ãåºãªã。
Expected 'set' as subject of 'public/internal/private' modifier
'public/internal/private'ãã¤ããããsetãæå¾
ããã
【確èªver】Swift 4.0.2//4.0.2
public class SomePublicClass {
public var a: Int = 0 //ã¨ã©ã¼ãªã
public public(set) var b: Int = 0 //ã¨ã©ã¼ãªã
public internal(set) var c: Int = 0 //ã¨ã©ã¼ãªã
public private(set) var d: Int = 0 //ã¨ã©ã¼ãªã
public(get) var e: Int = 0 //ã¨ã©ã¼ãã
internal(get) var f: Int = 0 //ã¨ã©ã¼ãã
private(get) var g: Int = 0 //ã¨ã©ã¼ãã
public(get) public(set) var h: Int = 0 //ã¨ã©ã¼ãã
public(get) private(set) var i: Int = 0 //ã¨ã©ã¼ãã
private(get) private(set) var j: Int = 0 //ã¨ã©ã¼ãã
}
Swiftã®æ§æã¨ãã¦、setå´ã«ã¯private(set)ãªã©ãç¨æããã¦ããã、getå´ã«ã¯public(get)ã®ãããªãã®ã¯ãªã(Swift1.2ç¾å¨)ãã£ã¦ãããã®ã¨ã©ã¼ã¯public(get)ã«å¯¾ãã¦、ããã¯setã®ééããªã®ã§ã¯ãªããã¨ææããã¨ã©ã¼ã¡ãã»ã¼ã¸ã¨æããã。getã«ãsetã«ãprivateãè¨å®ãã¦ãããã®ã¯、ããã§ãprivateã®setãè¦æ±ããã¡ãã»ã¼ã¸ãåºã。ãããä¸ã®çç±ã«ããprivate(get)ãæ¸ããããã¨ãåå ã§åºã¦ãããã®ã¨æ¨æ¸¬。
Internal property cannot have a public setter
Internalã®ããããã£ã¯publicã®ã»ãã¿ã¼ãæã¦ãªã
【確èªver】Swift 4.0.2//4.0.2
public class SomePublicClass {
public(get) public(set) var h: Int = 0 //ã¨ã©ã¼
}
public(get)ãã ããªè¡¨è¨ãªã®ã§æå¹ã«ãªãã、internalã¨å¤æããã。nilã®æ±ã
'nil' requires a contextual type
nilã¯æèä¸ã®åãå¿
è¦ã§ã
【確èªver】Swift 4.0//Swift 4.0
var abcd = nil
Int?ãString?ãªã©ã®åã決ããªãã¨ã ã。Reference to member 'none' cannot be resolved without a contextual type
noneã¡ã³ãã¸ã®åç
§ã解éã§ãã¾ãã。å決å®ã®æ
å ±ããªãã®ã§。
【確èªver】Swift 3.1//Swift 3.1
let a = .none
Int?ãString?ãªã©ã®åã決ããªãã¨ã ã。Nil is incompatible with return type '***'
***åãè¿ãã¨ããã§、nilã¯äºææ§ãããã¾ãã。
【確èªver】Swift 4.0.2é¢æ°ã®æ»ãå¤ã«?ä»ãã§ãªããã®ã宣è¨ããã¦ããã®ã«nilãè¿ããã¨ãã
//4.0.2
func abc () -> String {
return nil //ã¨ã©ã¼
}
Nil cannot inititialize specified type '***'
nilã¯***ãåæååºæ¥ã¾ãã
【確èªver】Swift 4.0//4.0
var abc: String = nil //ã¨ã©ã¼
nilãå
¥ãããªãString?ã®åã«ããªãã¨ãããªã//4.0
var abcde: Any = nil //ã¨ã©ã¼
var intOpt: Int? = nil
var anyInt: Any = intOpt //è¦åãåºããã¨ã©ã¼ã§ã¯ãªã。
Anyåãnilã§åæååºæ¥ãªã。ãã ã、ãªãã·ã§ãã«åãAnyã«ä»£å
¥ããã®ã¯ã¨ã©ã¼ã§ã¯ãªã。Optional ãªãã·ã§ãã«
Cannot force unwrap value of non-optional type '***'
éãªãã·ã§ãã«ã®***åã¯å¼·å¶ã¢ã³ã©ããåºæ¥ã¾ãã
【確èªver】Swift 4.0.2//4.0.2
let c: Bool = true
var d = c! //ã¨ã©ã¼
Boolããªãã·ã§ãã«åã§ã¯ãªãValue of optional type '***?' not unwrapped; did you mean to use '!' or '?'?
ãªãã·ã§ãã«åã®'***?'ã¯ã¢ã³ã©ããããã¦ãã¾ãã。ãããããã¨ã¯、!ã?ã使ç¨ãããåºæ¥ãããªã®ã§ã¯?
【確èªver】Swift 4.0.2ãªãã·ã§ãã«åãã¢ã³ã©ããã®æå³ãããããªãå ´åã¯、ãªãã·ã§ãã«åã«ã¤ãã¦èª¿ã¹ã(å°ãæéããããã¾ã)
//4.0.2
var aStr = "1980"
var aInt = Int(aStr) + 23 //ã¨ã©ã¼
Int(aStr)ã¯ãªãã·ã§ãã«åãè¿ã//4.0.2
let array: Array? = ["a","b"]
for element in array { //ã¨ã©ã¼
}
ã¾ã、?ã使ã£ã¦array?ã«ãã¦ãã¨ã©ã¼ã¯åºã。!ããããã。//4.0.2
var abc: Bool
var abc2: Bool? = true
if abc = abc2 {
}
letå¿ãCannot use optional chaining on non-optional value of type '***'
***åã®éãªãã·ã§ãã«å¤æ°ã«ãªãã·ã§ãã«ãã§ã¤ã³ã使ããã¨ã¯åºæ¥ã¾ãã
【確èªver】Swift 4.0.2//4.0.2
let a: Bool = true
var b = a? //ã¨ã©ã¼
Optional chain has no effect, expression already produces '***?'
ãªãã·ã§ãã«ãã§ã¤ã³ã¯æå³ãããã¾ãã。ãã§ã«***?åã«ãªã£ã¦ãã¾ã。
【確èªver】Swift 4.0.2//4.0.2
let c: Bool? = true
var d = c? //ã¨ã©ã¼
A*** not found in type 'B***?'
B***?åã«A***ã¯ããã¾ãã
【確èªver】Swift 4.0.2ãªãã·ã§ãã«åãã¢ã³ã©ããããªãã¾ã¾ã§ä½ãããã¨ããªã©
//4.0.2
enum TestEnumUnion {
case testUnionStr(String)
case testUnionInt(Int, Int)
}
let a = TestEnumUnion.testUnionInt(0, 0)
let aa = ["aa" : a]
if case .testUnionInt(0, 0) = aa["aa"] { //ã¨ã©ã¼
}
if case .testUnionInt(0, 0)? = aa["aa"]ã¨ããã¨OKImplicitly unwrapped optionals are only allowed at top level and as function results
æé»ã¢ã³ã©ãããªãã·ã§ãã«ã¯ãããã¬ãã«ãé¢æ°ã®æ»ãå¤ã®ã¿è¨±ããã
【確èªver】Swift 3.0//Swift 3.0
let arrayTest: [Int!] = [1, 2, 3, 4, 5] //ã¨ã©ã¼
é
åã®å®ç¾©ã、ã¿ãã«ã®å®ç¾©ã§ã¯Int!ãªã©ã®æé»ã¢ã³ã©ãããªãã·ã§ãã«ã¯ä½¿ããªã。Expression implicitly coerced from '***?' to Any
***?åãå¼·å¶çã«Anyã«å¤æããã
【確èªver】Swift 3.0.2【èª】coerce ç¡çããããã//Swift 3.0.2
var any: Any = UIImage(named: "aaa") //ã¨ã©ã¼
UIImage(named:)ã®æ»ãå¤ã¯ãªãã·ã§ãã«。åç
§ã«ã¦ã³ã¿
weakã¨unownedã¯ã¨ãã«å¯¾è±¡ãä¿æããªãå°。weakå¤æ°ã¯ãªãã·ã§ãã«åã«ä½¿ããåç
§å
ãæ¶ãããnilã«è¨å®ããã(nilãè¨å®ããã®ã§ãªãã·ã§ãã«åã«ãã使ããªã)。unowndå¤æ°ã¯éãªãã·ã§ãã«åã«ä½¿ããåç
§å
ãæ¶ãã¦ããã®ã¾ã¾ã§、æ¶ããåç
§å
ã«ã¢ã¯ã»ã¹ããã¨ã¯ã©ãã·ã¥ãã。ä¿æã®æå³ãããããªãã¨ãã®æ¨è¦æ¤ç´¢ç¨èªã¯strong weak ARC åç §ã«ã¦ã³ã¿
'weak'('unowned') may only be applied to class and class-bound protocol types, not '***'
'weak'('unowned')ã¯ã¯ã©ã¹(ã¯ã©ã¹ãã¦ã³ããããã³ã«å«ã)ã«ã®ã¿ä½¿ãã。***ã¯ã ã。
【確èªver】Swift 4.0.2【éæ¹ã«ããã度】★★★//Swift 4.0.2
unowned var a: UIView? //ã¨ã©ã¼
ä¸ã®è§£èª¬åç
§ãªãã·ã§ãã«ã¯ã ã
//Swift 4.0.2
unowned var b: Int = 0 //ã¨ã©ã¼
//Swift 4.0.2
weak var h: Int? = 0 //ã¨ã©ã¼
'weak' variable should have optional type '***?'
weakã¯ãªãã·ã§ãã«åã«ä½¿ãããã¹ãã§、ããã¯'***?'
【確èªver】Swift 4.0.2//Swift 4.0.2
weak var b: UIView //ã¨ã©ã¼
ä¸ã®è§£èª¬åç
§'weak' must be a mutable variable , because it may change at runtime
weakã¯(letã§ãªã)var宣è¨ã®å¤æ°ã§ããã¹ãã§、çç±ã¯å®è¡ä¸ã«å¤æ´ãããå¯è½æ§ããããã
【確èªver】Swift 4.0.2//Swift 4.0.2
weak let a: UIView? //ã¨ã©ã¼
ä¸ã®è§£èª¬åç
§as
Downcast from '***?' to '***' only unwraps optionals; did you mean to use '!'
'***?'ãã'***'ã¸ã®ãã¦ã³ãã£ã¹ãã¯ãã ãªãã·ã§ãã«ãã¢ã³ã©ããããã ãã§ã。ãããã¨ãã¦ãããã¨ã¯'!'ã§åºæ¥ã¾ããã?
【確èªver】Swift 2.0Swift2.0ã§çºçããå°ãè¬ã«æããã³ã³ãã¤ã«ã¨ã©ã¼。
var a: Int? = nil
var aa = a as? Int//ã¨ã©ã¼
as?ã¯ãã£ã¹ããããã¨ãã¦ããç®æ¨ã®åã®ãªãã·ã§ãã«åãè¿ãã、ãã®å ´åã¯Int?ããInt?ã¸ã®å¤æã¨ãªã、å¤æåã¨å¤æå¾ãåã。ãªã®ã§æå³ããªãã¨ããã³ã³ãã¤ã©ã®ææ。å¾åã®「ãããã¨ãã¦ãããã¨ã¯'!'ã§åºæ¥ã¾ããã?」ã¯ããã¤ããã解決çã®ãã¡ã®ã²ã¨ã¤ã¨ããæãã§åèç¨åº¦ã«æãã。Int?ããInt?ã¸å¤æ´ãã¦ãä½ãä¸å
·åã¯åºãªãã®ã§èµ¤è¦åã«ãããã¨ããªãããããªããã¨ããæ°ããã。aså¨ãã¯å¾®å¦ãªå¤æ´ãå¤ããã¾ã ä»æ§ãæºãã¦ããç¶æ
ã。var a: Int? = nil
if let aa = a as? Int {//ã¨ã©ã¼
}
ãã®ä¸ã®if letç³»ãã¿ã¼ã³ã§åºã人ãå¤ãã¨æã。ä¸ã®ããã«å¤æ´ããã°ãã。// æ£ããä¾
var a: Int? = nil
//ä½ãã®å¦ç
if let aa = a{
}
// aãInt?ã®ã¨ã
if a is Int { //ã¨ã©ã¼
}
ãªãã·ã§ãã«å(Int?)ãéãªãã·ã§ãã«å(Int)ãã®èª¿æ»ã«isã¯ä½¿ããªã。is asã¯ç¶æ¿é¢ä¿éã®èª¿æ»、å¤æ´ã«ä½¿ãããã®ãåºæ¬。'AnyObject' is not convertible to '***'; did you mean to use 'as!' to force downcast?
AnyObjectåã***åã«å¤æåºæ¥ã¾ãã。as!ã使ã£ãå¼·å¶ãã¦ã³ãã£ã¹ããªããããããã¨ãåºæ¥ãã®ã§ã¯?
【確èªver】Swift 4.0.2//4.0.2
class A {
}
var abc: AnyObject = A()
var abc2: A = abc //ã¨ã©ã¼
String, Character
Invalid use of '()' to call a value of non-function type 'Int'
Intã¨ããå¤(éé¢æ°)ã«å¯¾ãã¦、()ã®ééã£ã使ç¨
【確èªver】Swift 2.0let testArray = ["a", "b"]
let num = testArray.count()
countã«()ããããªãlet str = "ABCDE"
var num = str.count()
countã«()ããããªãã¡ãªã¿ã«Swift 2.0ã®æ®µéã§ã¯str.characters.countããããã。
ãã ãObjective-Cã¨ã«ã¦ã³ãçµæãæããããªãstr.utf16.countããããã。
'***' is unavailable: there is no universally good answer, see the documentation comment for discussion
***ã¯ä½¿ãã¾ãã。ããã¥ã¡ã³ãã®èª¬æãè¦ã¦ãã ãã。(there is no universally good answerã¯ã³ã³ãã¤ã©ãææ¡ã®ã¢ããã¤ã¹ãå¤æã§ããªãç¶æ
ã?)
【確èªver】Swift 3.0//Swift 3.0
let str = "ABCDE"
var num = str.count //ã¨ã©ã¼
Swift 3.0ã®æ®µéã§ã¯str.characters.countããããã。ãã ãObjective-Cã¨ã«ã¦ã³ãçµæãæããããªãstr.utf16.countããããã。
ã¨ã©ã¼å¦ç
Swift2.1ã®æç¹ã§、- tryã¯、ã¨ã©ã¼å¦çãå¿ è¦、do catchã§å²ããªã、ä¸(å¼ã³åºãå )ã«æãããªããã¦ãã ãã。
- try?ã¯、ã¨ã©ã¼å¦çã¯ãããªã。ã¨ã©ã¼ãèµ·ãã¦ãtry?ãæ¸ããã¦ããå¦çã®æ¬¡ã®è¡ãå®è¡ãã¾ã。ãã ã、ã¨ã©ã¼ãèµ·ããæã¯try?ãæ¸ããã¦ããå¦çã®æ»ãå¤ã«nilãå ¥ããã®ã§ãªãã·ã§ãã«ã§å®£è¨ãã¦ããã¦ãã ãã。
- try!ã¯、ã¨ã©ã¼å¦çã¯ãããªã。ã¨ã©ã¼ãèµ·ãããå®è¡æã¨ã©ã¼ã«ãªãã¾ã。
//4.0
enum MyError: Error {
case myError
}
func someThrowingFunction() throws -> Int {
if æ¡ä»¶ {
throw MyError.myError
}
return 0
}
func someFunction() {
someThrowingFunction() //Call can throw, but it is not marked...
try someThrowingFunction() //Errors thrown from here are not handled
try? someThrowingFunction() //OK
try! someThrowingFunction() //OK
let a: Int = try someThrowingFunction() //Errors thrown from here are not handled
let b: Int = try? someThrowingFunction() //Value of optional type '***?' not unwrapped...
let c: Int? = try? someThrowingFunction() //OK
let d: Int = try! someThrowingFunction() //OK
}
Expected throwing specifier; did you mean 'throws'?
throwããæå®åãæ³å®ããã
【確èªver】Swift 4.0//4.0
func abc() throw { //ã¨ã©ã¼
}
throwã§ã¯ãªãthrows。Call can throw, but it is not marked with 'try' and the error is not handled
(ã¡ã½ãã)å¼ã³åºãã¯(ã¨ã©ã¼ã)æããå¯è½æ§ãããã¾ã。ãããtryãæ¸ããã¦ããªãã®ã§ã¨ã©ã¼ãå¦çåºæ¥ã¾ãã。
【確èªver】Swift 4.0.2ä¸ã®ãµã³ãã«ãåç §。
do catchã§å²ããªã、ä¸(å¼ã³åºãå )ã«æãããªããã。
Errors thrown from here are not handled
ããã§æããããã¨ã©ã¼ã¯å¦çããã¾ãã(å¦çãæ¸ãã¦ãã ãã)
【確èªver】Swift 4.0.2 ä¸ã®ãµã³ãã«ãåç §。
do catchã§å²ããªã、ä¸(å¼ã³åºãå )ã«æãããªããã。
Value of optional type '***??' not unwrapped; did you mean to use 'try!' or chain with '?'
ãªãã·ã§ãã«åã®***??ã¯ã¢ã³ã©ããããã¦ãã¾ãã。ãããã¨ãã¦ãããã¨ã¯try!ã?ã®é£ç¶ã§åºæ¥ã¾ããã?
【確èªver】Swift 4.0.2 【å±éºåº¦】★★★★★try?ã使ã£ãã¨ãã«åºã。ä¸ã®ä¾ã§ã¯bã¸ã®ä»£å ¥ã®ã¨ããã§åºã¦ãã。try?ã®æã¯ã¨ã©ã¼ãçºçãã¦ã次ã®æã¸ç§»ã。ã¨ã©ã¼ãåºãã¨ãã¯bã«ã¯nilãå ¥ã£ã¦、ã¨ã©ã¼ã®çºçã®æç¡ã確èªã§ããããã«ãã。someThrowingFunction()ã¯Intãè¿ãã¡ã½ããã ã、nilã許容ããããã«bã¯Int?ã¨ããªããã°ãããªã。åæå®ããªããã°èªåã§Int?ã¨ãªã。
ã¾ãã¡ãã»ã¼ã¸ã®æå¾ã®chain with '?'ãè¬ã§ããã、次ã®æ§ã«ã¡ã½ããããªãã·ã§ãã«ãè¿ãã¨å®ç¾©ããã¦ããã¨ãã«try?ã®æ»ãå¤ã®åãInt??ã¨ãªãã、ããã®ãã¨ããªã¨ããæ°ããã。
//4.0.2
enum MyError: Error {
case myError
}
func someThrowingFunctionOPT() throws -> Int? {
if æ¡ä»¶1 {
throw MyError.myError
} else if æ¡ä»¶2 {
return 0
}
return nil
}
func someFunction() {
let e: Int? = try? someThrowingFunctionOPT() //Value of optional type '***?' not unwrapped...
let f: Int?? = try? someThrowingFunctionOPT() //OK
}
Int?ãæããã¡ã½ããã«å¯¾ãã¦try?ã使ç¨ãã¦ããã®ã§æ»ãå¤ã¯Int??ã¨ãªã。ã¾ã、ãã®ã¡ã½ããã®å±éºåº¦ã5ã¨ããã、fix-itã§åºã¦ããtry!ãé¸ã¶ã¨ã¨ã©ã¼çºçã®ã¨ãã«å®è¡æã¨ã©ã¼ã¨ãªãã®ã§å±éº。
Expected expression in 'throw' statement
throwæã®ä¸ã«æ³å®ããããã®ããªã
【確èªver】Swift 4.0//4.0
throw //ã¨ã©ã¼
throwã®å¾ã«ã¨ã©ã¼ãæ¸ããªãã¨ãããªã。Error is not handled because the enclosing function is not declared 'throws'
ã¨ã©ã¼ã¯å¦çããã¾ãã。ãã®å ´æãå²ã£ã¦ããé¢æ°ãthrowsãæ¸ãã¦ãªãããã§ã。
【確èªver】Swift 4.0//4.0
enum MyError: Error {
case a
}
func testFunc() {
throw MyError.a //ã¨ã©ã¼
}
'try' must be placed on the initial value expression
tryã¯åæå¤å¼ã«ç½®ãæããªãã¦ã¯ããã¾ãã
【確èªver】Swift 4.0.3//4.0.3
do {
try let player = AVAudioPlayer(contentsOf: fileURL) //ã¨ã©ã¼
player.play()
} catch let error as NSError {
print("Failed to make the audio player \(error.localizedDescription)")
}
let player = try AVAudioPlayer(contentsOf: fileURL) ã«ããã¨ã¨ã©ã¼ã¯æ¶ãã。Closure ã¯ãã¼ã¸ã£
Unable to infer closure type in the current context
ãã®æ¸ãæ¹ã§ã¯ã¯ãã¼ã¸ã£ã®åãæ¨æ¸¬ãããã¨ãåºæ¥ã¾ãã
【確èªver】Swift 3.0.1//Swift 3.0.1
let closureA = { Void -> Void in //ã¨ã©ã¼
}
let closureB = { (Void) -> Void in //ã¨ã©ã¼
}
ã¯ãã¼ã¸ã£ã®å®ç¾©ã§å¼æ°ã¯Voidã«ã§ããªã。Unable to infer complex closure return type; add explicit type to disambiguate
è¤éãªã¯ãã¼ã¸ã£ã®æ»ãå¤ã®åãæ¨æ¸¬ãããã¨ãåºæ¥ã¾ãã。ææ§ãããªããããã«ã¯ã£ããåãæ¸ãã¦ãã ãã。(æ訳)
【確èªver】Swift 3.0.1【èª】explicit ã¯ã£ããã¨ãã disambiguate éããæããã«ãã//Swift 3.0.1
class A {
}
let a1 = { //ã¨ã©ã¼
let a = A()
return a
}()
let a2 = { () -> A in //OK
let a = A()
return a
}()
Instance member 'A***' cannot be used on type 'B***'
Båã§、ã¤ã³ã¹ã¿ã³ã¹ã¡ã³ãã¼Aã¯ä½¿ãã¾ãã
【確èªver】Swift 3.0.1//Swift 3.0.1
class Test {
var a: Int = 0
let closureA = {
(num: Int) -> Void in
a = num + 3 //ã¨ã©ã¼
}
}
ã¯ãã¼ã¸ã£ã§ãªãã¡ã½ããã«ããã°ä½¿ããUse of unresolved identifier 'self'
selfãä½ããããã¾ãã
【確èªver】Swift 3.0.1//Swift 3.0.1
class Test {
var a: Int = 0
let closureA = {
(num: Int) -> Void in //ã¨ã©ã¼
self.a = num + 3 //ã¨ã©ã¼
}
}
ã¯ãã¼ã¸ã£ã§ãªãã¡ã½ããã«ããã°aã«ã¢ã¯ã»ã¹åºæ¥ã。Reference to property '***' in closure requires explicit 'self.' to make capture semantics explicit
ã¯ãã¼ã¸ã£ã®ä¸ã®***ããããã£ã¸ã®åç
§ã¯æ確ãªself.ãå¿
è¦。ã¤ãã¿æ¹ãæ確ã«ããããã«
【確èªver】Swift 3.0.1//Swift 3.0.1
class Test {
var a: Int = 0
func funcA() {
let closureA = {
(num: Int) -> Void in
a = num + 3 //ã¨ã©ã¼
}
}
}
self.aã«ããã¨OK。Call to method '***' in closure requires explicit 'self.' to make capture semantics explicit
ã¯ãã¼ã¸ã£ã®ä¸ã®***ã¡ã½ããã¸ã®åç
§ã¯æ確ãªself.ãå¿
è¦。ã¤ãã¿æ¹ãæ確ã«ããããã«
【確èªver】Swift 3.0.2//Swift 3.0.2
DispatchQueue.main.asyncAfter(deadline: .now() + 0.01) {
display()
}
(display()ãselfã®ã¡ã½ãããªã)self.display()ã«ããã¨OK。Generics ã¸ã§ããªã¯ã¹
Cannot explicitly specialize a generic function
ã¸ã§ããªãã¯ã®ãã¡ã³ã¯ã·ã§ã³ã¯æ確ãªå½¢æå®ãåºæ¥ã¾ãã
【確èªver】Swift 3.0.2//Swift 3.0.2
func abc<T>(a: T) -> T {
return a
}
let b = abc<Int>(a: 0) //ã¨ã©ã¼
Tã®æ
å ±ã¯å¼æ°ã§ä¸ãããæ»ãå¤ã§ä¸ããlet b = abc(a: 0)ã§OK。
Generic parameter '*' could not be inferred
ã¸ã§ããªãã¯ãã©ã¼ã¡ã¼ã¿ã®*ã®åãæ¨è«åºæ¥ã¾ãã
【確èªver】Swift 3.0.2//Swift 3.0.2
func abc<T>(a: IntegerLiteralType) -> T? {
return a as? T
}
let aaa = abc(a: 0) //ã¨ã©ã¼
æ»ãå¤ããæ¨è«ããã¿ã¤ããªã®ã§、代å
¥ããaaaãåæ
å ±ãæããªãã¨æ±ºå®ã§ããªã。ãã®ä»ã®ææ³
Found an unexpected second identifier in typealias declaration; is there an accidental break?
Expected '=' in typealias declaration
typealiasã®å®£è¨ã§æ³å®ãããªã2ã¤ãã®èå¥åãè¦ã¤ããã¾ãã。空ç½ãå
¥ã£ã¦ãã¾ããã?
typealias宣è¨ã§ã¯=ãå¿
è¦ã§ã
【確èªver】Swift 4.0.2//4.0.2
//(ééã£ãä¾)
typealias Score UInt8
//4.0.2
//(æ£ããä¾)
typealias Score = UInt8
'continue' is only allowed inside a loop
continueã¯ã«ã¼ãã®å
é¨ã§ã®ã¿è¨±å¯ããã¾ã(使ç¨åºæ¥ã¾ã)
'break' is only allowed inside a loop, if, do, or switch
breakã¯ã«ã¼ããifãdoã®å
é¨、ãããã¯switchã®å
é¨ã§ã®ã¿è¨±å¯ããã¾ã(使ç¨åºæ¥ã¾ã)
Unlabeled 'break' is only allowed inside a loop or switch, a labeled break is required to exit an if or do
(breadã®å¾ãã«)ã©ãã«ããªãbreakã¯ã«ã¼ããswitchå
ã§ã¯ä½¿ãã¾ãã。ifãdoããæããã«ã¯ã©ãã«ä»ãã®breakãå¿
è¦ã§ã
【確èªver】Swift 2.1ãããã¯ã«ã¼ããswitchã§ããªãã¨ããã§æ¸ãããã¨ãã«åºã。
é£ã³å ã®ã©ãã«æå®ã«åé¡ãããã¨ãã«åºã。
label1: for i in 0...9 {
print("in label1")
label2: for j in 0...9 {
print("in label2")
}
break label2 //ã¨ã©ã¼ 'break' is only allowed inside a loop
}
ä½ãåæ¥ããã®ãããããªã//(ç¹æ®ãªä¾)
label1: for i in 0...9 {
print("in label1")
label2: for j in 0...9 {
print("in label2")
if(j == 5) {
continue label3 //ã¨ã©ã¼ 'continue' is only allowed inside a loop
}
}
}
é£ã³å
ã®ã©ãã«ãå®ç¾©ããã¦ããªãã¨ãããã®ã¨ã©ã¼ãåºãif true {
break //ã¨ã©ã¼ Unlabeled 'break' is only allowed inside a loop or switch
}
ifã®åã«ã©ãã«ãå¿
è¦。//4.0
func testFunc(condition: Bool) {
guard condition else {
break
} //ã¨ã©ã¼
}
guardããåºãã®ã«breakã使ã£ã。ãã®å ´å、returnã使ããã¨。Labels are only valid on loops, if, and switch statements
ã©ãã«ã¯ã«ã¼ããif switchæã§ã®ã¿æå¹ã§ã
//4.0
let a = 5
switch a {
case 0:
print(a)
case 1:
print(a)
defalut: //ã¨ã©ã¼
break
}
defaultã®ã¤ã¥ãééã。switchæã ãã©ä½¿ãæ¹ãããããã®ã§ã¨ã©ã¼。Expected platform name
ãã©ãããã©ã¼ã ã®ååãæ³å®ããã
Expected ')' in availability query
#availableã®å¼æ°é¨åã«)ãæ³å®ããã。
//4.0
if #available(11.0, *) { //ã¨ã©ã¼
} else {
}
(iOS 11.0, *)ãªãOK。print
æã¯ããããããªãã¨ã©ã¼ã¡ãã»ã¼ã¸ã ã£ãã、Swift2.0ãããã§å¼æ°ã§ä¸ãããããã®ãã²ã¨ã¤ã²ã¨ã¤Stringã«å¤æãã¦ããå¦çã«å¤æ´ã«ãªã£ãã®ã§ç´ ç´ã§ãããããããªã£ã。ãã®è¨äºãæ¸ãããããªã£ã。ãã println(æã®è¨æ³)ã使ã£ãã¨ãã«åºãã¨ã©ã¼ã「printã使ã£ã¦ãã ãã」ã§ã¯ãªãå¥ã®ãã®ã§ãããã¨ããã。ãã©ã¡ã¼ã¿ã®ä¸ãæ¹ã¯printã§ã¯ééã£ã¦ããªããã®ã§ãåºã¦ãã¾ãã®ã§æ³¨æ。'println()' is unavailable: use print("")
println()ã¯ä½¿ããªããªãã¾ãã。print("")ã使ã£ã¦ãã ãã
【確èªver】Swift 2.1【å¤ãææ³åº¦】★★★println
Cannot invoke 'println' with an argument list of type '(***)'
ãã®å¼æ°ã®ãªã¹ãã§ã¯printlnãå®è¡ã§ãã¾ãã
【確èªver】Swift 2.1【ãã¼ã¸ã§ã³ã¢ããã§ä¿®æ£ãããå¯è½æ§ãé«ã度】★★★println(å¤ãæ¹)ã使ã£ã¦è¤éãªå¼æ°ãä¸ããã¨åºã。printlnã使ã£ã¦ãããã¨ãã ããªã®ã§printã使ãã¨ããå 容ãåºãã¦æ¬²ãã。ãã¼ã¸ã§ã³ã¢ããã§ä¿®æ£ãããå¯è½æ§ãé«ã。
print(æ°ããæ¹)ã¸ã®å¼æ°ã®ä¸ãæ¹ã¨ãã¦ã¯OKãªãã®ã§ãåºã。
abc = 5
println("abcdef","abcdef",abc) //ã¨ã©ã¼、ãã ãprintã®å¼æ°ã¨ãã¦ã¯OK
println(abc,"abcdef","abcdef") //ã¨ã©ã¼、ãã ãprintã®å¼æ°ã¨ãã¦ã¯OK
println("abcdef",abc,"abcdef") //ã¨ã©ã¼、ãã ãprintã®å¼æ°ã¨ãã¦ã¯OK
Cannot convert value of type '***' to expected argument type 'inout ...'
inoutãæ³å®ããã¦ããã¨ããã§***ãä¸ãããã¦ãå¤æã§ãã¾ãã
【確èªver】Swift 2.1【ãã¼ã¸ã§ã³ã¢ããã§ä¿®æ£ãããå¯è½æ§ãé«ã度】★★★ä¸ã®ã¨åãããã«、println(å¤ãæ¹)ã使ã£ã¦è¤éãªå¼æ°ãä¸ããã¨åºã。printlnã使ã£ã¦ãããã¨ãã ããªã®ã§printã使ãã¨ããå 容ãåºãã¦æ¬²ãã。ãã¼ã¸ã§ã³ã¢ããã§ä¿®æ£ãããå¯è½æ§ãé«ã。
print(æ°ããæ¹)ã¸ã®å¼æ°ã®ä¸ãæ¹ã¨ãã¦ã¯OKãªãã®ã§ãåºã。
var abc = 5
println(abc,abc) //ã¨ã©ã¼、ãã ãprintã®å¼æ°ã¨ãã¦ã¯OK
println("abcdef",abc) //ã¨ã©ã¼、ãã ãprintã®å¼æ°ã¨ãã¦ã¯OK
println(abc,"abcdef") //ã¨ã©ã¼、ãã ãprintã®å¼æ°ã¨ãã¦ã¯OK
'print' is unavailable: Please wrap your tuple argument in parentheses: 'print((...))'
(å¼æ°ãªãã§ã®)printã¯ä½¿ãã¾ãã。丸ã«ãã³ã®ä¸ã«ã¿ãã«ã§å¼æ°ãå
¥ãã¦ãã ãã。
【確èªver】Swift 2.1print()
Invalid character in source file
ã½ã¼ã¹ãã¡ã¤ã«ã«ç¡å¹ãªæåãããã¾ã
【確èªver】Swift 2.1【èª】Invalid ç¡å¹ãªvar num = 3
print(\(num)) //ã¨ã©ã¼
""å
ã§ã¯ãªãã®ã«\()è¨æ³ã使ã£ã。ããã¯print(num)ã¨ããã°åãä»ãã。var num = 3
print("There are" + \(num)) //ã¨ã©ã¼
print("There are" , \(num)) //ã¨ã©ã¼
""å
ã§ã¯ãªãã®ã«\()è¨æ³ã使ã£ã。ããããprint("There are \(num)")ã¨ããã°OKFix-itãåºã¦ãã¾ãã、ãããé©ç¨ãã¦ãå¤ã«ãªãã¾ã。
Expression implicitly coerced from '***?' to Any
***?ããAnyã«è£ã§å¼·å¶å¤æããã¾ã
【確èªver】Swift 3.1【èª】coerce ã«å¼·å¶ãã"be+åã身"ã®beåè©ããªã?
//3.1
var a: Int? = 0
print(a) //ã¨ã©ã¼
printã«ãªãã·ã§ãã«ãä¸ããã¨ãSwiftã®ãã¼ã¸ã§ã³å¤å
'A***' has been renamed to 'B***'
A***ã¯ååãå¤ãã£ã¦B***ã«ãªãã¾ãã
【確èªver】Swift 3.0.2【å¤ãææ³åº¦】★★★//Swift 3.0.2
NSBundle //ã¨ã©ã¼ Bundleã«ãªã£ã
NSFileManager //ã¨ã©ã¼ FileManagerã«ãªã£ã
FileManager.defaultManager //ã¨ã©ã¼ FileManager.defaultã«ãªã£ã
//Swift 3.0.1
class A: UIView {
func funcA() {
let next = self.nextResponder //ã¨ã©ã¼
}
}
nextResponderã¯nextã«ãªã£ã。//Swift 2.1
println("ããã«ã¡ã¯") //ã¨ã©ã¼
printlnã¯printã«ãªã£ã。Swift 2.1ã®ã¨ãã¯ååãå¤ãã£ã¦éããªãã®ã§ãã®è¦ªåãªã¨ã©ã¼ã¡ãã»ã¼ã¸ã ã£ãã、Swift3.1ã§ã¯Use of unresolved identifier 'println'ã¨ããå·ããã¡ãã»ã¼ã¸ã«ãªã£ã。
Argument A*** must precede argument B***
å¼æ°A***ã¯å¼æ°B***ããå
ã«ããã¹ã
【確èªver】Swift 3.0.2//Swift 3.1
var abc = [Int](count: 10, repeatedValue: 1) //ã¨ã©ã¼
countã¨repeatedValueã¯ãããã¼ã¸ã§ã³ã§ä½ç½®ãå
¥ãæ¿ãã£ã。(ä»ã«ååã®å¤æ´ããã)//Swift 3.1
func abcFunc(a: Int, b: Int){
}
abcFunc(b: 4, a: 1) //ã¨ã©ã¼
決ããããé çªã§ãããªãã¨ã ã。Argument A must precede unnamed argument #*
å¼æ°Aã¯ã®ååã®ç¡ã*çªç®ã©ãã«ããå
ã«ããªãã¨ããã¾ãã
【確èªver】Swift 3.1//Swift 3.1
func abcFunc(a: Int, b: Int){
}
abcFunc(4, a: 1) //ã¨ã©ã¼
aãåãã«æ¥ãã¹ãã ã、è¬ã®4ããã。ãã®ä»、Expectedç³»ãªã©
Swiftã®ã³ã³ãã¤ã«ã¨ã©ã¼ã§ã¯Expectedã¨ããåèªãããåºã¦ãã¾ã。åç´ã«è¨³ãã¨æå¾
ããã¦ããã¨ããæå³ã§ãã、æ¸ããããã¨ãæ³å®ããã¦ãããã®ãä½ãããããããæ¸ããã¦ããªã、ã¨ãããã¥ã¢ã³ã¹ã§ä½¿ããããã¨ãå¤ãã§ã。Use of unresolved identifier '***'
ã³ã³ãã¤ã©ãå¤æåºæ¥ãªãä½ã('***')ãæ¸ããã¦ãã
【確èªver】Swift 3.1//Swift 3.1
var aInt = 0
switch aInt {
case 0:
fall //ã¨ã©ã¼
case 1:
break
default:
break
}
ãã®å ´åã¯fallã§ã¯ãªãã¦fallthrough。//Swift 3.1
swich //ã¨ã©ã¼
宣è¨ããã¦ããªããã®ãæ¸ããã¦ãã。ãã®å ´åã¯ã¤ã¥ãééã。//Swift 3.1
enum Blood {
case A
case B
case O
case AB
}
let abc = Blood.A
switch abc {
case A: //ã¨ã©ã¼
print("A")
case B: //ã¨ã©ã¼
print("B")
case AB: //ã¨ã©ã¼
print("AB")
case O: //ã¨ã©ã¼
print("O")
}
enumã®è¦ç´ ãæ¸ãæã«å
é ã®.(ããã)ãå¿ããæ。switchæã®caseã®è¡¨è¨ãªã©。//Swift 3.1
print(Hello, world) //ã¨ã©ã¼
æ¬æ¥""ã§å²ãã¹ãã¨ããã§ãããå¿ãã¦ãã//Swift 3.1
var a = (1, 2)
switch a {
case (value, 0...10): //ã¨ã©ã¼
print("")
case (0...10, value): //ã¨ã©ã¼
print("")
default:
print("")
}
caseå
ã§letå¿ã//Swift 3.1
var a: Int = 0 {
get { //ã¨ã©ã¼
return 2.0 * M_PI
}
}
Use of unresolved identifier 'get'ã¨ã³ã³ãã¤ã©ã«è¨ããã。ã¹ãã¢ãããããã£å®ç¾©ã¨æ¼ç®ããããã£å®ç¾©ãæ··ä¹±ãã¦ãã。æ¼ç®ããããã£ã«ããããªã=0ã®åæå¤ã¯ãããªã。//Swift 3.1
println("ããã«ã¡ã¯") //ã¨ã©ã¼
Expected declaration
宣è¨ãæå¾
ããã
【確èªver】Swift 3.0.2【èª】declaration 宣è¨ä½ãã宣è¨ãããã¤ããã§éä¸ã§ãããã¨ã
宣è¨ãæ¸ããªãã¨ãããªãã¨ããã§ä½ãå¤ãªãã®ãæ¸ããã¨ãã«åºã
//Swift 3.1
class A {
a = 0 //ã¨ã©ã¼
static b: Int = 0 //ã¨ã©ã¼
}
varãletå¿ãclass TestView: UIView {
//ã¯ã©ã¹å®ç¾©ã®éãæ¬å¼§}ããªã
//ãã¡ã¤ã«ã®çµããã§ã¨ã©ã¼
ã¯ã©ã¹å®ç¾©ã®éãæ¬å¼§}å¿ãã¯å®£è¨ã®æªå®æã¨å¤æããã¦ãã®ã¨ã©ã¼ãåºãclass SomeClass {
let someInstance: Int
someInstance = 5 //ã¨ã©ã¼
init() {
}
}
宣è¨æ¸ã¿ã®å¤æ°ã«ãã®å ´æã§å¤ãä¸ãããã¨ã¯åºæ¥ãªã。宣è¨ã¨åæã«åæå¤ãä¸ãããã¨ã¯åºæ¥ã。Expected expression
(æ£ãã)å¼ãæå¾
ããã
【確èªver】Swift 2.1ããªããããããªç¶æ³ã§åºã。ã³ã³ãã¤ã©ãåæãã¦ããã¨ãã«äºæãã¦ããªããã®ãåºã¦ããå ´åã«å¤ã。
äºæ³ã ã、ãã®ã¨ã©ã¼ã¯ä½ã「æ¸ãããå¿ è¦ããããã®」ãæ¸ããã¦ããªãã¨ãã«åºãã®ã§ã¯ãªãã、ã¨æããã。ã¾ã、ãã®「æ¸ãããå¿ è¦ããããã®」ã¯ã¨ã©ã¼ç®æããåã®é¨åã«ãã³ãããããã¨ããã、ã¨æããã。
(ä¾1)ä½ããæ¸ãã¤ããã§éä¸ã§ããã
(ä¾2)å¥ã®è¨èªã®ææ³ã§æ¸ãã。ä¾ãã°Objective-Cãªã©
let a: Bool = true
var b = a? 1:0 //ã¨ã©ã¼
3é
æ¼ç®åã®ã¤ããã§ããã°ã©ã ãæ¸ãã¦ãããã³ã³ãã¤ã©ã«ã¯ãªãã·ã§ãã«ãã§ã¤ã³ã¨èªèããã¦、ãã®å¾ã®1:0ãç解ã§ããªã。3é æ¼ç®åã«ããããªã?ã®åã«ã¹ãã¼ã¹ãå ¥ããã¨ã§ãã。var b = a ? 1:0
ããã¯å°éã®ã¨ã©ã¼ã¡ãã»ã¼ã¸ãä½ããã。
let paramFunc = { a: Int -> Int in
let b = a * a
return b
}
å¼æ°é¨åã®a: Intã(a: Int)ã«ããã¨OK。Expected pattern
(æ£ãã)ãã¿ã¼ã³ãæå¾
ããã
【確èªver】Swift 4.0.2//4.0.2
let abc = 3
let //ã¨ã©ã¼
if abc == 5 {
}
letã®å¾ãæãã¦ããExpected expression in list of expressions
å¼ã®ãªã¹ãã§ä½ãã®å¼ãæå¾
ããã
【確èªver】Swift 3.0.2//Swift 3.0.2
func testValArg(a: Int, b: Int...) {
}
testValArg(a: 1, b:) //ã¨ã©ã¼
å¯å¤é·å¼æ°ã«æ¸¡ãå¼æ°ã0åã®ã¨ãã¯å¤é¨å¼æ°åããããªã。Expression resolves to unused l-value
æ¸ããã¦ããå¼ã¯ä½¿ç¨ãããªãl-valueã¨å¤æããã¾ãã
【確èªver】Swift 2.1var abc: String
abc //ã¨ã©ã¼
åã«å¤æ°ãæ¸ããã ãã§ä½ã®å¦çãããªãã¨ãã«åºã。playgroundã®ããã°ã©ã ãã³ããããã¨ããªã©ã«ãåºããã。l-valueã¨ããã®ã¯ã³ã³ãã¤ã©ã®å é¨ã§ä½¿ãããå°éç¨èªã?
Expected ',' separator
,ãæå¾
ããã
【確èªver】Swift 4.0.2//4.0.2
var abc = [1 2 3]
é
åã®è¡¨ç¾ã§è¦ç´ éã®,ãæãã¦ãã//4.0.2
func variableFunc(a: Int, b: Int...) {
}
func testFunc() {
variableFunc(a: 4, b: 4 4 4) //ã¨ã©ã¼
}
b: 4, 4, 4ã¨ããã¨OKExpected initial value after '='
=ã®å¾ã«åæåã®å¤ãæå¾
ããã
【確èªver】Swift 4.0.2//Swift 4.0.2
var a = //ã¨ã©ã¼
'A***' is unavailable: Use 'B***' value 'C***' instead
A***ã¯å©ç¨ã§ãã¾ãã。å¤ããã«C***ã使ã£ã¦ä¸ãã。C***ã®æ§è³ªã¯B***ã¨ãããã®ã§ã。
ãµã³ãã«ã³ã¼ãä¿åãå¿ã。詳細ä¸æ。Invalid character in source file
ä¸æ£ãªæåã§ã
【確èªver】Swift 4.0.2//Swift 4.0.2
let a = "a" //ã¨ã©ã¼
å
¨è§ã¹ãã¼ã¹ãããå ´åUnicode curly quote found, replace with '"'
ã¦ãã³ã¼ãã®æ¸¦å·»ãç¶ã®å¼ç¨ç¬¦ãè¦ã¤ããã¾ãã。"ã«å¤æ´ãã¦ãã ãã。
【確èªver】Swift 4.0.2【èª】curly 渦巻ãç¶ã® quote å¼ç¨ç¬¦【ãããã度】★★★★★//4.0.2
let abc = “ABC” //ã¨ã©ã¼
(ã©ããããæã£ã¦ããã¨ãã«)ã¨ãã£ã¿ã¼ã®ä½ãã®æ©è½ã§"ããããããªãã¤ã«èªåå¤æããã¦ããUnexpected end of block comment
ããã¹ãã§ãªãã³ã¡ã³ããããã¯ã®éã
【確èªver】Swift 3.0.2ã³ã¡ã³ãéå§è¨å·/*ã«æ¯ã¹ã¦éãè¨å·*/ãå¤ãã¨ã
//Swift 3.0.2
/*
ã³ã¡ã³ã
*/
*/ //ã¨ã©ã¼
Unexpected ',' separator
æå¾
ãã¦ããªãåºåãã®,
【確èªver】Swift 3.0.2//Swift 3.0.2
func func123(a: Bool, b: Bool) {
}
class A {
func call123() {
func123(true,) //ã¨ã©ã¼
}
}
2ã¤å¼æ°ãå¿
è¦ãªé¢æ°ã®å¼ã³åºãã§、å¼æ°ã®ã¨ããã(abc,)ã¨ãã¦ãã。æ¬å½ã¯「å¼æ°ã足ãã¾ãã」ã¨ããã¡ãã»ã¼ã¸ã®æ¹ããµãããã。Extraneous '}' at top level
ãããã¬ãã«(ã¯ã©ã¹å®£è¨å
ãé¢æ°å®£è¨å
ã§ã¯ãªã)ã«}ããã
【確èªver】Swift 2.1【èª】Extraneous æ¬è³ªçã§ãªã å¤é¨ããæ¥ãã©ããã§{ãæãã¦ããã、åç´ã«}ãå¤ã。
Declaration is only valid at file scope
宣è¨ã¯ãã¡ã¤ã«ã¹ã³ã¼ãã§ã®ã¿æå¹ã«ãªãã¾ã
ã¯ã©ã¹ã®å®ç¾©ã®ä¸ã§ãããã³ã«ã宣è¨ãã。class AAAA {
protocol AAAAA { //ã¨ã©ã¼
}
}
Closure expression is unused
使ãããªãã¯ãã¼ã¸ã£
【確èªver】Swift 4.0{}ãªã©ã§å²ã¾ããé¨åãä½ãã®åå ã§ç¡å¹ã«ãªã£ã?
{}ããåã§ä½ãåé¡ãããå ´åã«ãåºã
//4.0
func testFuncAAA() {
{ //ã¨ã©ã¼
var a = 0
}
}
æå³ã®ç¡ã{}å²ã¿//4.0
infix operator +-(a: Int, b: Int) {} //ã¨ã©ã¼
æ¼ç®åã®å®£è¨ã§ã¯å¼æ°ããããªãã®ã§ããã§ã³ã³ãã¤ã©ãå¦çã§ããªã。ãã®å¾ã®{}ã§å½ã¨ã©ã¼。//4.0
if #available(11.0, *) {
} else {
}
(iOS 11.0, *)ãªãOK。Type of expression is ambiguous without more context
æ¸ããã¦ãããã®ã¯ææ§ã§、åã決å®ããããã«ããå°ãä½ããå¿
è¦
【確èªver】Swift 2.0【èª】ambiguous ããã¾ãã var abc = ["A", 0, (1.2,3.5)]
ã¿ãã«ã¨ã¿ãã«ä»¥å¤ã®å
±åã¯ã ããããenum ABC {
case a
case b
case c
}
func funcABC() {
var aa = .a //ã¨ã©ã¼
//var aa = ABC.a ãããªãåã確å®
}
enumã®è¦ç´ ãåã確å®ããªãç¶æ
ã§ä½¿ã£ãenum TestEnumUnion {
case testUnionStr(String)
case testUnionInt(Int)
}
let a = TestEnumUnion.testUnionInt(0)
if a == .testUnionInt(0) { //ã¨ã©ã¼
}
if a == .testUnionInt { //ã¨ã©ã¼
}
if .testUnionInt(0) == a { //ã¨ã©ã¼
}
if .testUnionInt == a { //ã¨ã©ã¼
}
if case a = .testUnionInt(0) { //ã¨ã©ã¼
}
if case a = .testUnionInt { //ã¨ã©ã¼
}
if case .testUnionInt(0) = a { //OK
}
if case .testUnionInt = a { //OK
}
//Swift 3.0.2
var abc = [Int](repeating: 1.0, count: 10)
ããã¯ã©ãããçµç·¯ã§ambiguousã¨è¨ã£ã¦ããã®ã ãã?'***' is ambiguous for type lookup in this context
***ã¯ã©ã®åãªã®ãããã¾ã
【確èªver】Swift 4.0【èª】ambiguous ããã¾ãã //4.0
enum TestEnum {
case aa(Int)
case bb(TestEnum)
}
enum TestEnum {
case aa(Int)
case bb(TestEnum)
}
Consecutive statements on a line must be separated by ';'
ä¸è¡ã«é£ç¶ãã¦æãæ¸ãæã¯;ã§åºåã£ã¦ä¸ãã
Consecutive declarations on a line must be separated by ';'
ä¸è¡ã«é£ç¶ãã¦å®£è¨ãæ¸ãæã¯;ã§åºåã£ã¦ä¸ãã
【確èªver】Swift 4.0.2【èª】Consecutive é£ç¶ããã³ã³ãã¤ã©ãæ··ä¹±ããã¨ãã«åºãããã ã、ããªããããããªç¶æ³ã§åºã。åæã«åºã¦ãããã®ãä»ã«ããã¨ãã¯ä»ã®ãã®ã®æ¹ã«ãã³ãããããã¨ãå¤ã。
//4.0.2
func abc() String { //ã¨ã©ã¼
return "a"
}
->ããªã//4.0.2
let a = 1
let b = 2
let c = a *b //ã¨ã©ã¼
æ¼ç®åã®åå¾ã¯ç©ºç½ãéãããªã両æ¹éãã、éããªããªã両æ¹éããªã。a * bã®ããã«æ¼ç®åã®åå¾ã®ç©ºç½ãæããã¨åºãªããªã。
//4.0.2
var a: Int?
//ãã®éã«ãªã«ãããããããã
var b: Int = a?? 0 //ã¨ã©ã¼
a ?? 0ã®ããã«??ã®ä¸¡ãµã¤ãã«ç©ºç½ã空ããã¨OK//4.0.2
class A {
}
extention A { //ã¨ã©ã¼
}
extentionã§ã¯ãªãã¦extensiondid you mean to use '***'?
ãããããã¨ã¯***ã使ã£ããåºæ¥ã¾ããã?
【確èªver】Swift 4.0.2ææ¡é ç®ãããã¨ãã«åºã。精度ã¯ã¾ãã¾ã。
Statement cannot begin with a closure expression
ã¹ãã¼ãã¡ã³ãã¯ã¯ãã¼ã¸ã£å¼ã§å§ãããã¨ã¯åºæ¥ã¾ãã
【確èªver】Swift 2.2{}ã§ã®åã®é¨åã«ä½ãåé¡ããããã¨ãå¤ã
infix operator +-() {} //ã¨ã©ã¼
æ¼ç®åã®å®£è¨ã«ã¯()ãå
¥ããªãã®ã§ããã§ã³ã³ãã¤ã©ãå¦çã§ããªã。ãã£ã¦、ãã®å¾ã®{}ã§å½ã¨ã©ã¼ã¡ãã»ã¼ã¸。Inheritance from non-protocol, non-class type '***'
Expected '{' in class
ãããã³ã«ã§ãã¯ã©ã¹ã§ããªã***ããç¶æ¿ã§ãã¾ãã
class(ã®å®ç¾©)ã§ã¯{ãæå¾
ããã
【確èªver】Swift 4.0.2//4.0.2
class A {
class a: Int = 0 //ã¨ã©ã¼
}
classã®å®ç¾©ã¨å¤æããã¦ããvarãletå¿ã
static var a:Int = 0ãªãOK
static let a:Int = 0ãªãOK
class varã¨ããããªãæ¼ç®ããããã£ã«ããã¨OK
class letã¯NG。classã«ãããªãæ¼ç®ããããã£ã«ããªãã¨ãããªãã、æ¼ç®ããããã£ã¯letã«åºæ¥ãªãã®ã§。
Expected 'let' in conditional
æ¡ä»¶é¨ã«letãæå¾
ããã
【確èªver】Swift 3.0//Swift 3.0 var x: String? var y: String? if let a = x, b = y { //ã¨ã©ã¼ }
Expression was too complex to be solved in reasonable time; consider breaking up the expression into distinct sub-expressions
æé ãªæéã§è§£éåºæ¥ã¾ãã。åå²ãæ¤è¨ãã¦ãã ãã。
【確èªver】Swift 3.0.1【èª】reasonable é©åãª、æé 㪠distinct å¥ã
ã®//Swift 3.0.1 let radius = 5.0 let ratio = 0.5 var subRadius: CGFloat = sqrt(pow(radius / 2, 2) + sqrt(3) / 2 * radius * (1 - ratio)) //ã¨ã©ã¼å¼èªä½ã¯ç¹ã«è¤éã§ããªããã©、左辺ã«æ¸ãããCGFloatãå³è¾ºã®è¨ç®ã«å½±é¿ãã¦ãã。CGFloatãçãã¦、å³è¾ºã好ãã«ããããã¨ã¨ã©ã¼ã¯åºãªããã¿ã¼ã³。
A*** has been replaced by B***
A***ã¯B***ã«å¤æ´ã«ãªãã¾ãã
【確èªver】Swift 3.0Swiftã®ãã¼ã¸ã§ã³ã¢ããã§A***ãB***ã«å¤æ´ãããæ
Expected parameter name followed by ':'
:ãæå¾ã«ä»ãããã©ã¡ã¼ã¿åãå¿
è¦
【確èªver】Swift 4.0//4.0
func twoParamFunc(#a: Int, b: Int) { //ã¨ã©ã¼
}
ãã®ãããª#ã使ãç¨æ³ã¯ãã§ã«å»æ¢ã«ãªã£ã。#ã¯ãããªã。Expected an attribute name
å±æ§ã®ååãæå¾
ããã
Swift 2.1ããåã§åºã。Swift 2.1以éã¯æªç¢ºèª。var abc: String
abc = @"abc"
Stringã®ã¤ã³ã¹ã¿ã³ã¹ã«@ã¯ãããªã。ä»ã®ã¡ãã»ã¼ã¸ã«å¤æ´ã«ãªã£ã。
Cocoa
'IBOutlet' property has non-optional type '***'
éãªãã·ã§ãã«åã®***ã«IBOutletãä»ãã¦ãã¾ã
【確èªver】Swift 2.1éãªãã·ã§ãã«åã¯ã ãããã
#selector
//3.1
//æ£ãã使ãæ¹
override func viewDidLoad() {
super.viewDidLoad()
Timer.scheduledTimer(
timeInterval: 0.1,
target: self,
selector: #selector(nanikaCheck(timer:)),
userInfo: nil,
repeats: false)
}
func nanikaCheck(timer: Timer) {
print("nanika")
}
Cannot convert value of type 'Timer.Type' to expected argument type 'Timer'
Timeråãå
¥ããå¼æ°ã«Timer.Typeã渡ãã¦ãå¤æã§ãã¾ãã
【確èªver】Swift 3.1//3.1
selector: #selector(nanikaCheck(timer: Timer)),
:ã®ãããã¯ä½ãæ¸ããªããã¨。Missing argument label 'timer:' in call
timerã©ãã«ãå¿
è¦
【確èªver】Swift 3.1//3.1
selector: #selector(nanikaCheck(_: Timer)),
timer:ã¯çããªã。Expected Expression in list of expression
å¼ãæå¾
ããã
【確èªver】Swift 3.1//3.1
selector: #selector(nanikaCheck(:)),
Use of unresolved identifier 'nanikaCheck'
nanikaCheckãä½ãããããªã
【確èªver】Swift 3.1//3.1
selector: #selector(nanikaCheck(_:)),
nanikaCheckã¯timerã©ãã«ä»ãã§å®£è¨ããã¦ããã®ã§、ã©ãã«ãªãã®å¼ã³åºãã¯ä½ãªã®ãããããªã。Objective-Cã¨é£æº
Argument of '#selector' refers to instance method '***' that is not exposed to Objective-C
#selectorã®å¼æ°ã«Objective-Cããè¦ããªãã¡ã½ããã渡ããã¾ãã。
【確èªver】Swift 3.1//Swift 3.1
class SomeClass {
func someFunc() {
}
}
let sel = #selector(SomeClass.someFunc) //ã¨ã©ã¼
Objective-Cããè¦ããããã«ã¯SomeClassãNSObject(ããã®ãµãã¯ã©ã¹)ãç¶æ¿ããã、someFuncã¡ã½ããã«@objcãä»ãã。Objective-Cã®ã¤ããã§æ¸ãã¦ãã¾ã£ã
'YES' is unavailable : Use 'Bool' value 'true' instead
'NO' is unavailable : Use 'Bool' value 'false' instead
YESã¯ä½¿ãã¾ãã。代ããã«trueãBoolå¤ã¨ãã¦ä½¿ã£ã¦ãã ãã
NOã¯ä½¿ãã¾ãã。代ããã«falseãBoolå¤ã¨ãã¦ä½¿ã£ã¦ãã ãã
【確èªver】Swift 3.0.2//Swift 3.0.2
var result = NO //ã¨ã©ã¼
Consecutive statements on a line must be separated by ';'
é£ç¶ããæã¯;ã§åºåã£ã¦ãã ãã
【確èªver】Swift 3.0.2//Swift 3.0.2
String abc = "ããã" //ã¨ã©ã¼
Objective-C風ã®å®£è¨æ¹æ³//Swift 3.0.2
let a = 1.0
let b = (Int)a //ã¨ã©ã¼
/code>
Objective-C風ã®ãã£ã¹ãString literals in Swift are not preceded by an '@' sign
Swiftã®æååã¯é ã«@ãä»ãã¾ãã
【確èªver】Swift 3.0.2【èª】precede å
è¡ãã//Swift 3.0.2
let abc = @"ããã" //ã¨ã©ã¼
Use of undeclared type 'Boolean'; did you mean to use 'DarwinBoolean'?
Booleanã¯å®ç¾©ããã¦ãã¾ãã。ãããããã¨ã¯DarwinBooleanã§åºæ¥ã¾ããã?
【確èªver】Swift3.0.2//Swift 3.0.2
var abc: Boolean = true //ã¨ã©ã¼
trueã¯é常Boolå。Single-quoted string literal found, use '"'
ã·ã³ã°ã«ã¯ãªãã¼ã·ã§ã³ãªãã©ã«(è¦ããã« ' ã§æã¾ãããã®)ãè¦ã¤ããã¾ãã。" ã«ãã¦ä¸ãã。
【確èªver】Swift 3.0.2Cè¨èªã®æå表ç¾ã¯ã ã。
//Swift 3.0.2
var a: Character = 'a' //ã¨ã©ã¼
ã³ã³ãã¤ã«ã¨ã©ã¼ä»¥å¤(Xcodeãåºããã®ãªã©)
Enable Recommended Warning
This will enable the following recommended compiler warning
ãªã¹ã¹ã¡ã®è¦åãæå¹ã«
ä¸è¨ã®ãªã¹ã¹ã¡ã®è¦åãæå¹ã«ãã¾ã
【確èªver】Xcode 8.3.3Xcodeã®ãã¼ã¸ã§ã³ãä¸ãã¦ã¯ã¼ãã³ã°ã®åºãæ¹ãå¤ãã£ãå ´å、å¤ãããã¸ã§ã¯ããç«ã¡ä¸ããã¨åºããã¨ããã。ãã®æç« ã®ä¸ã«ç®æ¡æ¸ãã§æå¹ã«ããè¦åãå ·ä½çã«æ¸ããã。
Read failed: The data couldn't be read because it isn't in the correct format.
èªãã®ã«å¤±æ。æ£ããå½¢å¼ã§æ¸ãã¦ãªãã®ã§ãã¼ã¿ã¯èªãã¾ãã。
【確èªver】Xcode 9.0.1Localizable.stringsã®;å¿ã
Expression implicitly coerced from "Error/" to Any
è¿ä¿¡åé¤ããã¯ã©ã®ããã«ãããè¯ãã§ãããã?
Any ãåãä»ããã¨ããã«ãªãã·ã§ãã«åãå ¥ãããã¨ããã¨ãã«åºãè¦åã§ã。ææ³çã«ã¯ Any ã¯ãªãã·ã§ãã«åãåãä»ãã¾ãã、Any ã«ãªãã·ã§ãã«åãå ¥ãã㨠== nil ã®æ¯è¼ãåºæ¥ãªã (常㫠true ã«ãªã) ãªã©æ±ãã«ããé¢ããããããªã®ã§、ãªãã·ã§ãã«åãã¢ã³ã©ããããªãã¦ããã念ã®ããã«ã³ã³ãã¤ã©ã確èªã®æãåºãã¦ãã¾ã。ã¢ã³ã©ãããã¦ä»£å ¥ããã®ãããã¨æãã¾ã。
åé¤Swift 3.0.2