Swift - Extra Argument in call - swift

I am trying to call a function declared in ViewController class from DetailViewController class.
When trying to debug the 'Extra Argument in call" error pops up.
In ViewController class:
func setCity(item : Cities, index : Int)
{
citiesArray!.removeObjectAtIndex(index)
citiesArray!.insertObject(item, atIndex: index)
}
In detailViewController Class
// city of type Cities
ViewController.setCity(city ,5 ) //Error: "Extra argument in call"
This is pretty simple yet I'm baffled.

In some cases, "Extra argument in call" is given even if the call looks right, if the types of the arguments don't match that of the function declaration. From your question, it looks like you're trying to call an instance method as a class method, which I've found to be one of those cases. For example, this code gives the exact same error:
class Foo {
func name(a:Int, b: Int) -> String {
return ""
}
}
class Bar : Foo {
init() {
super.init()
Foo.name(1, b: 2)
}
}
You can solve this in your code by changing your declaration of setCity to be class func setCity(...) (mentioned in the comments); this will allow the ViewController.setCity call to work as expected, but I'm guessing that you want setCity to be an instance method since it appears to modify instance state. You probably want to get an instance to your ViewController class and use that to call the setCity method. Illustrated using the code example above, we can change Bar as such:
class Bar : Foo {
init() {
super.init()
let foo = Foo()
foo.name(1, b: 2)
}
}
Voila, no more error.

SwiftUI:
This error message "extra argument in call" is also shown, when all your code is correct, but the maximum number of views in a container is exceeded (in SwiftUI). The max = 10, so if you have some different TextViews, images and some Spacers() between them, you quickly can exceed this number.
I had this problem and solved it by "grouping" some of the views to a sub container "Group":
VStack {
Text("Congratulations")
.font(.largeTitle)
.fontWeight(.bold)
Spacer()
// This grouping solved the problem
Group {
Text("You mastered a maze with 6 rooms!")
Text("You found all the 3 hidden items")
}
Spacer()
// other views ...
}

In my case calling non-static function from static function caused this error. Changing function to static fixed the error.

This error will ensue, if there is a conflict between a class/struct method, and a global method with same name but different arguments. For instance, the following code will generate this error:
You might want to check if there is such conflict for your setCity method.

You have to call it like this:
ViewController.setCity(city, index: 5)
Swift has (as Objective-C) named parameters.

I have had this error when there is nothing at all wrong with the expression highlighted by the compiler and nothing wrong with the arguments specified, but there is an error on a completely different line somehow linked to the original one. For example: initialising object (a) with objects (b) and (c), themselves initialised with (d) and (e) respectively. The compiler says extra argument on (b), but in fact the error is a type mismatch between the type of (e) and the expected argument to (c).
So, basically, check the whole expression. If necessary, decompose it assigning the parts to temporary variables.
And wait for Apple to fix it.

This can also happen if you have more than 10 views for ViewBuilder arguments in SwiftUI

This is not the direct answer to this question but might help someone.
In my case problem was that class with same name existed in a different (Test) target.
While running Test target I got this error as a new argument was added to init method but was missing in the class in Test target.
Adding the same argument also to other init solved the issue.

In latest Swift 2.2, I had a similar error thrown which took me a while to sort out the silly mistake
class Cat {
var color: String
var age: Int
init (color: String, age: Int) {
self.color = color
self.age = age
}
convenience init (color: String) {
self.init(color: color, age: 1){ //Here is where the error was "Extra argument 'age' in call
}
}
}
var RedCat = Cat(color: "red")
print("RedCat is \(RedCat.color) and \(RedCat.age) year(s) old!")
The fix was rather simple, just removing the additional '{ }' after 'self.init(color: color, age: 1)' did the trick, i.e
convenience init (color: String) {
self.init(color: color, age: 1)
}
which ultimately gives the below output
"RedCat is red and 1 year(s) old!"

Related

Having an VStack as a property in a Struct

