class

Get NSClassFromString from Array of Strings - Swift

强颜欢笑 提交于 2019-12-25 01:43:11
问题 I am trying to write a function that loads a particular view controller from my array of string>. However I'm struggling with this concept in swift - I achieved this in Objective - C. static NSString const *const viewControllerClassName[3] = {@"one", @"two", @"three"}; . // get the name of the class of the viewcontroller that will be shown on this page const NSString *className = viewControllerClassName[1]; Class class = NSClassFromString((NSString *)className); UIViewController *controller =

How to get the current classes of an element in an Angular directive

核能气质少年 提交于 2019-12-25 01:42:55
问题 I have to make an Angular 7 directive where I can toggle (add/remove) a class from the element (ElementRef). When the class in not in the element add it, and when it's in the element remove it. I know how to add / remove a class ... but how to get the current classes of an element ? ... so I can check if I have to add or remove 回答1: To get the current classes of an element, you could do: const elementRef: ElementRef; const classes = elementRef.nativeElement.classList; if (classes.contains(

Accessing private variable objects

限于喜欢 提交于 2019-12-25 01:41:33
问题 If I have a class: class A { public: A(); ~A(); int something(); } class B { public: B() {a = new A();}; ~B(); private: A *a; } main() { B x; } Is the only way to use object "a" in main is to have a getter for it? class B { public: A getA() {return *a;}; private: A *a; } And then if I wanted to set the private variable object, I would need a setter, and set it in main? Edit: I updated class A, B, main a little. Main question is, what is the best way if I create an object of B in main. Can I

Can a child class respond to events captured by its super?

僤鯓⒐⒋嵵緔 提交于 2019-12-25 01:39:40
问题 I have a custom class which I am extending for various purposes, and the following code is working just fine: class Inator { constructor(whichCanvas) { this.myCanvas = whichCanvas; } } class Ballgowninator extends Inator { constructor(whichCanvas) { super(whichCanvas); this.myCanvas.addEventListener("mousedown",this.handleMouseDown); this.myCanvas.addEventListener("mouseup",this.handleMouseUp); } handleMouseDown(e) { alert("ballgowninator mousedown"); } handleMouseUp(e) { alert(

When can I omit self

吃可爱长大的小学妹 提交于 2019-12-25 01:07:18
问题 I found this example of a simple tkinter class. The example works with either 'frame' or 'self.frame' Why can or would I safely omit 'self'? from Tkinter import * class App: def __init__(self, master): frame = Frame(master) frame.pack() self.button = Button( frame, text="QUIT", fg="red", command=frame.quit ) self.button.pack(side=LEFT) self.hi_there = Button(frame, text="Hello", command=self.say_hi) self.hi_there.pack(side=LEFT) def say_hi(self): print "hi there, everyone!" root = Tk() app =

accessing an instance in main from a form

狂风中的少年 提交于 2019-12-25 01:01:17
问题 /* Hi i am trying to make my first c# application on visual studio. I have created a class and an instance of that class in main and i am simply trying to query a member of that instance inside a click event on a form but its telling me the instance name does not exist in the current context. Any help would be appreciated here's my code. */ using System; using System.Collections.Generic; using System.Linq; using System.Windows.Forms; namespace WindowsFormsApplication10 { public class

Access to instance variable, but not instance method in Python

↘锁芯ラ 提交于 2019-12-25 01:00:51
问题 I'm a newbie to python and I think similar question have been asked (including this one: Can you use a string to instantiate a class in python?), but I don't understand the answers or how to apply them. I'm trying to create multiple instances of a class using what i'll call 'instance names' in a list. Here's an example of what I'm trying to do: class InstanceNames(): def __init__(self): self.names = ['inst1', 'inst2', 'inst3'] class DoSomething(): instances = [] def __init__(self):

Why 'issubclass(object, type)' gives false (in python)?

眉间皱痕 提交于 2019-12-25 00:49:59
问题 I'm confused in python class hierarchy. I want to know the relation between type and object. object is the top of 'issubclass()' function. type is the top of 'thing. class ' and 'type(thing)'. (I intentionally didn't use the word object again to avoid confusion. instead I used thing.) Surprisingly isinstance(object, type) and isinstance(type, object) both return true. Explain the hierarchy in detail. Thanks I mean which one was written first? type? or object? 回答1: In Python, everything is an

Is it possible to access class properties without initialising the class?

余生颓废 提交于 2019-12-25 00:45:13
问题 I want to access all of the properties of a class that will be defined when the constructor is called, so that I can implement a sort of interface for the class. Say I had a class that defines the property hello , I would like to access it to check it has been implemented and the type assigned to it is correct. Problem is, since all non- static class properties are tied to an instance, I can't get at them without instantiating the class, which I can't do. In this situation, is it possible to

I would like to reassign 128 column classes with a list/vector of column classes?

自作多情 提交于 2019-12-25 00:44:13
问题 I can't seem to find what I need in other posts, essentially, I need to reorder my data from the data.table read in (I can't give the col classes fread statement because my columns are out of order) I need to change the columns classes to what I need listed below. A lot of the other posts seem to be changing all of one type of class to another type of class: Change the class of many columns in a data frame Convert column classes in data.table I believe my problem is different because there is