Questions tagged [init]

May refer to Linux init, an abbreviation of initialization - giving variables a "starting" value, or Python's __init__ class initiation method.

May refer to :

  • Linux Init - the parent of all processes, which primary role is to create processes from a script stored in the file /etc/inittab.
  • variable init (abbreviation of initialization) - giving variables a "starting" value.
  • python magic __init__ - magic function that initializes an object.
1905 questions
33
votes
4 answers

How to write init method in Swift?

I want to write an init method in Swift. Here I initialize an NSObject class in Objective-C: -(id)initWithNewsDictionary:(NSDictionary *)dictionary { self = [super init]; if (self) { self.title = dictionary[@"title"]; …
Vineesh TP
  • 7,755
  • 12
  • 66
  • 130
32
votes
4 answers

What is initState and super.initState in flutter?

In the documentation it is written but I am not able to understand it. Called when this object is inserted into the tree. The framework will call this method exactly once for each State object it creates. Override this method to perform…
Rajesh Shaw
  • 547
  • 1
  • 4
  • 9
29
votes
3 answers

Python multi-inheritance, __init__

Regarding multiple parent inheritance, when I call the super.__init__, why doesn't parent2's __init__ function get called? Thanks. class parent(object): var1=1 var2=2 def __init__(self,x=1,y=2): self.var1=x …
Renl
  • 291
  • 1
  • 3
  • 4
24
votes
3 answers

What does object's __init__() method do in python?

While reading the code of OpenStack and I encountered this. A class named 'Service' inherits the base class 'object', and then in Service's __init__() method, object's __init__ is called. The related code looks like this: the class definition: class…
can.
  • 2,098
  • 8
  • 29
  • 42
24
votes
3 answers

iOS loadNibNamed confusion, what is best practice?

I'm familiar with most of the process of creating an XIB for my own UIView subclass, but not everything is working properly for me - it's mostly to do with the IBOutlets linking up. I can get them to work in what seems like a roundabout way. My…
Cloov
  • 538
  • 1
  • 3
  • 15
23
votes
3 answers

calling init for multiple parent classes with super?

Possible Duplicate: Can Super deal with multiple inheritance? Python inheritance? I have a class structure (below), and want the child class to call the __init__ of both parents. Is this possible to do in a 'super' way or is it just a terrible…
scruffyDog
  • 721
  • 3
  • 7
  • 17
23
votes
2 answers

What's the purpose of golang allowing multiple init in one package?

I know that golang allows multiple init in one package and even in one file. I am wondering why? For example, if a pkg has many files, we could write multiple init then we could get lost in where to we should put init, and we could be also confused…
harrycmfan
  • 1,055
  • 3
  • 9
  • 12
22
votes
2 answers

What is the meaning of npm init -y

Please I would love to know the meaning of the flag -y. I noticed it is used in setting up an npm project, but what exactly does it mean? npm init -y
George Foreman
  • 349
  • 1
  • 2
  • 6
22
votes
1 answer

Swift: Calling an init from another init

I have an object with two init methods. One of them takes in a NSDictionary, and the other takes in a whole ton of String variables. I want to call the NSDictionary init, and from there convert my dictionary into Strings and call the other init with…
Jonathan Allen Grant
  • 3,408
  • 6
  • 30
  • 53
22
votes
1 answer

Optional parameter in class initialization

I'm working with Swift, Sprite-Kit and Xcode 6, I have a class declared like this : class Obstacles: SKSpriteNode { init(initTime: Int, speed: CGFloat, positionX: CGFloat, rotationSpeed: CGFloat) { self.initTime = initTime …
Drakalex
  • 1,488
  • 3
  • 19
  • 39
21
votes
5 answers

Why should we use -> in def __init__(self, n) -> None:?

Why should we use -> in def __init__(self, n) -> None:? I read the following excerpt from PEP 484, but I am unable to understand what it means. (Note that the return type of __init__ ought to be annotated with -> None. The reason for this is…
user14612542
21
votes
1 answer

'Use of self in method call before super.init initializes self', can't init properties through a method call

I'm curious is there is anyway to call a method inside your init method that sets instance properties of the class. Essentially I just have a class that sub-classes UIView, adds some subviews in init, and some of those subviews are instance…
Kevin DiTraglia
  • 25,746
  • 19
  • 92
  • 138
21
votes
1 answer

Emacs init.el file doesn't load

When I open emacs, the following messages appear in the *Messages* buffer, and my init.el file (located at ~/.emacs.d/init.el) doesn't load. Loading 00debian-vars...done Loading /etc/emacs/site-start.d/50cedet-common.el (source)... Error while…
Justin Blank
  • 1,768
  • 1
  • 15
  • 32
20
votes
1 answer

Passing parameters to a custom class on initialization

I have a class Message with two attributes, name and message, and another class MessageController with two text fields, nameField and messageField. I want to make an instance of Message in MessageController, passing these two attributes as…
user567
  • 3,712
  • 9
  • 47
  • 80
20
votes
3 answers

swift - Initialize view controller from storyboard by overriding init

I have a ViewController instance defined in a storyboard. I can initialize it by the following var myViewController = UIStoryboard(name: "Main", bundle: nil).instantiateViewControllerWithIdentifier("myViewControllerIdentifier") as!…
adamF
  • 961
  • 2
  • 9
  • 23