I need to have a VStack as a property in a struct like this
struct Str
{
let view: VStack
....
}
The compiler says:
"Reference to generic type 'VStack' requires arguments in <...>
Insert '<<#Content: View#>>'
"
Xcodes "fix" produces:
struct Str
{
let view: VStack<Content: View>
...
}
But the compiler still complains:
"Expected '>' to complete generic argument list"
Is it allowed to have a VStack in a struct?
What you have discovered is that VStack is not really a type. We can more accurately describe it as a “type constructor”. It is declared like this:
struct VStack<Content> where Content : View {
...
}
You give it some other type as its Content argument, and it gives you a type. You give it the type Text and you get back the type VStack<Text>. You give it the type Image and you get back the type VStack<Image>. The types you get back are different types! A object of type VStack<Text> is not an object of type VStack<Image>.
So you just need to know what type to pass as the argument, right? Well, the problem is that lots of SwiftUI “types” are actually generic type constructors. So the type gets complex. Here's an example from an app I'm working on:
var body: some View {
VStack(spacing: 0) {
scene
if store.model.latestError != nil {
Divider()
ErrorView(store: errorStore)
.padding(20)
}
} //
.frame(width: 450)
}
What's the type of body? I can print it at runtime to find out:
print(type(of: AppView(store: store).body))
The output is
ModifiedContent<VStack<TupleView<(AnyView, Optional<TupleView<(Divider, ModifiedContent<ErrorView, _PaddingLayout>)>>)>>, _FrameLayout>
Notice that the type of the object returned by body exposes lots of details about body's implementation. For example, because the ErrorView has a padding modifier, the body object's type includes ModifiedContent<ErrorView, _PaddingLayout>. I can change the padding amount from 20 to 30 without changing the type. But if I remove the padding modifier entirely, it changes the type (by changing ModifiedContent<ErrorView, _PaddingLayout> to just ErrorView).
So how do you solve this? One way is to use AnyView:
struct Str {
let view: AnyView
...
}
let str = Str(view: AnyView(VStack {
...
}))
Note that sometimes you will hear advice that you should avoid AnyView. Here's Joe Groff explaining why:
You can use the AnyView wrapper to explicitly wrap up types where they can dynamically change.
However, the animation system will have an easier time if you can push this down the view graph as far as possible. You could have one Layout type that takes .portrait/.landscape, apply rotation, translation, etc. differently in response, and then the transition can animate

'unresolved identifier' for return value of Type Method in Swift

I'm trying to access the return value from a Type Method in one file from another file. To wit:
file_1:
class LetterView: UIView {
class func testFunction() -> CGSize {
return CGSizeMake(100,200)
}
}
file_2:
class AnotherClass {
func callTestFunction() {
var result = LetterView.testFunction()
print("- breakpoint here - ")
}
}
I get an Unresolved Identifier error on var result if I put a breakpoint in the debugger and do a po result. However if I change the return type of testFunction() to be an Int (say 2) and return that instead, then the function call works as expected. Color me confused.
Is the second file importing UIKit as well? Also, you should update your example from function to func. This all works in the playground which leads to UIKit missing.
There could be a few possible issues.
One of the classes has a Testing target and other one doesn't. You have to even include all of your classes in the testing target or none of them.
If it's Objective C class, check that the class is in ObjectiveC bridging header file.
If it's NSManagedObject subclass. Add #objc(className) before the class declaration.
If it's part of a different framework, make sure that the class or function is public
This is the original answer link : Swift Compiler Error: Use of unresolved identifier 'name'

unwrapping SKPhysicsBody doesn't work

