initializer

Calling Objective-C initializer with variadic arguments

别来无恙 提交于 2019-12-14 02:49:49
问题 I'm trying to re-use an Objective-C class, namely TSAlertView, into a Swift project. The problem is that the class uses an initializer with variadic arguments. I followed the same approach suggested at this stackoverflow question and my code works in the iOS Simulator if I use the iPad Air but NOT if I use the iPad Retina. The code also crashes on a real iPad 3. I was able to create a toy example that shows the same issue. TestClass.h #import <Foundation/Foundation.h> @interface TestClass :

How can I properly use breakpoints when using an object initializer?

安稳与你 提交于 2019-12-12 09:47:08
问题 For example, doing something like this: foreach (DataRow row in data.Rows) { Person newPerson = new Person() { Id = row.Field<int>("Id"), Name = row.Field<string>("Name"), LastName = row.Field<string>("LastName"), DateOfBirth = row.Field<DateTime>("DateOfBirth") }; people.Add(newPerson); } Setting a breakpoint to an individual assignation is not possible, the breakpoint is set to the entire block. If I want to see specifically where my code is breaking, I have to use: foreach (DataRow row in

Create a subclass of UIImage with added properties

别来无恙 提交于 2019-12-12 06:26:10
问题 I'm trying to create a subclass of UIImage with an added property, but when I create a convenience init, I can't call the UIImage's designated init init(named name: String) because for some reason it's not inherited. class myUIImage: UIImage { var imageType$: String? convenience init(imageName$ imageName$: String) { self.init(...?) self.imageType$ = // ... } } Any ideas? 回答1: There is "not inherited" string in named: initializer declaration: public /*not inherited*/ init?(named name: String)

Initialize class depending on config value

家住魔仙堡 提交于 2019-12-12 02:36:23
问题 I would like to find out how it is possible to initialize a Module , depending on a value. So I have a config.extend value which will decide if the core will instantiate of the Core or ExtendedCore module. However I am getting the error "value := is not a member of Sodor.core". val extend = 1 val core = Module(new Core(data_address)) if(extend==1){ core := Module(new ExtendedCore(data_address)) } What is the proper way to intialize a Module depending on the statement, like in this case?

Unable to use I18n.t call in an initializer file

强颜欢笑 提交于 2019-12-11 23:19:17
问题 I would like to use I18n.t call in an initializer file. Unfortunately, it doesn't work. Rails returns the usual "translation missing:" message. It seems that the I18n files haven't been loaded yet when the call is made. Are there any workarounds ? Thanks 回答1: I had the problem when I was using Rails 2.3.2. Since then, I've migrated to 2.3.5 and I18n.t calls work fine in my initializers. 来源: https://stackoverflow.com/questions/3514536/unable-to-use-i18n-t-call-in-an-initializer-file

Why can’t I initialize a Swift UnsafeMutablePointer<UInt32> with (&myUInt32) or (&[myUInt32])

六月ゝ 毕业季﹏ 提交于 2019-12-11 11:42:16
问题 The docs say: "When a function is declared as taking an UnsafeMutablePointer argument, it can accept any of the following... An in-out expression whose operand is a stored lvalue of type Type, which is passed as the address of the lvalue." I can copy the example and demonstrate this. func takesAMutablePointer<T>(x: UnsafeMutablePointer<T>) -> UnsafeMutablePointer<T> { return x } func useAMutablePointer() { var legInt :UInt32 = 42 var legIntArray: [UInt32] = [legInt] var legIntPtr:

Rails.logger.info is not working in initializer

社会主义新天地 提交于 2019-12-11 07:15:45
问题 Rails.logger.info does not write any information to log when used in initializer. How to get logging in initializer? 回答1: Rails.logger = Logger.new(STDOUT) before MyServer::Application.initialize! in /config/environment.rb 回答2: May be the log level is silencing your message. Is it production or development? Take a look to your config.log_level in your config/*.yml files 来源: https://stackoverflow.com/questions/26377359/rails-logger-info-is-not-working-in-initializer

Rails: Run initializer before creating classes

只谈情不闲聊 提交于 2019-12-11 01:17:43
问题 Basically I have an initializer class at RAILS_ROOT/config/initialiers/app_constant.rb to make everything easy to control. class AppConstant APIURL = 'http://path.to.api' end And in the RAILS_ROOT/model/user.rb , I have the settings: class User < ActiveResource::Base self.site = AppConstant::APIURL end And when run rails s , I got the following error <class:User>: uninitialized constant User::AppConstant::APIURL I know that the problem is because Rails run Initializers after creating the

Initialize UIGestureRecognizer as part of property definition in Swift?

不打扰是莪最后的温柔 提交于 2019-12-11 01:10:55
问题 I would like to initialize a UIPanGestureRecognizer as part of a UIViewController ´s property definition, so that I don't have to declare it optional (as I would have to if initialization occurs only in viewDidLoad ). Both of the following two attempts fail at compile time (I am using the latest version of Xcode): -- 1st attempt class TestController: UIViewController { let panGestureRecognizer: UIPanGestureRecognizer required init(coder: NSCoder) { super.init(coder: coder)

How to get the server port in a Rails initializer

不羁的心 提交于 2019-12-10 19:28:45
问题 I have multiple instances of Rails servers and there is a need for each one of them to know its own listening port in environment.rb. request.port will work in the controllers but not in the context of the environment.rb. Is there a way? Thanks! 回答1: You can get the running rails port using this code: Rails::Server.new.options[:Port] You can take a look at the options parser in the Rails documentation to see what hash parameters are available. 来源: https://stackoverflow.com/questions/9574129