let list = ["a", "b", "c", "d"]
let str = join(",", list)
上記だと「Cannot invoke `join` with an argument list of type (String, [String])」 というエラーになる
以下のように変更する必要がある
let list = ["a", "b", "c", "d"]
list.joinWithSeparator(",")
なんで変更したんだAppleさん・・・
let list = ["a", "b", "c", "d"]
let str = join(",", list)
上記だと「Cannot invoke `join` with an argument list of type (String, [String])」 というエラーになる
以下のように変更する必要がある
let list = ["a", "b", "c", "d"]
list.joinWithSeparator(",")
なんで変更したんだAppleさん・・・
指定した範囲内でランダムな値を生成するには、以下のような関数で実装できます。
func getRandomNumber(Min _Min : Float, Max _Max : Float)->Float {
return ( Float(arc4random_uniform(UINT32_MAX)) / Float(UINT32_MAX) ) * (_Max - _Min) + _Min
}
使用例 : - 0.1〜9.9までの範囲で乱数を生成
getRandomNumber(Min: -0.1, Max: 9.9)
SKSpriteNodeの子クラスでコンストラクタであるinitを普通にオーバーライドしようとしたら、こんなエラーメッセージが表示されてしまった。
「must call a designated initializer of the superclass SKSpriteNode」
init()は子クラスから呼べないみたいです。
対処方法として、init(texture, color, size)を呼ぶことにします
import UIKit
import SpriteKit
class Man: SKSpriteNode {
init() {
let texture = SKTexture(imageNamed: "man")
super.init(texture: texture1, color: nil, size: texture.size())
}
required init(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
}
ちなみに、init(coder aDecoder: NSCoder)はrequired initとして指定されているので、こいつもオーバーライドしてあげないとエラーになります。override func touchesBegan(touches: NSSet, withEvent event: UIEvent) { //anycode }↓
override func touchesBegan(touches: Set<NSObject>, withEvent event: UIEvent) {//anycode }
・Sprite・Sceneimport SpriteKit protocol MyBtnDelegate: class { func exec() } class MyBtn: SKSpriteNode { var delegate: MyBtnDelegate? = nil override func touchesBegan(touches: NSSet, withEvent event: UIEvent) { self.delegate?. exec() } }
import SpriteKit class PlayScene: SKScene,MyBtnDelegate { let btn : MyBtn = MyBtn(imagenamed:"MyBtn") override func didMoveToView(view: SKView) { btn.delegate = self } func exec(){ //todo } }
if !str{
//anycode
}
if str == nil{
//anycode
}
if str.isEmpty{
//anycode
}