Files
swift-mirror/test/ClangModules/objc_nsmanagedobject.swift
Jordan Rose 0733ba42c9 Allow @NSManaged to be applied to methods.
Core Data synthesizes Key-Value-Coding-compliant accessors for @NSManaged
properties, but Swift won't allow them to be called without predeclaring
them.

In practice, '@NSManaged' on a method is the same as 'dynamic', except
you /can't/ provide a body and overriding it won't work. This is not the
long-term model we want (see rdar://problem/20829214), but it fixes a
short-term issue with an unfortunate workaround (go through
mutableOrderedSetValueForKey(_:) and similar methods).

rdar://problem/17583057

Swift SVN r30523
2015-07-23 02:08:55 +00:00

60 lines
1.7 KiB
Swift

// RUN: %target-swift-frontend(mock-sdk: %clang-importer-sdk) -I %S/Inputs/custom-modules -parse -parse-as-library -verify %s %S/Inputs/objc_nsmanaged_other.swift
// RUN: %target-swift-frontend(mock-sdk: %clang-importer-sdk) -I %S/Inputs/custom-modules -parse -parse-as-library -verify -primary-file %s %S/Inputs/objc_nsmanaged_other.swift
// RUN: %target-swift-frontend(mock-sdk: %clang-importer-sdk) -I %S/Inputs/custom-modules -emit-silgen -parse-as-library -o /dev/null -DNO_ERROR %s %S/Inputs/objc_nsmanaged_other.swift
// RUN: %target-swift-frontend(mock-sdk: %clang-importer-sdk) -I %S/Inputs/custom-modules -emit-silgen -parse-as-library -o /dev/null -DNO_ERROR -primary-file %s %S/Inputs/objc_nsmanaged_other.swift
// REQUIRES: objc_interop
import Foundation
import CoreData
func markUsed<T>(t: T) {}
// Inferred @requires_stored_property_inits.
class MyManagedObject : NSManagedObject {
#if !NO_ERROR
var foo: String // expected-error{{stored property 'foo' requires an initial value}}
var bar: String // expected-error{{stored property 'bar' requires an initial value}}
#endif
@NSManaged var managed: String
override init() {
#if !NO_ERROR
foo = "1"
bar = "2"
#endif
super.init()
}
var wibble: String {
return "hello"
}
#if !NO_ERROR
var wobble: String { // expected-error{{stored property 'wobble' requires an initial value}}
willSet(value) {
markUsed(value)
}
}
#endif
}
func getOtherManagedObject() -> OtherManagedObject {
return OtherManagedObject()
}
func accessOther(om: OtherManagedObject) -> String {
return om.managed
}
// rdar://problem/20821582
func accessMine(obj: MyManagedObject) -> String {
return obj.anotherManaged
}
func accessMyMethod(obj: MyManagedObject) {
obj.managedMethod()
}