In my project, I create new nodes using a class called RocketMaker. Inside this class, I have a function called applyRecurringForce()...
func applyRecurringForce() {
var thrust: CGVector = CGVectorMake(100, 100)
physicsBody!.applyForce(thrust)
}
My problem is I cannot access this function from the main scene.
override func update(currentTime: NSTimeInterval) {
/* Called before each frame is rendered */
for rocketNode in rocketShips.children {
println("physicsBody: \(rocketNode.physicsBody.description)")
rocketNode.physicsBody.applyRecurringForce()
}
}
Starting with the above code, I get two errors, one for the println, and one for the call to applyRecurringForce().
Approach 1: No forced unwrapping...
1) The println error is "Value of optional type 'SKPhysiceBody' not unwrapped; did you mean to use '!' or '?'?" and proposes I force unwrap
2) The call returns "Cannot invoke 'applyRecurringForce' with no arguments"
Approach2: I add "!" following the suggested solution...
1) The println error is the same as for the previous approach": "Value of optional type 'SKPhysiceBody' not unwrapped; did you mean to use '!' or '?'?" and again it proposes I force unwrap
2) The call returns the same error as previously: "Cannot invoke 'applyRecurringForce' with no arguments"
Approach3: So I follow the chain, using "physicsBody!!" in both lines in the override function. This time, one of the two errors is removed...
1) The println error is gone
2) The call returns "'SKPhysicsBody does not have a member named 'applyRecurringForce'"
If I comment out the call, I get
physicsNodeName: type: representedObject:[ name:'rocket1' position:{56, 294} accumulatedFrame:{{16.849998474121094, 280.20001220703125}, {78.300003051757812, 27.5999755859375}}]
Does anyone have an idea what's up?? This double-unwrapping looks very strange to me.
Well your applyRecurringForce method is declared in your custom node class (RocketMaker), not the SKPhysicsBody class. So you need to change the inside of your for-loop to this:
println("physicsBody: \(rocketNode.physicsBody!.description)")
rocketNode.applyRecurringForce()
Also i'm not really sure what rocketShips is. I originally though it was an array but given that you are accessing the children property i'm going to assume it is some kind of SKNode. Usually you don't want to name a single node plural.
Assuming that rocketShips is a node, then you will need to cast its children to your custom node class because by default children is an array of AnyObject (which is why you see the double unwrapping). See below for full solution. Do note though that i'm casting the entire children array. If your array contains a mix of RocketMaster nodes and other nodes you will need to cast each child separately.
import SpriteKit
class GameScene: SKScene {
var rocketShips: SKNode! //var rocketShips: [RocketMaster] = []
override func update(currentTime: NSTimeInterval) {
/* Called before each frame is rendered */
for rocketNode in rocketShips.children as! [RocketMaster] {
println("physicsBody: \(rocketNode.physicsBody!.description)")
rocketNode.applyRecurringForce()
}
}
}
class RocketMaster: SKNode {
func applyRecurringForce() {
var thrust: CGVector = CGVectorMake(100, 100)
physicsBody!.applyForce(thrust)
}
}

Passing generic struct for unnamed default parameter results in garbage properties

I'm seeing some odd behaviour in a class I created a while ago, where it seems that a struct's properties are changing immediately after being passed (copied) to a method.
I've boiled it down to a simple test case that can be run in a playground:
struct StructToPass<T> {
let x: T
}
class MyClass<T> {
func createAndPassStructWithValue(value: T) {
let structToPass = StructToPass(x: value)
println("Before passing to method: \(structToPass.x)")
passStruct(structToPass)
}
func passStruct(_ theStruct: StructToPass<T>? = nil) {
println("Inside method: \(theStruct!.x)")
}
}
let myClass = MyClass<Int>()
myClass.createAndPassStructWithValue(42)
Looking at the relevant printed statements, it shows that the struct's x property has changed:
// Before passing to method: 42
// Inside method: 140734543799888
Creating the struct outside the class and calling passStruct(_:) directly causes the playground to crash, as does writing passStruct(_:) as a function:
// Causes playground to crash:
let aStruct = StructToPass(x: 42)
myClass.passStruct(aStruct)
// Also causes playground to crash:
func passStruct<T>(_ theStruct: StructToPass<T>? = nil) {}
passStruct(aStruct)
Changing the passStruct(_:) method/function to use the default external parameter name fixes the issue, as does introducing another parameter (before/after the default parameter):
// This works:
func passStruct<T>(theStruct: StructToPass<T>? = nil) {
println("Inside function: \(theStruct!.x)")
}
passStruct(theStruct: aStruct)
// This also works:
func passStruct<T>(_ theStruct: StructToPass<T>? = nil, someOtherParam: Int) {
println("Inside function: \(theStruct!.x)")
}
passStruct(aStruct, 42)
Is this a compiler bug? It seems the compiler doesn't like it when a generic function/method with a single argument with a default value doesn't use an external parameter name. It's a specific case, but I think it ought to work. If it shouldn't work, there ought to be a compiler warning.
110% compiler bug. I've even tried this out of Playground. It all happily compiles until you want to add a line which actually does something, like sending a passStruct. There's all kinds of things wrong with this. I even had this fail:
func passStruct<T>(_ theStruct: StructToPass<T>? = (nil as StructToPass<T>?)) {
println("Inside function: \(theStruct!.x)")
}
which I kinda thought might be the problem (even though it shouldn't be I've had that elsewhere).
Well found! Report it. They're clearly not finished with generics. In my experiments I found that generic class properties aren't allowed.
static let nilStruct: StructToPass<T>? = nil
does not compile, with one of the "not yet supported" error messages.

Swift compiler segmentation fault when building

