init

Swift - Assign a NIB to self in class

时光总嘲笑我的痴心妄想 提交于 2019-11-30 17:20:20
问题 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, how do I properly do this from within the class itself? class MyDropDown: UIView { func showNotification() { self = UINib(nibName: nibNamed, bundle: bundle).instantiateWithOwner(nil, options: nil)[0] as? UIView } } 回答1:

How to run a command as a specific user in an init script?

╄→尐↘猪︶ㄣ 提交于 2019-11-30 13:11:57
问题 I'm writing an init script which is supposed to execute a single command as a user different than root. This is how I'm doing it currently: sudo -u username command This generally works as expected on Ubuntu/Debian, but on RHEL the script which is executed as the command hangs. Is there another way to run the command as another user? (Note that I can't use lsb init functions as they're not available on RHEL/Centos 5.x.) 回答1: On RHEL systems, the /etc/rc.d/init.d/functions script is intended

Success with start-stop-daemon and mono-service2?

邮差的信 提交于 2019-11-30 12:33:59
问题 Has anyone had any success using start-stop-daemon and mono-service2 together? I've been fighting this for a few days now and have gotten various bits to work, but have had no success in getting a fully functional init script for a mono service. Here is what I have learned to date: The mono or mono-service exe must be named as the variable DAEMON (you can't list your exe as the DAEMON) You must use the --background flag ... otherwise when this script is executed from a package installer (deb

RedHat daemon function usage

非 Y 不嫁゛ 提交于 2019-11-30 11:33:15
I'm working on an init script for Jetty on RHEL. Trying to use the daemon function provided by the init library ( /etc/rc.d/init.d/functions ). I found this terse documentation , and an online example (I've also been looking at other init scripts on the system for examples). Look at this snippet from online to start the daemon daemon --user="$DAEMON_USER" --pidfile="$PIDFILE" "$DAEMON $DAEMON_ARGS &" RETVAL=$? pid=`ps -A | grep $NAME | cut -d" " -f2` pid=`echo $pid | cut -d" " -f2` if [ -n "$pid" ]; then echo $pid > "$PIDFILE" fi Why bother looking up the $PID and writing it to the $PIDFILE by

How to swizzle init in Swift

徘徊边缘 提交于 2019-11-30 10:50:53
I'm following Swift & the Objective-C Runtime , it works for normal methods. I like to swizzle init method, from my understanding, init is like a class method. So I tried swizzling init as instance and class method. But it does not seem to work I can make it work using Objective C, just wonder how to make it work in Swift Excerpted from my gist dispatch_once(&Static.token) { let originalSelector = Selector("init:source:destination:") let swizzledSelector = Selector("ftg_init:source:destination:") let originalMethod = class_getClassMethod(self, originalSelector) let swizzledMethod = class

Understanding method signature in NoSuchMethod exception

▼魔方 西西 提交于 2019-11-30 06:40:49
问题 I got this exception but resolved it. java.lang.NoSuchMethodError: antlr.NoViableAltForCharException.<init> (CLjava/lang/String;II)V But i'd like to know how to interpret these kind of messages: "(CLjava/lang/String;II)V" Also, does this "init" mention the constructor of NoViableAltForCharException class?? Thanks. 回答1: Type Signatures - taken from this page. The JNI uses the Java VM’s representation of type signatures. Table 3-2 shows these type signatures. Z boolean B byte C char S short I

Would it be correct/ellegant use only alloc without init?

可紊 提交于 2019-11-30 05:25:36
If we don't want to implement init method in our class, and bearing in mind that init in NSObject only returns an instance of the object without initialization, I don't see the point of calling init if we already get the instance with alloc. I have tried and it works, but I am not sure it won't cause future problems. myClass *newObject = [myClass alloc]; instead of: myClass *newObject = [[myClass alloc] init]; Thanks a lot. No, just calling alloc would not be correct. alloc zeroes out all instance variables of the object, init then has the chance to set all or some instance variables to their

HttpModule Init method is called several times - why?

淺唱寂寞╮ 提交于 2019-11-30 04:20:15
I was creating a http module and while debugging I noticed something which at first (at least) seemed like weird behaviour. When i set a breakpoint in the init method of the httpmodule i can see that the http module init method is being called several times even though i have only started up the website for debugging and made one single request (sometimes it is hit only 1 time, other times as many as 10 times). I know that I should expect several instances of the HttpApplication to be running and for each the http modules will be created, but when i request a single page it should be handled

Objective C - difference between init and constructor?

强颜欢笑 提交于 2019-11-30 03:37:30
问题 I'm trying to find the difference between init and constructor in Objective C.I'm not a C developer, but I need to convert some Objective C-code to Java and actually I can't understand the difference between both things. 回答1: In Objective-C, the way an object comes to life is split into two parts: allocation and initialization . You first allocate memory for your object, which gets filled with zeros (except for some Objective-C internal stuff about which you don't need to care):

Running services (upstart/init.d) in a container

我只是一个虾纸丫 提交于 2019-11-30 03:03:06
问题 I'm trying to launch a system in docker that has many init and upstart services and I get this error. initctl: Unable to connect to Upstart: Failed to connect to socket /com/ubuntu/upstart: Connection refused All the workarounds suggest making a hard link to /bin/true to silence the error. But I need to have these services managed by upstart for restart-ability and for upstart emit events to work... As it seems docker does not support this, I'm considering the gross hack of writing a script