instance-variables

What is the use of placing an instance variable in .h where it wouldn't have a getter and setter ( i.e. nobody can set nor get it)?

╄→尐↘猪︶ㄣ 提交于 2019-12-04 16:30:05
I have read Where to put iVars in "modern" Objective-C? and some other questions, but I am still confused. I am reading from https://www.raywenderlich.com/913/sqlite-tutorial-for-ios-making-our-app SQLite Tutorial: .h #import <Foundation/Foundation.h> #import <sqlite3.h> @interface FailedBankDatabase : NSObject { sqlite3 *_database; } + (FailedBankDatabase*)database; - (NSArray *)failedBankInfos; @end .m #import "FailedBankDatabase.h" #import "FailedBankInfo.h" @implementation FailedBankDatabase static FailedBankDatabase *_database; + (FailedBankDatabase*)database { if (_database == nil) {

Marking instance variables @private

强颜欢笑 提交于 2019-12-04 15:33:00
I've noticed that a lot of Apple's interfaces use @private before their instance variable declarations. Is there a good design reason for this, and is it something I should do? Private instance variables are used to separate interface from implementation. In Objective-C, since the class declaration must show all of the instance variables, there needs to be a way to prevent subclasses from accessing the ones that are part of the internal implementation. Otherwise, other programmers could write code that depends on those internal variables, which would make it impossible for the class designer

python tkinter passing variables between functions

我与影子孤独终老i 提交于 2019-12-04 05:58:14
问题 I am trying to pass the variable dirpath into the export_data() function. Export data runs off of a double click on a button located on a widget. Why is dirpath printing as: `<Tkinter.Event instance at 0x8ade56c>` instead of the actual path? def export_data(dirpath): print 'exporting...' print str(dirpath) os.mkdir('/home/bigl/Desktop/Library') shutil.copytree(dirpath, output_path) When I run my code I get the error exporting... <Tkinter.Event instance at 0x8ade56c> Traceback (most recent

JNI - how to use multiple Jni wrapper instances with different fields?

那年仲夏 提交于 2019-12-04 05:22:39
问题 background I have an android project that uses JNI (using NDK) to code in both Java and C/C++. I've created a Jni java wrapper on the java side that will do all the Jni oprerations by itself, while no other java class can access the jni operations directly other than this wrapper. the problem problem is , i wish to create multiple instances of this wrapper, while the Jni part should have an instance per Jni wrapper. this is a problem, since the Jni part holds the same fields for all instances

How to fix - 41: non-static variable cannot be referenced from a static context -> What is the reason for this?

最后都变了- 提交于 2019-12-04 05:03:06
问题 I'm trying to write this code to get the first initialCapacity prime numbers and then print them in sequence using java. It isn't working for two reasons, firstly I get the error 41: non-static variable listOfPrimeNumbers cannot be referenced from a static context when I try to run the program, but even when I change the variable to static and run the program, it will only print out "1". So it is only iterating the while loop in the constructor Primes once, and then stopping and I simply

Exposing/Synthesizing iVar properties in Objective c

天大地大妈咪最大 提交于 2019-12-04 03:54:44
问题 I have a class that essentially acts as a light weight wrapper class around another class. It holds that other class as an iVar. I want to be able to expose certain properties (quite a few actually) of the iVar, but to do so I have to write out each property accessor like so: - (void) setProperty:(Class *)value{ _iVar.property = value; } - (Class *) property{ return _iVar.property; } Of course, I have to do this for every single property, which is a pain (there are about 30 of them). I would

C# how can I preserve data between class instances?

不打扰是莪最后的温柔 提交于 2019-12-04 02:35:26
问题 Apologies for the vague title, but I am not really sure how else to explain it. Given Class A, B and C. If Class A contains a List, how can I preserve the data in that list so that Class B and C can access the data in the list (even if B and C both new up their own instance of Class A)? Classes B and C must create their own instances (this is out of my control). I am using this class as my object data source, and let's say I cannot modify the contents of Class C. Following is an example class

instance variables in @interface; header vs implementation

耗尽温柔 提交于 2019-12-04 00:57:15
Is there any difference between declaring a private instance variable in the header vs declaring it in the implementation? in TestObj.h @interface TestObj : NSObject { int test; } @end vs in TestObj.m @interface TestObj() { int test; } @end Both seem equivalent to me, is there any actual difference between declaring an instance variable in the header vs in the implementation, if not which is preferred? The @interface within the implementation file just seems like a way to declare private properties, does it have any other purpose outside that? The preference is generally to place private

Instance Variables Inheritance

二次信任 提交于 2019-12-03 23:32:55
Can someone explain how a class can access the instance variables of its superclass and how that is not inheritance? I'm talking about 'The Ruby Programming Language' and the example class Point def initialize(x,y) # Initialize method @x,@y = x, y # Sets initial values for instance variables end end class Point3D < Point def initialize(x,y,z) super(x,y) @z = z end def to_s "(#@x, #@y, #@z)" # Variables @x and @y inherited? end end Point3D.new(1,2,3).to_s => "(1, 2, 3)" How can class Point3D access x and y inside to_s if they're not inherited? The book says: "The reason that they sometimes

Instance Variables in Rails Model

十年热恋 提交于 2019-12-03 15:45:15
I want to initialize an instance variable within my Rails model that will hold an array and I want to access this variable in other methods within my model. I tried this: class Participant < ActiveRecord::Base @possible_statuses = [ 'exists', 'paired', 'quiz_finished', 'quiz_results_seen', 'money_sent' ] def statuses @possible_statuses end But when I tried the following using rails console: Participant.first.statuses I am returned nil :( Why does this happen? Is there a way to accomplish what I am trying to accomplish? I would recommend using a constant for this kind of cases: class