如何设置协议的可选属性?例如,UITextInputTraits具有许多可选的读/写属性.当我尝试以下操作时,我收到编译错误(无法在'textInputTraits'中分配给'keyboardType'):
func initializeTextInputTraits(textInputTraits: UITextInputTraits) {
textInputTraits.keyboardType = .Default
}
Run Code Online (Sandbox Code Playgroud)
通常在访问协议的可选属性时添加问号,但在分配值时这不起作用(错误:无法分配给此表达式的结果):
textInputTraits.keyboardType? = .Default
Run Code Online (Sandbox Code Playgroud)
协议看起来像:
protocol UITextInputTraits : NSObjectProtocol {
optional var keyboardType: UIKeyboardType { get set }
}
Run Code Online (Sandbox Code Playgroud) 我正在尝试隐藏域类中的属性,但它一直出现在输出的JSON中.我正在使用Jackson 2.0和Spring 3.1.1
输出/ users/1:
{"id":1,"password":null,"email":"someone@somewhere.com","firstName":"John","lastName":"Smith"}
Run Code Online (Sandbox Code Playgroud)
我的域名类:
@Entity
public class User {
private String mPassword;
...
@JsonIgnore
public String getPassword() {
return mPassword;
}
public void setPassword(String password) {
mPassword = password;
}
...
}
Run Code Online (Sandbox Code Playgroud)
我的springmvc配置:
...
<mvc:annotation-driven/>
<bean class="org.springframework.web.servlet.view.ContentNegotiatingViewResolver">
<property name="favorPathExtension" value="true" />
<property name="mediaTypes">
<map>
<entry key="json" value="application/json"/>
</map>
</property>
<property name="defaultContentType" value="application/json"/>
<property name="defaultViews">
<list>
<bean class="org.springframework.web.servlet.view.json.MappingJacksonJsonView" />
</list>
</property>
</bean>
...
Run Code Online (Sandbox Code Playgroud)
而我的控制器:
@Controller
@RequestMapping("/users")
public class UserController {
private UserService mUserService;
public UserController(){}
@Inject
public void …Run Code Online (Sandbox Code Playgroud) 我试图通过调用NSException.raise()在Swift中引发异常.定义是:
class func raise(_ name: String!, format format: String!, arguments argList: CVaListPointer)
Run Code Online (Sandbox Code Playgroud)
但是当我尝试以下内容时:
NSException.raise("Exception", format:"Error: %@", arguments:getVaList([error]))
Run Code Online (Sandbox Code Playgroud)
我得到编译错误:调用中的额外参数'format'.
我有什么想法我做错了吗?我正在使用XCode 6 Beta 5.
我有一个应用程序有2个变化,只有品牌不同.对于每个版本,我在资产目录中都有一个AppIcon和LaunchImage.我为每个版本创建了一个不同的目标.在第二个版本中,当我尝试在第二个资产目录中选择AppIcon时,它只是默认为第一个.删除第一个资产目录似乎解决了它,但我更喜欢一个不那么"hacky"的解决方案.
我正在使用date.toLocaleDateString(locale)方法来获取用户的日期格式。我在服务器端获取用户的语言环境,同时使用Accept-Language标头和地理编码的IP地址(即使您不在美国,浏览器似乎默认为en-US)。但是toLocaleDateString()似乎不能识别所有语言环境,即,如果您这样做,date.toLocaleDateString('en-IE')您将获得美国日期格式而不是欧洲日期格式。Intl.Collator.supportedLocalesOf('en-IE', {localeMatcher: 'lookup'})没有帮助。有浏览器支持的语言环境列表吗?
顺便说一句,我已经在OSX的Chrome和Firefox上尝试了上述方法。