Coding practice: Calling NSObject

Hi all,
I have a question about structure. I have a backup button in my settingsVC. I have created an NSObject file with the functions that I need. They put CoreData info into an array and iterate what I want from the array into the variable 'backUpFile'.

I've accessed the NSObject file from the button in the settingsVC, and it works. My question is, is this an acceptable way to go about it? Does the test object still reside in memory when the operation is done? Do I need to clear it or do some kind of clean up after getting my result?


Cheers for any responses.


@IBAction func backUpTapped(_ sender: Any) {


let test = BackUp()


test.getRecords()

test.getInfo()

let file = test.backUpFile

print(file)

}


Must've been a stupid question.

I don't know about "stupid", but it's phrased strangely. By "NSObject file" do you mean a class? A file is a storage concept - a container on disk that can hold code in various languages, images, data etc. I assume you're talking about a Swift file that contains, possibly among other things, the definition of a Swift class that extends from NSObject. You call instance methods on instances of that class, or class methods on the class, but you don't "access a file".


Anyway. Objects remain in memory only while some other object holds a strong reference. So in your example above, the BackUp object instance referred to by "test" will get cleaned up as soon as that function exits, since your local variable "test" goes out of scope. Unless some code somewhere else is storing a reference to that object instance.


I'm not aware of anything special about NSObject in that regard.

Coding practice: Calling NSObject
 
 
Q