instance

Getting name of the class from an instance

余生长醉 提交于 2019-12-02 14:46:14
I have the following problem: I get an instance of a class passed and want to know the name of the class of this instance. How to get this? NSStringFromClass([instance class]) should do the trick. if all you want to do is test an object to see if it's a type of a certain Class BOOL test = [self isKindOfClass:[SomeClass class]]; From within the class itself -(NSString *) className { return NSStringFromClass([self class]); } ealee Just add a category: NSObject+Extensions.h - (NSString *)className; NSObject+Extensions.m - (NSString *)className { return NSStringFromClass(self.class); } Then use

NullPointerException in while loop when trying to add new Class instances to ArrayList

折月煮酒 提交于 2019-12-02 13:17:19
The more I google this the more confused I'm getting. I'm bringing in a list of names of unknown length with some other details in from a CSV which I then need to turn into Person objects and store in a list called people which is the instance variable for the class Club, a list of its members basically. This is a very simplified version of something more complex I need to do in which I need to while loop through a file creating objects for each line which I then need to add to a list collection. I keep getting a nullPointerException error when I run my code though and I'm stumped how to avoid

How to create a new form instance using the name of the form as a String

南楼画角 提交于 2019-12-02 10:17:41
问题 Code to create new form instance of a closed form using form name I want to replace the long Select Case list with a variable. Full code of module In Access 2010 I have a VBA function that opens a new instance of a form when given a string containing the form's name. By adding a form variable "frm" to a collection: mcolFormInstances.Add Item:=frm, Key:=CStr(frm.Hwnd) The only way I can figure out to open "frm" is with a Select Case statement that I've manually entered. Select Case strFormName

Adding multiple instances of a Sprite?

有些话、适合烂在心里 提交于 2019-12-02 10:16:17
I am building a Custom Image Picker, that shows 6 alternative versions. However the photo is only showing on the 6th item. _model.selectedPhoto returns a Sprite, and does not let the app function correctly. However when I use _model.photos[ii] , A photo is added to each item - Why is this? I need to add _model.selectedPhoto to each s:Sprite for (var ii:int; ii < 6; ii++) { //Create BG var s:Sprite = new Sprite(); s.graphics.beginFill(Math.random() * 0xffffff, 0.4); s.graphics.drawRect(0, 0, 291, 184); //add Photo var p:Sprite = new Sprite(); p.addChild(_model.selectedPhoto); p.scaleX = p

Haskell show instance on list

£可爱£侵袭症+ 提交于 2019-12-02 10:12:29
问题 Im having issues with adding a show instance to my data structure, wich is: data Structure = Structure String [Structure] and I would like to have this output: strct strct1 strct2 strct3 I've been trying this instance Show Structure where show (Structure a (xs)) = show a ++ "\n" ++ " " ++ show xs But its output is "strct" ["strct1" [], "strct2" []] So, I would need no brackets, no commas and no quotation marks. Any ideas? Thanks 回答1: I'm sure there are better library routines for this, but

Declare all instances of a typeclass are in another typeclass without modifying the original class declarations

偶尔善良 提交于 2019-12-02 09:24:51
问题 There is an Crypto.Random API inside the crypto-api package that specifies what it means for something to be a "pseudorandom number generator". I have implemented this API using an instance of System.Random's RandomGen class, namely, StdGen: instance CryptoRandomGen StdGen where newGen bs = Right $ mkStdGen $ shift e1 24 + shift e2 16 + shift e3 8 + e4 where (e1 : e2 : e3 : e4 : _) = Prelude.map fromIntegral $ unpack bs genSeedLength = Tagged 4 genBytes n g = Right $ genBytesHelper n empty g

Can you declare an instance variable as a parameter in a constructor?

纵然是瞬间 提交于 2019-12-02 09:11:39
问题 Would this work? class Cars{ Cars(int speed, int weight) } I am just trying to figure out the constructor. If it is called like a method then I thought it would work similar to a method. You can create local variables in a method that are used when that method is called so I don't see why instance variables have to be declared before constructors can use them. 回答1: In your example speed and weight are not instance variables because their scope is limited to the constructor. You declare them

Object reference not set to an instance of an object - webservices

╄→尐↘猪︶ㄣ 提交于 2019-12-02 07:59:39
I have this error appearing in my web service and even though I'v had a look at the articles on the null issue, I am not able to find how to fix this error this is my code: SendInvUpdate.InvServices.UpdateRatePackagesRequest urq = new SendInvUpdate.InvServices.UpdateRatePackagesRequest(); SendInvUpdate.InvServices.UpdateRatePackagesOperationResponse ors = new SendInvUpdate.InvServices.UpdateRatePackagesOperationResponse(); protected void Page_Load(object sender, EventArgs e) { Int64 HID = 819942; Int64 HRID = 154482; SendInvUpdate.InvServices.UpdateRatePackagesRequest request = new

unwanted object property changed when changing another object property c#

戏子无情 提交于 2019-12-02 07:26:31
from what i understand in other posts i know that my objects use same place in memory but how to separate these objects? i tried to use new but it didn't work or i didn't used it correctly. Note that i didnt paste setter and getter here. class Supermarket { List<Product> _products = new List<Product>{ }; List<Customer> _customers = new List<Customer>{ }; } class Customer { List<Product> _purchased= new List<Product>{ }; } class Product { string _id; string _name; DateTime _expireDate; int _cost; int _count; } i add one Product in one Method. Product product = new Product(...); supermarket

I am looking to create instances of a class from user input

陌路散爱 提交于 2019-12-02 07:07:44
问题 I Have this class: class Bowler: def __init__(self, name, score): self.name = name self.score = score def nameScore(self): return '{} {}'.format(self.name, self.score) I need to get user input until a blank line is entered. Then use the data I got to create instances of a class. I was thinking something like: def getData(): name, score = input("Please enter your credentails (Name score): ").split() B1 = Bowler(name, score) print(B1.nameScore()) But then I would somehow have to loop it until I