swift - Code runs fine on Playground; at the same time it yields an EXC_I386_GPFLT error -


i'm having curious issue in playground prints expected result @ same time see error telling me execution stopped because of exc_i386_gpflt error.

i'm using playground model how should api wrapper i'm writing used. idea of doing plan nice api future developers.

the following entire "planning" code have written plan out wrapper. feel free copy , paste on playground see problem in action:

class anilist {     init() {}      internal class userapis {         weak var parent: anilist? = nil          init(parent: anilist) {             self.parent = parent         }     }      lazy var user: userapis = { [unowned self] in         let userapi = userapis(parent: self)         return userapi     }() }  extension anilist.userapis {     func me(_ completionhandler: (results: [string]) -> void ) {         // logic, fetching stuff parent         completionhandler(results: ["lorem", "sammet"])     } }  let andy = anilist() andy.user.me { results in     print(results) } 

curiously, prints ["lorem", "sammet"] properly, @ same time error.

successful error!

i have read (for c++) few other questions regarding error unfortunately haven't been able solve issue. can gather happening because i'm attempting access memory nil? in general, haven't been able find information regarding other being architecture protection.

while code runs fine, i'm hesitant putting on actual code yet, have no idea how behave. if works on first run, it's hard predict if produce errors in long run.

edit:

it looks has calculated lazy var. changing line this:

lazy var user: userapis = userapis(parent: self) 

works expected (as in, prints array , doesn't give me exc_i386_gpflt error).

edit 2:

previous edit seems inaccurate information.

this isn't answer workaround till figure out why works:

let andy = anilist() let somevar = andy.user.me { results in     print(results) } 

this gives compile time warning saying constant somevar inferred have type (), maybe unexpected.

but doing this:

let andy = anilist() let _ = andy.user.me { results     print(results) } 

works fine without errors @ all. weird enough. it'd if explain why happens.


Comments

Popular posts from this blog

jOOQ update returning clause with Oracle -

java - Warning equals/hashCode on @Data annotation lombok with inheritance -

java - BasicPathUsageException: Cannot join to attribute of basic type -