instance-variables

Class Objects and Instance Variables in Objective-C

人走茶凉 提交于 2019-12-05 13:31:29
I'm having a hard time wrapping my head around this concept. I'll take the quote exactly from the book: Class objects also inherit from the classes above them in the hierarchy. But because they don’t have instance variables (only instances do), they inherit only methods. Correct me if I'm wrong, but a class object would be this: NSString *aString = [[NSString alloc]initWithString:@"abc.."]; The class object in this case is *aString -- am I correct so far? The thing that confuses me is the second sentence in the quote above, "But because they don’t have instance variables (only instances do),

How to set an initial value for @NSManaged property PFObject Subclass?

被刻印的时光 ゝ 提交于 2019-12-05 13:02:55
I have a subclass of PFObject called Attendee . In this class, there is a instance variable I have called isFavorite . Below is its class definition: @NSManaged var isFavorite: Bool This is an instance var that is local to the device and I never sync it up to the server. In addition, I never explicitly instantiate the Attendee class, but rather create it by typecasting from PFObject . I would like to set the above var to have an initial value of false . How would I achieve this? var isFavorite: Bool { get { if let isFavorite = self["isFavorite"] as? Bool { return isFavorite } return false /

Android Static Variable Scope and Lifetime

笑着哭i 提交于 2019-12-05 12:41:19
I have an application that has a Service that uses an ArrayList<Double> to store numbers in the background for a very long time; the variable is initialized when the service started. The service is in the background, and there will be frequent access to the variable (that's why I don't want to use file management or settings -- it will be very expensive for a file I/O for the sake of battery life). The variable will likely be ~1MB->2MB over its lifetime. Is it safe to say that the variable will never be nulled by GC or the system, or is there any way to prevent it? CommonsWare I have an

Rails rendering instance variable from application.html.erb

假如想象 提交于 2019-12-05 10:48:07
I am following the Agile Web Development with Rails 4 book and I'm a bit confused on a part about rendering. The simple version of the question is... within the application.html.erb file there it says render @cart This is confusing because I thought that there needed to be a controller associated with that view in order to know which partial and @cart variable to use. Is it simply by naming convention that this line looks for a partial like _cart.html.erb? And in that case does it not actually know what @cart is until it renders that partial? Some clarification would be lovely. Thanks! This is

Python | Why is accessing instance attribute is slower than local?

我与影子孤独终老i 提交于 2019-12-05 06:34:02
import timeit class Hello(): def __init__(self): self.x = 5 def get_local_attr(self): x = self.x # 10x10 x;x;x;x;x;x;x;x;x;x; x;x;x;x;x;x;x;x;x;x; x;x;x;x;x;x;x;x;x;x; x;x;x;x;x;x;x;x;x;x; x;x;x;x;x;x;x;x;x;x; x;x;x;x;x;x;x;x;x;x; x;x;x;x;x;x;x;x;x;x; x;x;x;x;x;x;x;x;x;x; x;x;x;x;x;x;x;x;x;x; x;x;x;x;x;x;x;x;x;x; def get_inst_attr(self): # 10x10 self.x;self.x;self.x;self.x;self.x;self.x;self.x;self.x;self.x;self.x; self.x;self.x;self.x;self.x;self.x;self.x;self.x;self.x;self.x;self.x; self.x;self.x;self.x;self.x;self.x;self.x;self.x;self.x;self.x;self.x; self.x;self.x;self.x;self.x;self.x;self

“Access of shared member, constant member, enum member or nested type through an instance”

岁酱吖の 提交于 2019-12-05 02:04:21
I wonder why Visual Studio is raising this warning: Access of shared member, constant member, enum member or nested type through an instance My code: Dim a As ApplicationDeployment = deployment.Application.ApplicationDeployment.CurrentDeployment If System.Deployment.Application.ApplicationDeployment.IsNetworkDeployed Then If a.IsNetworkDeployed Then ' do something End If End If What implies "through an instance"? Also, why is this a "warning"? Showing a warning is a design option. In C#, it would throw an error when calling a static using an instance ( this ) keyword. The problem is that you

Ruby attr_reader allows one to modify string variable if using <<

怎甘沉沦 提交于 2019-12-05 00:26:45
问题 Ran into some weird behaviour and wondering if anyone else can confirm what I am seeing. Suppose you create a class with a member variable, and allow it to be read with attr_reader. class TestClass attr_reader :val def initialize(value) @val = value end end Now when I do the following, it seems to modify the value of @val, even though I have only granted it read privileges. test = TestClass.new('hello') puts test.val test.val << ' world' puts test.val This returns hello hello world This is

How to get rails controller variable in js file

点点圈 提交于 2019-12-04 23:38:03
问题 I have a variable in rails controller like def index @approveflag = true end I need to access this variable in my javascript code, I used the code given below in index.html.erb <script> alert("<%=@approveflag%>") <script> It works fine with result "true".But when I moved this code to its corresponding .js file it gives an alert with result string ""<%=@approveflag%>"". What is the reason. How can I solve this? Thanks in advance. 回答1: I personally don't like mixing js with erb so I would do

Private properties vs instance variables in ARC [duplicate]

。_饼干妹妹 提交于 2019-12-04 18:21:56
This question already has an answer here : Best way of declaring private variables in cocoa (1 answer) Closed 6 years ago . Having ARC enabled for an iOS app, if I want a class to have a private value/object, it should be better to declare this: // .m file @interface MyClass () @property (strong, nonatomic) NSString *name; @end or this?: @implementation MyClass { NSString *name; } What memory management considerations should I have? Thanks! You can use either approach. In the first case you are declaring a private property--which has some benefits. For instance you could expose that private

Sharing instance variables between classes ruby

a 夏天 提交于 2019-12-04 16:36:29
I know that this question has been answered before, but I can't seem to make any of the solutions work I'm making a ruby wrapper for an API that I need to call. The Interface class does all of the session handling and actual calling of the api, but I want to build helper classes for the functions that I will be performing most frequently. The problem I am having is that I need a way of maintaining one instance of the Interface class across multiple helper classes. Here's the code I have so far require_relative 'interface' module Api_Helper attr_accessor :xmlmc #get a new instance of the