instance-variables

Why 'self.self' compiles and run in swift?

倖福魔咒の 提交于 2019-12-22 06:36:53
问题 Yesterday I reviewed a piece of code in Swift which included this line: self.self.someProperty Which surprised me, because the word self is reserved and used as a reference to the current instance. At first I checked for that phenomenon in other languages, but all gave errors. Which wasn't a surprise - but still, why in swift does it compile and run? Second I searched in the internet about this and haven't found anything relevant... Edit I reproduced that and from my checks: self.someProperty

Rails rendering instance variable from application.html.erb

落花浮王杯 提交于 2019-12-22 05:34:22
问题 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

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-21 20:56:41
问题 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

Instance Variables Inheritance

牧云@^-^@ 提交于 2019-12-21 07:25:24
问题 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

Why use instance variables to “connect” controllers with views?

北战南征 提交于 2019-12-21 04:18:08
问题 This is a conceptual question and I haven't been able to find the answer in SO, so here I go: Why instance variables are used to connect controllers and views? Don't we have two different objects of two different classes (Controller vs Views). So, when the view is rendered we are in a different context, but we are using instance variables of another object? Isn't this breaking encapsulation in somehow? How does Rails manage to do that matching from one object to another? Does it clone all the

Why does Scala language require you initialize a instance variable instead of relying on a default value?

◇◆丶佛笑我妖孽 提交于 2019-12-20 09:48:55
问题 Scala language requires you initialize your instance variable before using it. However, Scala does not provide a default value for your variable. Instead, you have to set up its value manually by using the wildcard underscore, which acts like a default value, as follows var name:String = _ I know, i know... I can define a constructor in the class definition, which takes as parameter our instance variable, so Scala does not force its initialization as shown below class Person(var name:String)

Instance variable not retaining value in iOS application

吃可爱长大的小学妹 提交于 2019-12-20 05:28:09
问题 I have declared this ivar in my ViewController.h #import <UIKit/UIKit.h> @interface FirstViewController : UIViewController <UITableViewDelegate, UITableViewDataSource> { NSArray *sortedCountries; } @property (nonatomic, retain) NSArray *sortedCountries; @end In ViewController.m, sortedCountries does it's job in -(void)ViewDidLoad{} by storing the result of a sorted .plist. When -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {} is called

What exactly does “static” mean when declaring “global” variables in Java?

瘦欲@ 提交于 2019-12-19 17:39:57
问题 I've been running into this problem many times and I never bothered to learn why its happening and learn what "static" actually means. I just applied the change that Eclipse suggested and moved on. public class Member { // Global Variables int iNumVertices; int iNumEdges; public static void main(String[] args) { // do stuff iNumVertices = 0; // Cannot make a static reference to the non-static field iNumVertices // do more stuff } // main end } So eclipse tells me to do static int iNumVertices

Declaring private variables in header file vs declaring variables in class extension

吃可爱长大的小学妹 提交于 2019-12-19 10:53:20
问题 What's the difference between declaring a @private ivar in the header file and declaring the same ivar in the class extension without @private? As far as I understand it's the same thing. Also, can you declare a private property in the header? 回答1: What's the difference between declaring a @private ivar in the header file and declaring the same ivar in the class extension without @private? There are a few differences. In short, variables declared in the header file are visible to subclasses

instance variable, class variable and the difference between them in ruby

点点圈 提交于 2019-12-19 09:23:43
问题 I am having a hard time understanding instance variable, class variable and the difference between them in ruby... can someone explain them to me? I have done tons of Google searches, just can't understand them fully. Thank you! 回答1: Let's say you define a class. A class can have zero or more instances. class Post end p1 = Post.new p2 = Post.new Instance variables are scoped within a specific instance. It means if you have an instance variable title , each post will have its own title. class