The question is whether the code below is correct or not.
In XCode 9.0, this is the code for Swift 4.
When I tried to execute it with the code below
error:Execution was interrupted, reason:EXC_BAD_ACCESS (code=2, address=0x7ffff5c02cff8).
1. Please let me know the reason
2. Is the code below wrong in the first place?
Have your own instance in the class or declare your own instance
Is it possible to define an array to store your own instances?
class Test {
vartest:Double {
get{
return self.test+100
}
set(a){
self.test=a
}
}
vartestList —Array<Test>=Array()
init(a:Double) {
self.test=a
addTest(a:a)
}
funcaddTest(a:Double) {
let t : Test = Test (a:a)
testList.append(t)
}
}
vartest1: Test=Test(a:1) ※←Exception display location
print(test1.testList[0].test)
Answer 1:
addTest()
function{
Initiator {
addTest()
function{
}
}
}
Answer 2: YES. Wrong for the above reasons.
init(a:Double, count:Int=0){
self.test=a
addTest(a:a, count+1)
}
funcaddTest(a:Double, count:Int){
if count<5{
let t : Test = Test (a:a, count:count)
testList.append(t)
}
}
I think it's OK to count the number of loops in this way (unless it has to last indefinitely).
NOTE: var testList: Array<Test>=Array()
→var testList:[Test]=[]
610 Uncaught (inpromise) Error on Electron: An object could not be cloned
599 GDB gets version error when attempting to debug with the Presense SDK (IDE)
567 rails db:create error: Could not find mysql2-0.5.4 in any of the sources
887 When building Fast API+Uvicorn environment with PyInstaller, console=False results in an error
© 2024 OneMinuteCode. All rights reserved.