ios - Extending Array to append SKTextures -


this question has answer here:

being new swift decided @ extending array (or more [sktexture] arrays of sktexture) function add specified number of frames application bundle.

// frames fuzzyrabbit_0001@2x.png fuzzyrabbit_0002@2x.png fuzzyrabbit_0003@2x.png fuzzyrabbit_0004@2x.png  // call var rabbittextures = [sktexture]() self.rabbittextures.texturefromframes("fuzzyrabbit", count: 4) 

my first attempt listed below, getting error cannot invoke 'append' argument list of type '(sktexture!)' looking @ function fuzzypush because trying append sktexture rather generic t.

is possible, or limited fact don't want function generic rather specific arrays of sktexture.

extension array {      // sktexture     mutating func texturefromframes(imagename: string, count: int) {         if !(self[0] sktexture) { return }         index in 1...count {             let image = string(format: "\(imagename)_%04d", index)             let texture = sktexture(imagenamed: image)             self.append(texture) // error: cannot invoke append argument list of type sktexture!         }     }      // works fine     mutating func fuzzypush(newitem: t) {         self.append(newitem)     } } 

i curious if extension, not problem have function takes 3 parameters (imagename, count, arraytoappend) can quite use that.

this extension not possible write today. cannot apply extension method types of arrays.

there 2 solutions. can use has-a pattern creating struct (texturelist) contains [sktexture], or can use function.


Comments

Popular posts from this blog

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -