FAQ Database Discussion Community


Swift - Assign a NIB to self in class

ios,swift,subclass,xib,init
I am creating a UIView subclass for a notification dropdown banner. I am using a XIB to build out the view and want to assign that xib to the class when it initializes (i.e. avoiding having to do this from the calling ViewController). Since you can't assign to 'self' in...

Swift Initialization - Why are multiple init functions being called?

ios,iphone,ipad,swift,init
Here's is my class with override inits class BottomView: UIView { // MARK: - initilization override init() { println("init") super.init() setup() } override init(frame: CGRect) { println("init frame") super.init(frame: frame) setup() } required init(coder aDecoder: NSCoder) { println("init decoder") super.init(coder: aDecoder) setup() } func setup() { println("setup") } } I...

Syntax error on simple init script for debian

bash,shell,debian,init
It seems like the colons should be there from the tutorials I am reading, and yet it is telling me to remove them? /etc/init.d/uwsgi: 27: /etc/init.d/uwsgi: Syntax error: ";;" unexpected Any help on this error would be appreciated. #!/bin/sh ### BEGIN INIT INFO # Provides: uwsgi # Required-Start: $local_fs $remote_fs...

What is the reason python needs __init__.py for packages?

python,module,package,init
I understand that python needs the __ init __.py file in order to recognize the directory as a python package, that way we can import sub modules into our program.I can see the similarity to classes and how init can be used to execute necessary code off the bat. However,...

Problems debugging initializer?

xcode,debugging,swift,init,lldb
I have a debugging error on the following code: required init(coder aDecoder: NSCoder) { fatalError("init(coder:) has not been implemented") } Here is all of my code: class ViewController: UIViewController { required init(coder aDecoder: NSCoder) { fatalError("init(coder:) has not been implemented") } override func viewDidLoad() { super.viewDidLoad() var button = UIButton.buttonWithType(.Custom)...

How have multiple init() with Swift

swift,init
Is it possible, if yes how, to have multiple init without parameter, in a Class like this (the string is just an exemple): aVar: String init() { aVar = "simple init" } initWithAGoodVar() { aVar = "Good Var!" } initWithFooBar() { aVar = "Foo Bar" } ...

Way to override a class __init__ in python

python,override,init
When I call mic.openTheMic(record_seconds = 10), I'd like to either use all of the class defaults, or if I want to change (one or more) parameter(s), then only have to include one, e.g., this case where record_seconds = 10. Is there a way to do this? class myAudio(object): def __init__(self,...

Why I can not initialize my variable in jQuery?

javascript,jquery,function,initialization,init
I'm freeze in my app. I want to create my own reports.js file using variables like a functions but I can not initialize it. I'm copying other ones already done in the template but I can't understand why mine is not working. Here is the part where I call it...

Swift 2.0 : infer closure type error

swift,types,init,lazy-initialization
I get error Unable to infer closure type in the current context In code which was working in Swift 1.2 private lazy var _messagesVC = { return MessagesViewController(nibName:"MessagesViewController",bundle:nil)}() Whole View Controller where I get this error import UIKit class FriendsViewController: UIViewController { @IBOutlet weak var containerView: UIView! @IBOutlet weak var...

Automatically calling an init function whenever an object is used for the 1st time

c#,load,delay,auto,init
I have an object that only initializes itself with barebones data when constructed (fast), and loads itself for real (slow) when first accessed. The idea is that I'm creating a lot of these barebones objects at startup and hash them into a map, then fully load each object whenever it...

How can I pass a value to Django Form's init method from a view?

django,forms,views,init,choicefield
forms.py class AddDuration(forms.Form): def __init__(self, *args, **kwargs): super(AddDuration, self).__init__(*args, **kwargs) // set value to relates_to_choices relates_to_choices = ????????????? // Something like self.choices self.fields['duration'].choices = relates_to_choices duration = forms.ChoiceField(required=True) Now, I have a views.py file that has a class class AddDurationView(FormView): template_name = 'physician/add_duration.html' form_class = AddDurationForm ...

Init Method in Singleton Class (Objective-C)

ios,objective-c,singleton,instance,init
I have a question regarding the safe way of implementing a singleton class in Objective-C. My background is mostly in web-development (PHP) but I know that in Obj-C things are quite different. For instance I have this custom class MyClass that I want to be singleton: static MyClass *sharedInstance =...

object init in objective-c [closed]

objective-c,object,init
#import "Page.h" @implementation Page -(instancetype)init{ self = [super init]; if (self) { self.firstPage =[[Page alloc]init]; self.choiceA = [[Page alloc]init]; self.choiceB = [[Page alloc]init]; } return self; } @end I'm new to Objective-C. error: exc_bad_access code=2 What's wrong with my code ? Thanks....

To use init or not to in Python classes

python,class,init
I have always defined variables for classes like: class A(): def __init__(self): self.x = 1 However, I discovered it is also simply possible to use: class A(): x = 1 In both cases, a new instance will have a variable x with a value of 1. Is there any difference?...

Initializing a Three Dimensional Vector in a C++ Class

c++,c++11,vector,initialization,init
Using the following code I would like to move a multidimensional vector in various directions. Unfortunately right after initializing I get an EXC_BAD_ACCESS error. Direction: Values from 0 to 2 for x,y and z movement Steps: Only -1 and 1 (Back, Forward) Container: Multidimensional Vector if (verMove(direction, steps)==true) { std::vector<int>...

Error: avcodec_init();

init,avcodec
I'll try to compile under Ubuntu 14.04.2 and I get the following error: VideoPlayerPipHd.c: In static member function ‘static void reel::VideoPlayerPipHd::Create()’: VideoPlayerPipHd.c:792:6: error: ‘avcodec_init’ was not declared in this scope avcodec_init -> avcodec_register_all; ^ VideoPlayerPipHd.c:793:7: error: ‘av_open_input_file’ was not declared in this scope av_open_input_file -> avformat_open_input; ^ The code is:...

Groups of optional arguments for a function - python

python,class,init
Okay so I have to make two classes (in two different scripts), both called Block, which store information about the position and size of a rectangular block. Version 1 should have attributes to store the coordinates of the center of the block (either as separate x- and y-coordinates or as...

mount fails from spawned process

linux,init,mount
I want to start a process that uses a USB hard drive once it gets inserted. Since UDEV rules specifically mentions not to run long-time processes from RUN command, I send a FIFO message to my service which then opens the relevant process. So the flow goes like this: UDEV...

Syntax error on simple init script for debian

linux,bash,shell,init
I have this init script to run uwsgi. It works, but only on the start command. All the other commands give me this error: /etc/init.d/uwsgi: 27: /etc/init.d/uwsgi: Syntax error: ";;" unexpected It seems like the colons should be there from the tutorials I am reading, and yet it is telling...