Error when migrating from swift 2.3 to swift 3 - swift

I just want to try Swift 3.0 in one of my projects and It is working fine in Swift 2.Xcode Version 8.3.1
Everything I fixed but getting error in FXForm library.Below is the error I am getting at the time of project compilation:
"_OBJC_CLASS_$__TtCC13Test11AppDelegate15FXFormVariables", referenced from:
objc-class-ref in FXForms.o
error: linker command failed with exit code 1 (use -v to see invocation)
I had passed the logged in user validation from App delegate like below:
//objective C class
#objc class loggedinUser : NSObject {
class func isUserLoggedIn() -> Bool { return userLoggedin! }
}
and used it in Objective-C class of FXForm like below:
if([loggedinUser isUserLoggedIn] == true){
// default to bottom
return CGPointMake(self.bounds.size.width/2, (self.bounds.size.height - (toast.frame.size.height / 2)) - style.verticalPadding - 120);
}
Please help in fixing the above error and thanks in advance.

This isn't a Swift 2 to Swift 3 refactoring problem.
It's a problem where you need to make sure the FXForms .m file is being compiled in your project. Do you include the .h & .m files in your project?
Go to the file inspector (the list of files in the left side) of your Xcode window, click on the FXForms.m file and make sure "Target Membership" is checked, like in the right red circle of this screenshot:

Related

Xcode iOS app build fails due to MXSendReplyEventStringLocalizer protocol

