init

Can we ensure nullability of `+ (nonnull instancetype)sharedInstance;`?

与世无争的帅哥 提交于 2019-12-05 09:37:10
This is a question on how to gracefully circumvent the nullability of init in NSObject class. So here is a classic objective-c implementation: + (instancetype)sharedInstance { static dispatch_once_t onceToken; static id sharedInstance; dispatch_once(&onceToken, ^ { sharedInstance = [[self alloc] init]; }); return sharedInstance; } But now I want to declare it as nonnull , if possible: + (nonnull instancetype)sharedInstance; Unfortunately, init returns a nullable instancetype value. Should I add an NSAssert or something after calling init ? I noticed that some people even document nonnull

UIViewController init vs initWithNibName:bundle:

僤鯓⒐⒋嵵緔 提交于 2019-12-05 08:53:34
In my app I am pushing a view controller (a UITableViewController) that has also a property/outlet referencing a UITableViewCell. It appears that creating the controller with: PreferencesController *pController = [[PreferencesController alloc] init]; doesn't create the object for the UITableViewCell in the xib file, thus the outlet is null, thus the table loading generates an exception. I solved this with: PreferencesController *pController = [[PreferencesController alloc] initWithNibName:@"PreferencesController" bundle:nil]; but I didn't really get why it worked, as from documentation it

Python: Import file in grandparent directory

孤街浪徒 提交于 2019-12-05 08:20:05
Hierarchy: scripts/ web/ script1.py tests/ script2.py common/ utils.py How would I import utils in script1 and script2, and still be able to run those scripts seperately (i.e., python script1.py ). Where would I place the __init__.py files, and is that the correct way to go about this? Thank you! package/ __init__.py scripts/ web/ __init__.py script1.py tests/ __init__.py script2.py common/ __init__.py utils.py I've added a bunch of empty __init__.py files to your package. Now you have 2 choices, you can use an absolute import: from package.common import utils or equivalently: import package

文件描述符再述之 initscript 和 systemd

南笙酒味 提交于 2019-12-05 07:46:49
服务的 ulimit 设置无效 设定 文件描述符 /etc/security/limits.conf 内容: * soft nproc 10000 * hard nproc 10000 * soft nofile 4194304 * hard nofile 4194304 /etc/sysctl.conf 片段: fs.nr_open = 5242880 fs.file-max = 4194304 /etc/profile.d/ulimit.sh 内容: #!/bin/bash [ "$(id -u)" == "0" ] && ulimit -n 4194304 ulimit -u 80000 /etc/pam.d/login 下相关文件片段 session required pam_limits.so service 启动的服务, Runtime 文件描述符仍是 1024 ? :joy: grep 'open files' /proc/$(pgrep cron)/limits # Max open files 1024 4096 files SysV的系统设定(CentOS6/Debian7) initscript 增加一个 /etc/initscript 文件就可以改变所有 service 的 环境变量 了。 示例 # cat /etc/initscript ulimit -n

spring的InitializingBean介绍

筅森魡賤 提交于 2019-12-05 07:31:10
InitializingBean Spirng的InitializingBean为bean提供了定义初始化方法的方式。InitializingBean是一个接口,它仅仅包含一个方法:afterPropertiesSet()。 Bean实现这个接口,在afterPropertiesSet()中编写初始化代码: package research.spring.beanfactory.ch4; import org.springframework.beans.factory.InitializingBean;publicclass LifeCycleBean implements InitializingBean{publicvoid afterPropertiesSet() throws Exception { System.out.println("LifeCycleBean initializing..."); } } 在xml配置文件中并不需要对bean进行特殊的配置: xml version="1.0" encoding="UTF-8"?>DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd"><beans><bean name=

Using alloc, init in ARC enabled projects

怎甘沉沦 提交于 2019-12-05 06:43:28
Actually I am working on a project with ARC enabled. I know using alloc and init is taking ownership of the object. I know, If I create a string like this NSString *myString = [[NSString alloc]initWithFormat:@"Something"]; then I need to release the myString on myself. What If I am using ARC enabled? I cannot release on myself. So will it create a leak? Or should I don't create object like this? I can create a string like below code too. NSString *myString = [NSString stringWithFormat:@"Something"]; But which type I need to use exactly for ARC enabled project ? What will happen if I use first

LoadError when installing ruby devkit [closed]

别来无恙 提交于 2019-12-05 02:36:53
This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center . Closed 7 years ago . I have installed ruby on Windows 7 using the installer Ruby 1.9.3-p125 which is the latest version ( ruby -v shows the right version). Next, I downloaded devkit-3.4.5r3-20091110 , which is also the latest version. When I tried the following in the

python 反射

烈酒焚心 提交于 2019-12-05 02:12:25
一. 什么是反射? 反射: 用字符串数据类型的变量名来访问这个变量的值 反射的方法: getattr,hasattr,setattr,delattr 反射可以用在: " 类, 对象, 模块, 反射自己模块中的内容" hasattr(判断要么是True, 要么是False), getattr # 根据字符串的形式,去对象中找成员。 hasattr # 根据字符串的形式,去判断对象中是否有成员。 类名.名字 相当于: getattr(类名, "名字")  对象名.名字    hasattr(对象, "名字") 模块名.名字 相当于: import 模块 getattr(模块, "名字") 自己文件.名字 相当于: import sys getattr(sys.modules["__main__"], "名字") == > 名字 修改 setattr(对象, 名字, 修改内容) 删除 delattr(对象, 名字)1. getattr和hasattr的用法 class Reflex(object): reflex = '反射' def __init__(self,name): self.name = name def func(self): print('start func') @classmethod def login(cls): print('登录') r = Reflex(

Golang之反射reflect包

…衆ロ難τιáo~ 提交于 2019-12-05 01:02:59
反射规则 在计算机科学领域,反射是指一类应用,它们能够自描述和自控制。也就是说,这类应用通过采用某种机制来实现对自己行为的描述(self-representation)和监测(examination),并能根据自身行为的状态和结果,调整或修改应用所描述行为的状态和相关的语义。 每个语言的反射模型都不同(同时许多语言根本不支持反射)。 Go语言实现了反射,所谓反射就是动态运行时的状态。 我们用到的包是reflect。 从接口值到反射对象的反射 反射仅是一种用来检测存储在接口变量内部(值value,实例类型concret type)pair对的一种机制。 在reflect反射包中有两种类型让我们可以访问接口变量内容 reflect.ValueOf() // ValueOf returns a new Value initialized to the concrete value // stored in the interface i. ValueOf(nil) returns the zero Value. func ValueOf(i interface {}) Value {...} reflect.TypeOf() // TypeOf returns the reflection Type that represents the dynamic type of i. // If

Should I always release self for failed init methods?

无人久伴 提交于 2019-12-05 00:44:22
Should I always release self when there is a failure inside init, or should I only do so if I have initialized instance variables first? To put it another way, is this pattern valid? Is there a time when I shouldn't release self inside an init method, or should I assume that if the control flow enters init, self has at least a retain count of 1? - (id)init { if ((self = [super init]) == nil) { [self release]; return nil; } //do some init stuff if (somethingFailed) { [self release]; return nil; } return self; } Brandon Bodnar If some check you need in your initialization method fails, then yes