Initializers are called to create a new instance of a particular type. In its simplest form, an initializer is like an instance method with no parameters
Questions tagged [initializer]
684 questions
2
votes
2 answers
YAML.load never returns in Rails initializer
I'm trying to load a yaml config file during initialization of my Rails 3.1 app, and the call to YAML.load never returns. Here is my initializer file:
STRIPE_CONFIG = begin
config = YAML.load(Rails.root.join('config', 'stripe.yml')) || {}
…

Matt Huggins
- 81,398
- 36
- 149
- 218
2
votes
2 answers
Workaround for data member initialization happening after base class construction
I would have liked to do something like this:
template
class RasterView {
T* data;
unsigned stride;
RasterView(T* data, unsigned stride)
: data(data)
, stride(stride)
{}
public:
T& operator()(int j,…

Museful
- 6,711
- 5
- 42
- 68
2
votes
1 answer
LateInitializationError: Field 'mapController' has not been initialized
I am trying to integrate google map in my app and giving it source and destination to place markers. It was running correctly from last few days, no error at all. Suddenly today this error shows up and map is not working. Even though it is not…

Usama Bin Tahir
- 143
- 1
- 11
2
votes
2 answers
Can I initialize an object with null?
I have an object Contact, which is stored on disk.
Upon creating the contact object with Contact contact = new Contact("1234") it is automatically beeing loaded from disk:
class Contact
{
public Contact(string id)
{
Node? testNode =…

julian bechtold
- 1,875
- 2
- 19
- 49
2
votes
2 answers
Rake tasks and rails initializers
Kinda new to Rails, so please cope with me. What i'm doing now is background processing some Ruby code use Resque. To get the Rescque rake task started, I've been using (on heroku), I have a resque.rake file with that recommended code to attach into…

haider
- 2,418
- 3
- 24
- 26
2
votes
0 answers
Resolving ambiguous initializer from multiple frameworks
I have declared an initializer in an extension on a built in protocol type.
extension SomeProtocol {
init(fromData: Data) { // my code here }
}
A framework that I use also declares an initializer for the same protocol with the same function…

Tim Fuqua
- 1,635
- 1
- 16
- 25
2
votes
0 answers
Load a Railtie only for Server and Console
I am creating a gem for a Rails project and I got some troubles to
understand how generators and initializers work.
I would like to
initialize my module loading some stuff from the database from models
related to tables my gem should create with…

EppO
- 23
- 1
- 5
2
votes
1 answer
Why is {0} always a valid struct initializer?
Consider the following C code:
typedef struct abc {
int a[4];
int b;
int c;
} abc_t;
abc_t x = { 0 };
I have found that comping this with gcc -c -Wall -Wextra -pedantic -std=c99 does not generate any warning or error messages. My…

Sven
- 1,364
- 2
- 17
- 19
2
votes
1 answer
why are initializers getting errors when upgrading from Rails 2 to Rails 3?
This is in my config/initializer/string.rb:
class String
include ClearCompany
end
I have lib/clear_company.rb
That is where I have a module ClearCompany.

Satchel
- 16,414
- 23
- 106
- 192
2
votes
1 answer
Missing example of a Member Initializer List on p. 184 of Programming Principles and Practice Using C++, 2nd ed
I'm currently having trouble with part of Chapter 6 of "Programming: Principles and Practice Using C++" (2nd ed, 3rd printing).
According to the book's index, an example of a member initializer list is on page 184.
Part of page 184 reads as…

KBurchfiel
- 635
- 6
- 15
2
votes
2 answers
How do I use an existing property in a property wrapper when self hasn't been initialized? (SwiftUI)
I have a struct with two variables inside property wrappers. One of the variables is supposed to be computed from the other. When I try to do this, I get the following error:
Cannot use instance member 'name' within property initializer; property…

Evan93
- 155
- 11
2
votes
1 answer
Swift Required initializers in EVReflection
I'm writing code in Swift, and using https://github.com/evermeer/EVReflection. However, Xcode is playing shenanigans with my class structure - in a few places, it claims I need to include a required initialized, declared in EVObject, but not in…

Erhannis
- 4,256
- 4
- 34
- 48
2
votes
2 answers
Why incrementing (`x++;`) yet undeclared field isn't allowed inside an instance initializer, but is ok if wrapped into an anonymous class?
I am puzzled why incrementing yet undeclared field (x++;) is not allowed inside an instance initializer, but it becomes allowed inside an instance initializer if wrapped into an anonymous class (yes, anonymous class has access to class fields, but…

Code Complete
- 3,146
- 1
- 15
- 38
2
votes
2 answers
Dependency on fixture data in rails initializer
I have an initializer which sets a default that is used throughout the app. The value is an ActiveRecord model, I'm essentially caching it for the lifetime of the app:
@@default_region = Region.find_by_uri("whistler")
The record is guaranteed to be…

Andrew Vit
- 18,961
- 6
- 77
- 84
2
votes
2 answers
What initializer called in convenience init of UIViewController?
I often use convenience init in UIViewController to make custom initializer.
But I don't know what existing initializer of UIViewController being called when self.init().
Is it public init(nibName nibNameOrNil: String?, bundle nibBundleOrNil:…

undervine
- 59
- 6