Adding a (convenient) computed height property to UIView in my UIViewExtension.swift file is causing the Swift compiler to segfault... What could possibly be going wrong here?
0 swift 0x00000001061e5608 llvm::sys::PrintStackTrace(__sFILE*) + 40
1 swift 0x00000001061e5af4 SignalHandler(int) + 452
2 libsystem_platform.dylib 0x00007fff894da5aa _sigtramp + 26
3 libsystem_platform.dylib 0xb03939841e997c88 _sigtramp + 2504775416
4 swift 0x00000001064c8bb9 swift::NominalTypeDecl::getMembers(bool) const + 41
5 swift 0x00000001055efab9 swift::irgen::ClassMetadataLayout<(anonymous namespace)::FindClassMethodIndex>::addClassMembers(swift::ClassDecl*) + 329
6 swift 0x00000001055e97b2 swift::irgen::emitVirtualMethodValue(swift::irgen::IRGenFunction&, llvm::Value*, swift::SILType, swift::SILDeclRef, swift::CanTypeWrapper<swift::SILFunctionType>, swift::ResilienceExpansion) + 434
7 swift 0x00000001056550d3 swift::SILVisitor<(anonymous namespace)::IRGenSILFunction, void>::visit(swift::ValueBase*) + 42611
8 swift 0x000000010564a266 swift::irgen::IRGenModule::emitSILFunction(swift::SILFunction*) + 8678
9 swift 0x00000001055cb6f8 swift::irgen::IRGenModule::emitGlobalTopLevel() + 184
10 swift 0x00000001056376e3 performIRGeneration(swift::IRGenOptions&, swift::Module*, swift::SILModule*, llvm::StringRef, llvm::LLVMContext&, swift::SourceFile*, unsigned int) + 1859
11 swift 0x0000000105638033 swift::performIRGeneration(swift::IRGenOptions&, swift::SourceFile&, swift::SILModule*, llvm::StringRef, llvm::LLVMContext&, unsigned int) + 51
12 swift 0x00000001055aa65a frontend_main(llvm::ArrayRef<char const*>, char const*, void*) + 4842
13 swift 0x00000001055a935d main + 1533
14 libdyld.dylib 0x00007fff8a82e5fd start + 1
 
