如何让@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
var data: JSON = []
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
loadData()
return true
}
func loadData () {
Alamofire.request(.GET, "...", parameters: nil)
.responseJSON { response in
data = JSON(response.result.value!)
}
}
}
的Gradle @Input工作?我尝试添加List<CustomClass>
方法,这有所帮助,但它仍然以奇怪的方式失败。什么是使其可序列化的正确方法?这是Gradle版本2.4。
失败:toString()
List<CustomClass>
此操作失败并显示以下消息:
@Input
List<CustomClass> getMyInput() {
List<CustomClass> simpleList = new ArrayList<>()
simpleList.add(new CustomClass())
return simpleList
}
static class CustomClass {
String str
}
成功:"Unable to store task input properties. Property 'myInput' with value '[null]' cannot be serialized."
List<String>
创建例外的Gradle源代码参考: https://github.com/gradle/gradle/blob/master/subprojects/core/src/main/groovy/org/gradle/api/internal/changedetection/state/InputPropertiesSerializer.java#L42
答案 0 :(得分:0)
该类需要实现'Serializable'接口。这是为了允许Gradle完全序列化对象,以便可以在构建之间比较二进制格式以查看是否有任何更改。一旦CustomClass可序列化,那么List<CustomClass>
也可以序列化,只要它使用ArrayList
等标准实现。
以下是一个例子:
@EqualsAndHashCode
static class CustomClass implements Serializable {
// Increment this when the serialization output changes
private static final long serialVersionUID = 1L;
String projectName
@SuppressWarnings('unused')
private static void writeObject(ObjectOutputStream s) throws IOException {
s.defaultWriteObject();
}
// Gradle only needs to serialize objects, so this isn't strictly needed
@SuppressWarnings('unused')
private static void readObject(ObjectInputStream s) throws IOException {
s.defaultReadObject();
}
}