I'm an Xcode newbie. I'm using non-modified Swift source code from the Github project that is 100% working itself as it's released to public.
I installed pods for it.
When trying to build this non-modified testing app in xCode, it fails with:
MXKSendReplyEventStringLocalizer.swift:19:7 Type 'MXKSendReplyEventStringLocalizer' does not conform to protocol 'MXSendReplyEventStringLocalizerProtocol'
As the code itself should be working out of the box, I suppose the issue is caused by my Mac's environment.
if I select "Fix" in the problematic code block (adding protocol stubs offered by Xcode), this error disappears on the next build attempt, but new ones appear, I. believe because the placeholder was set by selecting "Fix" previously.
Command SwiftEmitModule failed with a nonzero exit code
About this code:
_class MXKSendReplyEventStringLocalizer: NSObject, MXSendReplyEventStringLocalizerProtocol {
func replyToEndedPoll() -> String {
<#code#>
}
Any advise what direction to investigate is appreciated. Searching other threads related to MXSendReplyEventStringLocalizer didn't help.
Here is the problematic code block** that is highlighted by Xcode on the initial build:
import Foundation
class MXKSendReplyEventStringLocalizer: NSObject, MXSendReplyEventStringLocalizerProtocol {
func senderSentAnImage() -> String {
VectorL10n.messageReplyToSenderSentAnImage
}
func senderSentAVideo() -> String {
VectorL10n.messageReplyToSenderSentAVideo
}

How to resolve Abort trap: 6 ERROR - xcode 12

We have faced the issue of "abort trap 6" in Xcode 12. Due to this reason app not running using Xcode 12. We are using the swift 5 versions and jsqmessageviewcontroller objective c library.
Below errors getting in Xcode 12.
<unknown>:0: error: fatal error encountered while reading from module 'wwww'; please file a bug report with your project and the crash log
<unknown>:0: note: module 'wwww' full misc version is '5.3.2(5.3.2)/Apple Swift version 5.3.2 (swiftlang-1200.0.45 clang-1200.0.32.28)'
top-level value not found
Cross-reference to module 'JSQMessagesViewController'
... JSQMessageMediaData
error: Abort trap: 6 (in target 'zapwww' from project 'zapwww')
If anyone has a solution please help us.
I had the same error in Xcode 12.5.1 and it seems to be a bug that has been fixed in the next beta. However there seem to be several issues that could cause this error. So my solution might not work.
For me the problem was very specific and only happened in the following scenario:
A method that returns an optional RealmObject (might be different in your case) is called.
The returned RealmObject has been assigned a variable.
Trying to unwrap the variable with guard let or if let using the same name for the new safely unwrapped variable.
The easiest fix is using different variable names or
Safely unwrapping the returned object directly without assigning it a variable.
Example that causes the error in my case:
class MyClass {
func returnObject() -> Object? {
return nil
}
func anyMethod() {
let myObject = returnObject()
guard let myObject = myObject else { return } // <-- works anywhere else but here.
}
}
Same example that fixed the error in my case:
class MyClass {
func returnObject() -> Object? {
return nil
}
func anyMethod() {
let myObject = returnObject()
guard let myNewObject = myObject else { return } // <-- Changed name of new variable here
}
}
I've seen people had this issue with other types, so it's not limited to the RealmObject type. But going through all guard let or if let with the same variable name is a good start.
I've also seen other people use fix it by cleaning the build folder or removing packages and reinstalling them. That didn't help for me though.
Problem: Abort Trap (In my case my code is working perfectly but when I trying to make an Archive file I got the "Abort Trap")
Solution:- Just Select Your Project from project Navegater (most Left Pane) Select Project > Select Targets > Build Settings > Swift Compiler - Code Genration > Optimization Level > Debug and Realease make "No Optimization [-Onone]"enter image description here
Flutter Specific
I had to set Optimization Level to No Optimization [-Onone] for Pods target.
Just Select Your Project from project Navigater (most Left Pane) Select
Pods > Build Settings > Swift Compiler - Code Generation > Optimization Level > Debug and Realease make No Optimization [-Onone]
for me i have just remove the library which cause the problem from pods file , then installed again will fix the problem
just had to run: 'pod update' to update my Realm pods and fixed it for me.

Can't run XCTest for a Cocoa Framework with SwiftyJSON dependency

I am building a dynamic Cocoa Framework (let's say MyFrame) using Swift 1.2 and Xcode 6.4.
I am using SwiftyJSON as a linked framework in MyFrame after downloading it using Carthage. It builds and runs perfectly.
I wrote unit tests in a XCTestCase. The testing target is MyFrameTests. It works perfectly as long as MyFrame does not use SwiftyJSON. When I add SwiftyJSON in MyFrame, I get the following error:
2015-08-25 18:22:25.653 xctest[17732:237778] The test bundle at /Users/manonh/try16/MyFrame/DerivedData/MyFrame/Build/Products/Debug-iphonesimulator/MyFrameTests.xctest could not be loaded because an unanticipated error occurred.
2015-08-25 18:22:25.654 xctest[17732:237778] Detailed error information: Error Domain=NSCocoaErrorDomain Code=3587 "The bundle “MyFrameTests” couldn’t be loaded because it is damaged or missing necessary resources." (dlopen_preflight(/Users/manonh/try16/MyFrame/DerivedData/MyFrame/Build/Products/Debug-iphonesimulator/MyFrameTests.xctest/MyFrameTests): Library not loaded: #rpath/SwiftyJSON.framework/SwiftyJSON
Referenced from: /Users/manonh/try16/MyFrame/DerivedData/MyFrame/Build/Products/Debug-iphonesimulator/MyFrameTests.xctest/MyFrameTests
Reason: image not found) UserInfo=0x7f8e13705070 {NSLocalizedFailureReason=The bundle is damaged or missing necessary resources., NSLocalizedRecoverySuggestion=Try reinstalling the bundle., NSFilePath=/Users/manonh/try16/MyFrame/DerivedData/MyFrame/Build/Products/Debug-iphonesimulator/MyFrameTests.xctest/MyFrameTests, NSDebugDescription=dlopen_preflight(/Users/manonh/try16/MyFrame/DerivedData/MyFrame/Build/Products/Debug-iphonesimulator/MyFrameTests.xctest/MyFrameTests): Library not loaded: #rpath/SwiftyJSON.framework/SwiftyJSON
Referenced from: /Users/manonh/try16/MyFrame/DerivedData/MyFrame/Build/Products/Debug-iphonesimulator/MyFrameTests.xctest/MyFrameTests
Reason: image not found, NSBundlePath=/Users/manonh/try16/MyFrame/DerivedData/MyFrame/Build/Products/Debug-iphonesimulator/MyFrameTests.xctest, NSLocalizedDescription=The bundle “MyFrameTests” couldn’t be loaded because it is damaged or missing necessary resources.}
*** Test session exited(1) without checking in. If you believe this error represents a bug, please attach the log file at /var/folders/9g/jxyyssdx0xn9xp_29fg2l9080000gq/T/com.apple.dt.XCTest-status/Session-2015-08-25_18:22:25-2wDwFh.log
I googled this and found some things about defines module and other options in Build Settings > Packaging. Did not work.
I have tried to add import SwiftyJSON inside the test swift file. Did not work
I also tried to put SwiftyJSON in Copy Bundle Resource in MyFrame. Did not work
In MyFrameTests, I tried to add SwiftyJSON in Link Binary With Libraries and Copy Bundle Resource. I tried all the combinations of the above "locations" of SwiftyJSON framework. Did not work
After 2 days of struggling and googling and reading other stackoverflow posts, I haven't found a way to run this test.
Is there anyone that knows how to unit test a cocoa framework that has a dependency?
Thanks in advance for the help!
Below is the very basic class I want to test in MyFrame and the testcase in MyFrameTests, if it can be of any use.
MyFrameClass.swift
import Foundation
import SwiftyJSON
public class MyFrameClass {
public init() {}
public func getFive() -> Int {
return 5
}
}
MyFrameTests.swift
import UIKit
import XCTest
import MyFrame
class test18Tests: XCTestCase {
override func setUp() {
super.setUp()
}
override func tearDown() {
super.tearDown()
}
func testExample() {
XCTAssert(true, "Pass")
}
func testExample2() {
var c = MyFrameClass()
XCTAssertEqual(c.getFive(), 5, "Five test of MyFrameClass")
}
func testPerformanceExample() {
// This is an example of a performance test case.
self.measureBlock() {
// Put the code you want to measure the time of here.
}
}
}
Just remove import SwiftyJSON from MyFrameClass.swift and it works like a charm.
I had a similar (not exactly the same though) problem. My swiftyJSON was installed using cocoa pods.
I then removed it form cocoa pods and installed the file manually in my project and that solved the problem. I know I have to manually update that file now, but since it hasn't any dependencies on other frameworks that's fairly easy and a small price to pay
Copy the xcodeproj from SwiftyJSON inside your workspace
In the buildPhase/link binary with libraries from the test target, add "SwiftyJSON" clicking + and choose from the workspace
(you must have the cocoa framework there + the SwiftyJSON framework there)
Command B
Command U

Use of Undeclared Type 'AVCamViewController'

I'm new to the coding industry and am seriously struggling with Swift. I have a situation where I want to go from one page to another, but I keep getting an error of "use of undeclared type AVCamViewController. This is my code:
#IBAction func goToApp(sender : AnyObject) {
let AVCam = self.storyboard.instantiateViewControllerWithIdentifier("AVCam") as? AVCamViewController.h
self.navigationController.pushViewController(AVCam, animated: true)
}
And if I try to import the AVCamViewController or AVCamViewController.h or AVCamViewController.m, I get an error of 'no such module'.
I have have all the files of the AVCam application in my app so I am not sure what to do. Any advice please?
You need to remove .h from line when you instantiate vc:
let AVCam = self.storyboard.instantiateViewControllerWithIdentifier("AVCam") as? AVCamViewController
AVCamViewController.h is file name but you need class name which is AVCamViewController
Do you have a bridging header set up? If AVCamViewController is a system class, you have to #import the right framework, i.e. #import AVFoundation. Otherwise, you have to create a header specifically for use as a bridge from Objective C to Swift. In said header, you include your own headers that you want Swift to see. You will have to set the build settings to point to the new header. If you added a new Swift class/file, Xcode should have asked if it could create one automatically. If you do have one, you can put your header imports/includes into that file.

Accessing private variable from Category generates linker error

I have the following code:
#interface UIAcceleration (Simulation)
- (id) initWithTimestamp:(NSTimeInterval)aTimeStamp
X:(UIAccelerationValue)ax
Y:(UIAccelerationValue)ay
Z:(UIAccelerationValue)az;
#end
#implementation UIAcceleration (Simulation)
-(id)initWithTimestamp:(NSTimeInterval)aTimeStamp
X:(UIAccelerationValue)ax
Y:(UIAccelerationValue)ay
Z:(UIAccelerationValue)az
{
if (self = [super init])
{
timestamp = aTimeStamp;
x = ax;
y = ay;
z = az;
}
return self;
}
#end
when compiling this for simulator SDK everything works fine. When compiling for device SDK I get the following linker error:
"_OBJC_IVAR_$_UIAcceleration.x", referenced from:
_OBJC_IVAR_$_UIAcceleration.x$non_lazy_ptr in UIAcceleration+IRowAdditions.o
"_OBJC_IVAR_$_UIAcceleration.y", referenced from:
_OBJC_IVAR_$_UIAcceleration.y$non_lazy_ptr in UIAcceleration+IRowAdditions.o
"_OBJC_IVAR_$_UIAcceleration.z", referenced from:
_OBJC_IVAR_$_UIAcceleration.z$non_lazy_ptr in UIAcceleration+IRowAdditions.o
"_OBJC_IVAR_$_UIAcceleration.timestamp", referenced from:
_OBJC_IVAR_$_UIAcceleration.timestamp$non_lazy_ptr in AccelerometerSimulation.o
ld: symbol(s) not found
collect2: ld returned 1 exit status
What am I doing wrong? What is different between linking against Simulator frameworks (namely UIKit) and linking against device frameworks?
I think you probably included only the simulator version of the UIKit framework. I'm not so sure about this, but go to the left pane in Xcode and under the Frameworks folder, right click on UIKit.framework and Get Info. On mine, the path is /System/Library/Frameworks/UIKit.framework and right under that it says Path Type: "Relative to Current SDK". That should automatically pull the correct framework depending on what you're building for.
Worth a check.
This may be related to this issue with categories on the iPhone. Try adding -ObjC (iPhone OS 2.x) and -all_load (iPhone OS 3.0) to your "Other Linker Flags".
Ok, as none of the answers given helped, I did something diferent.
I created a class with exactly the same interface as UIAcceleration. Because both of them have the same memory layout, I can safely cast between pointers of UIAcceleration and my class. At least as long as gcc wants.