1. While emitting IR SIL function #_TFCSo6UIViewg6heightSd for 'anonname=0x7ff422892fd0' at <path redacted>/UIViewExtension.swift:60:5
<unknown>:0: error: unable to execute command: Segmentation fault: 11
<unknown>:0: error: swift frontend command failed due to signal (use -v to see invocation)
Command /Applications/Xcode6-Beta.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift failed with exit code 254
If more information is needed to crack this, just comment. Thanks!
Edit:
Here's a related .xcodeproj that returns this question's compiler error. Download here
I had this error because I was doing this :
if(currentMeal?.State == .Deleted){
}
instead of
if(currentMeal!.State == .Deleted){
}
so I think optional not unwrapped in if condition can cause this error
When you run into a compiler segfault in Swift, you don't get a handy line number and error message. Here's how you can track the problem down:
Create a new file called SegFaultDebugger.swift in your project.
In this new file, define an extension to the class that's giving you problems.
Move a group of methods from the main file to SegFaultDebugger.swift.
Compile.
At this point, one of three things happens:
You still get the segfault in the original file: Move the methods from SegFaultDebugger.swift back to the original file and move a different set of methods into SegFaultDebugger.swift. Repeat
You get a segfault in SegFaultDebugger.swift: Great! Now use binary search to pin the segfault down to a specific method until you can figure out what construct is causing it.
You get meaningful compiler errors: Great! Fix the errors. Once everything compiles, move your methods back into the original file.
I got this error while extending one of my protocols and mistyped and optional type argument.
protocol SomeProtocolName: class {
var someProtocolVariable: String { get set }
func someProtocolFunction(someProtocolVariable: String)
}
// MARK:
extension SomeProtocolName {
func someProtocolFunction(someProtocolVariable: String?) {
self.someProtocolVariable = someProtocolVariable
}
}
The difference in function arguments String in prototype and String? in extension caused Segmentation Fault 11.
In Xcode 7, you can click on the error in the Debug Navigator and you'll be shown an expanded view of the crashes. Clicking on the hamburger button on the right expands the error, and if you scroll all the way down to the bottom of the expanded error message, you will see where it comes from.
For me, I had two of those segmentation fault errors. In the picture above, the first one is what it looks like when collapsed, the second is when you expand the hamburger button. At the very bottom of the expanded gray box, you'll see a message that says where the compiler crashed.
Note however that the error message may at times be not informative enough, so while it tells you where it crashed, it doesn't always say why and how to fix it. Getting rid of this error is still very much a matter of guesswork.
I had this error too, and I fixed it like this:
Check your project and find out which files are used twice and remove one, or delete and re-add them all.
Errors in my Xcode:
:0: error: filename "AttributedString.swift" used twice:
'/Users/.../CNJOB/CNJOB/AttributedString.swift' and
'/Users/.../CNJOB/CNJOB/AttributedString.swift'
:0: note: filenames are used to distinguish private
declarations with the same name
:0: error: filename "APIClient.swift" used twice:
'/Users/.../CNJOB/CNJOB/APIClient.swift' and
'/Users/.../CNJOB/CNJOB/APIClient.swift'
:0: note: filenames are used to distinguish private
declarations with the same name
Command /Applications/Xcode
3.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swiftc
failed with exit code 1
I’ve discovered a simple workaround until the problem is fixed in a future Xcode/Swift build:
Simply place all extensions causing the issue in the .swift file that it’s being used.
In the example project you provided, place the contents of UIViewExtension.swift and CALayerExtension.swift above AppDelegate.swift
Hopefully this can get us to write working Swift code until the problem’s cleared up.
As for me, adding private to static var fixed clang crash:
private static var taskId = 0
I had a compiler segmentation fault on a statement like this:
someFunction(isFlagged ? "String1" : "String2")
I just did a if-else statement instead and it works.
This typically happens when the compiler does not have enough information (despite what you think) to guarantee/determine the state of a statement or a variable within a statement.
For example, imagine you have a dictionary of type [String: String] which you populate with city names as keys and a comma separated list of corresponding zip codes/post codes.
Imagine that somewhere in your code you want to update the list of corresponding codes:
myDict[town] += newZipCode + ","
In this case, the compiler will respond with segmentation fault as town might not be in the dictionary and therefore it cannot guarantee that the above statement will have a valid value.
To resolve this, you should store the current state of myDict[town] in a separate variable allowing you to handle the case of key not in dict and then update the value for the given key:
myDict[town] = guaranteedValue + "," newZipCode + ","
Unfortunately, it is not always straightforward to determine the root cause so I hope this simple example helps.
You can also have this problem if you declare a condition with an unwrapped Bool as a property
In my case, a misplaced colon during string interpolation broke mine (XCode 6.1.1).
Example:
println("\(value1:value2)")
when I meant to do:
println("\(value1) : \(value2)")
This error happened to me when I tried to override weak variable from parent class.
In base class:
weak var stripeViewDelegate : StripeViewDelegate? = nil
Derived class:
override weak var stripeViewDelegate : StripeViewDelegate? = nil {
didSet {
self.stripeView.delegate = stripeViewDelegate
}
The error disappeared when I removed =nil from derived class.
I catch some exception today
class func createByAny(instance: Any?) -> ApiCollectionResponse { ... }
and this solved it:
class func createByAny(instance: Any) -> ApiCollectionResponse { ... }
Because "Any" type is any type event "nil", "AnyObject", optional, ... :)
It is cannot be optional, it is already optional.
typealias Any = protocol<>
This error happens also if you accidentally declare a variable with a type matching its name:
var sectionGroup: sectionGroup? { ... }
Ran into this error because of an extraneous generic type on an operator function, e.g.
func ==<T>(lhs: Foo, rhs: Foo) -> Bool {
return lhs.bar == rhs.bar
}
In my case, removing <T> resolved the issue.
In my case I had declared a struct inside a func. Moving the struct to class level solved the issue.
Now that I write this I remember having had issues with struct inside funcs before. It was something else than the segmentation fault (which seems to become notorious with the Swift 1.2 beta). OMG Apple, what are you doing there?
In my case, this error because I use Class name for variable
var MYClass : MYClass {
get {
return.....
}
}
And this fixes my problem
var myClass : MYClass {
get {
return.....
}
}
Im my case, this happened when I did incorrect static initialization in a protocol. I found a way to get around, but a compiler should never produce a segmentation fault while building.
There are three files involved. A protocol NamedSegues.swift, a custom TableViewController that among other things implements the protocol which contains a callback, a custom TableViewCell that holds reference to this protocol to call the callback.
//file1
import Foundation
protocol NamedSegues {
func executeSegueWithId(id: String) -> Void
static func getDefault() -> NamedSegues // This was required because of init requirement in CustomCellView
}
//file2
class CustomController: UITableViewController, NamedSegues {
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier("CustomCellID", forIndexPath: indexPath ) as! CustomCellView
// Configure the cell...
//App logic...
cell.parent = self
}
//Mark: NamedSegues
func executeSegueWithId(id: String) ->() {
NSLog("Received callback to execute segue: \(id)")
//
}
static func getDefault() -> NamedSegues { // I think this must be where it threw up.
return self as! NamedSegues
}
}
//file3
import UIKit
class CustomCellView: UITableViewCell {
var id: String = "NoName"
var parent: NamedSegues = NamedSegues.getDefault() // This is where it was needed.
override func touchesBegan(touches: Set<NSObject>, withEvent event: UIEvent) {
NSLog("Touched id: \(id)")
parent.executeSegueWithId(id) // This is where parent was used.
}
}
I got around it by using ?
In the protocol file, file1: delete the declaration of getDefault()
In the CustomController file2: delete the implementation of getDefault.
In the CustomCellView, file3:
var parent: NamedSegues?
...
parent?.executeSegueWithId(id)
The compiler should have caught this and given some error message instead of throwing a segmentation fault during build!
Seems like the Swift 2 compiler might not have been quite ready for prime-time! In case this helps anyone, I was getting a segmentation fault: 11 due to a mismatch with the variable type in a closure header, specifically in a Parse method, PFQuery.query.findObjectsInBackgroundWithBlock.
You can see the issue in more detail here:
https://github.com/ParsePlatform/Parse-SDK-iOS-OSX/issues/280
Like #Fjohn said, this was an issue related to unwrapping an optional for me (broke in both Xcode 7.0 beta 6 and Xcode 7). In my case, I was not unwrapping optional of the optional (what tipped me off was double ?? in the descriptor. Using if let solved the issue
As others wrote above, for me this happened when I'm using an extension over a protocol but the signature of methods in the protocol don't match the implementations in an extension.
In my case, I had added a new parameter to the implementation (in the extension) but forgot to also add it to the method's signature in the protocol.
in my case, I tried to add a function parameter after a variadic parameter.
Reversing parameter sequence and making the variadic parameter the last parameter in the parameter list fixed it.
Swift 3.0 (Xcode 8.1) exhibits this issue when a protocol declares an optional variable, and an implementer implements that variable as a lazy initialised one.
Bug is reported here:
https://bugs.swift.org/browse/SR-1825
Xcode 8.2.
Adding #nonobjc protocol implementation into extension causing segmentation faults.
Move #nonobjc protocol implementation into class implementation.
In my case the culprit was accidentally overloading a function expecting an array argument with one with a variadic argument:
public required init(_ args: Node...) {
}
When the superclass had it defined as an array:
public required init(_ args: [Node]) {
}
For me the following caused a segfault while type is an optional:
switch type {
case .aType:
// Do Something
default:
break
}
and this solved it:
switch type {
case .Some(.aType):
// Do Something
default:
break
}
I got this error with the following method signature in a custom UITableViewController.
func filterContentForSearchText(searchText: String)
changing to:
func filterContentForSearchText(searchText: String!)
fixed the problem.
I had the same problem in an extension. My extension had two convenience initializers:
convenience init(context: NSManagedObjectContext) {
let entityDescription = NSEntityDescription.entityForName("PropertyEntity", inManagedObjectContext: context)!
self.init(entity: entityDescription, insertIntoManagedObjectContext: context)
}
convenience init(dictionary: NSDictionary, context: NSManagedObjectContext) {
self.init(context: context)
property1 = (dictionary["key"] as? String) ?? ""
// More properties...
}
To get rid of the error I added an instance method map(dictionary: NSDictionary) and the segmentation fault error disappeared.
convenience init(dictionary: NSDictionary, context: NSManagedObjectContext) {
self.init(context: context)
map(dictionary)
}
For me the issue was having my architectures not set to the standard. I had added i386 or something, just set it back to default xcodeproject arch and it compiled fine.
I had the same problem in a swift project. The issue was a function that should have returned an object, but didn't have a return in it. This sort of error used to be signaled while editing with Obj-C. It seems like t isn't the case in Swift.