Exported Swift Framework using SwiftyJSON is facing: Terminating app due to uncaught exception





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}







0















I am creating Swift Framework to parse some JSON data to be used in Objective C project and facing this error :



here is my framework code in Swift in addtion to SwiftyJson library



import Foundation

@objc public class parse : NSObject {
public override init() {
}

var Api = "XXXXXXX"

@objc public func parseJSON(){
print("flag")

let requestURL: NSURL = NSURL(string: Api)!
let urlRequest: URLRequest = URLRequest(url: requestURL as URL)
let session = URLSession.shared

let task = session.dataTask(with: urlRequest as URLRequest) { (data, response, error) -> Void in
if data != nil {
do {
let readableJSON = try JSON(data: data!, options: JSONSerialization.ReadingOptions.mutableContainers)
let Name = readableJSON["data"]["buttonText"].stringValue as String!
let buttonTextColor = readableJSON["data"]["buttonTextColorCode"].stringValue as String!
let buttonBackgroundColorCode = readableJSON["data"]["buttonBackgroundColorCode"].stringValue as String!
let visibility = readableJSON["data"]["visibility"].boolValue
let indexURL = readableJSON["data"]["indexURL"].stringValue as String!
let authURL = readableJSON["data"]["authURL"].stringValue as String!
let module = readableJSON["data"]["module"].stringValue as String!
let alignment = readableJSON["data"]["alignment"].stringValue as String!

print("(Name!) n (buttonTextColor!) n (buttonBackgroundColorCode!) n (indexURL!) n (alignment!)")

print("done")
print("Color value:(buttonBackgroundColorCode!)")
} catch {
print(error)
}
}
}

task.resume()
}
}


and here is my project in Objective C :



#import "ViewController.h"

@import JSONFrameWork;
#import <JSONFrameWork/JSONFrameWork-Swift.h>
@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad {
[super viewDidLoad];

[[parse alloc]init];
[[parse alloc]parseJSON];
}

@end


and when I run the code getting the error below, I am suspecting SwiftyJSON is not functioning well in ObjetiveC



*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[NSURL initWithString:relativeToURL:]: nil string parameter'
*** First throw call stack:
(......) libc++abi.dylib: terminating with uncaught exception of type NSException


Note: This framework works fine in Swift project and here is JSON response from API:



{  
"data":{
"buttonText":"u067eu06ccu0634 u0628u06ccu0646u06cc u06a9u0646!",
"buttonTextColorCode":"#000000",
"buttonBackgroundColorCode":"#7ca2d246",
"visibility":true,
"indexURL":"XXXXXX",
"authURL":"XXXXX",
"module":"MATCH_PREDICTION",
"alignment":"RIGHT_TOP",
"marginTop":"10",
"marginLeft":"10",
"marginRight":"10",
"marginBottom":"10",
"allowChannels":[
"22",
"52",
"10"
]
},
"success":true
}









share|improve this question

























  • post the json.......

    – Sh_Khan
    Jan 3 at 13:10











  • you mean the json response ?

    – UncleJunior
    Jan 3 at 13:11











  • yes......................

    – Sh_Khan
    Jan 3 at 13:11











  • question updated .........

    – UncleJunior
    Jan 3 at 13:13






  • 1





    [[parse alloc]init]; [[parse alloc]parseJSON]; That's really strange. I'd do: parse *p = [[parse alloc] init]; [parse parseJSON];. But parse should be named Parse with an uppercase.

    – Larme
    Jan 3 at 13:18


















0















I am creating Swift Framework to parse some JSON data to be used in Objective C project and facing this error :



here is my framework code in Swift in addtion to SwiftyJson library



import Foundation

@objc public class parse : NSObject {
public override init() {
}

var Api = "XXXXXXX"

@objc public func parseJSON(){
print("flag")

let requestURL: NSURL = NSURL(string: Api)!
let urlRequest: URLRequest = URLRequest(url: requestURL as URL)
let session = URLSession.shared

let task = session.dataTask(with: urlRequest as URLRequest) { (data, response, error) -> Void in
if data != nil {
do {
let readableJSON = try JSON(data: data!, options: JSONSerialization.ReadingOptions.mutableContainers)
let Name = readableJSON["data"]["buttonText"].stringValue as String!
let buttonTextColor = readableJSON["data"]["buttonTextColorCode"].stringValue as String!
let buttonBackgroundColorCode = readableJSON["data"]["buttonBackgroundColorCode"].stringValue as String!
let visibility = readableJSON["data"]["visibility"].boolValue
let indexURL = readableJSON["data"]["indexURL"].stringValue as String!
let authURL = readableJSON["data"]["authURL"].stringValue as String!
let module = readableJSON["data"]["module"].stringValue as String!
let alignment = readableJSON["data"]["alignment"].stringValue as String!

print("(Name!) n (buttonTextColor!) n (buttonBackgroundColorCode!) n (indexURL!) n (alignment!)")

print("done")
print("Color value:(buttonBackgroundColorCode!)")
} catch {
print(error)
}
}
}

task.resume()
}
}


and here is my project in Objective C :



#import "ViewController.h"

@import JSONFrameWork;
#import <JSONFrameWork/JSONFrameWork-Swift.h>
@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad {
[super viewDidLoad];

[[parse alloc]init];
[[parse alloc]parseJSON];
}

@end


and when I run the code getting the error below, I am suspecting SwiftyJSON is not functioning well in ObjetiveC



*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[NSURL initWithString:relativeToURL:]: nil string parameter'
*** First throw call stack:
(......) libc++abi.dylib: terminating with uncaught exception of type NSException


Note: This framework works fine in Swift project and here is JSON response from API:



{  
"data":{
"buttonText":"u067eu06ccu0634 u0628u06ccu0646u06cc u06a9u0646!",
"buttonTextColorCode":"#000000",
"buttonBackgroundColorCode":"#7ca2d246",
"visibility":true,
"indexURL":"XXXXXX",
"authURL":"XXXXX",
"module":"MATCH_PREDICTION",
"alignment":"RIGHT_TOP",
"marginTop":"10",
"marginLeft":"10",
"marginRight":"10",
"marginBottom":"10",
"allowChannels":[
"22",
"52",
"10"
]
},
"success":true
}









share|improve this question

























  • post the json.......

    – Sh_Khan
    Jan 3 at 13:10











  • you mean the json response ?

    – UncleJunior
    Jan 3 at 13:11











  • yes......................

    – Sh_Khan
    Jan 3 at 13:11











  • question updated .........

    – UncleJunior
    Jan 3 at 13:13






  • 1





    [[parse alloc]init]; [[parse alloc]parseJSON]; That's really strange. I'd do: parse *p = [[parse alloc] init]; [parse parseJSON];. But parse should be named Parse with an uppercase.

    – Larme
    Jan 3 at 13:18














0












0








0








I am creating Swift Framework to parse some JSON data to be used in Objective C project and facing this error :



here is my framework code in Swift in addtion to SwiftyJson library



import Foundation

@objc public class parse : NSObject {
public override init() {
}

var Api = "XXXXXXX"

@objc public func parseJSON(){
print("flag")

let requestURL: NSURL = NSURL(string: Api)!
let urlRequest: URLRequest = URLRequest(url: requestURL as URL)
let session = URLSession.shared

let task = session.dataTask(with: urlRequest as URLRequest) { (data, response, error) -> Void in
if data != nil {
do {
let readableJSON = try JSON(data: data!, options: JSONSerialization.ReadingOptions.mutableContainers)
let Name = readableJSON["data"]["buttonText"].stringValue as String!
let buttonTextColor = readableJSON["data"]["buttonTextColorCode"].stringValue as String!
let buttonBackgroundColorCode = readableJSON["data"]["buttonBackgroundColorCode"].stringValue as String!
let visibility = readableJSON["data"]["visibility"].boolValue
let indexURL = readableJSON["data"]["indexURL"].stringValue as String!
let authURL = readableJSON["data"]["authURL"].stringValue as String!
let module = readableJSON["data"]["module"].stringValue as String!
let alignment = readableJSON["data"]["alignment"].stringValue as String!

print("(Name!) n (buttonTextColor!) n (buttonBackgroundColorCode!) n (indexURL!) n (alignment!)")

print("done")
print("Color value:(buttonBackgroundColorCode!)")
} catch {
print(error)
}
}
}

task.resume()
}
}


and here is my project in Objective C :



#import "ViewController.h"

@import JSONFrameWork;
#import <JSONFrameWork/JSONFrameWork-Swift.h>
@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad {
[super viewDidLoad];

[[parse alloc]init];
[[parse alloc]parseJSON];
}

@end


and when I run the code getting the error below, I am suspecting SwiftyJSON is not functioning well in ObjetiveC



*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[NSURL initWithString:relativeToURL:]: nil string parameter'
*** First throw call stack:
(......) libc++abi.dylib: terminating with uncaught exception of type NSException


Note: This framework works fine in Swift project and here is JSON response from API:



{  
"data":{
"buttonText":"u067eu06ccu0634 u0628u06ccu0646u06cc u06a9u0646!",
"buttonTextColorCode":"#000000",
"buttonBackgroundColorCode":"#7ca2d246",
"visibility":true,
"indexURL":"XXXXXX",
"authURL":"XXXXX",
"module":"MATCH_PREDICTION",
"alignment":"RIGHT_TOP",
"marginTop":"10",
"marginLeft":"10",
"marginRight":"10",
"marginBottom":"10",
"allowChannels":[
"22",
"52",
"10"
]
},
"success":true
}









share|improve this question
















I am creating Swift Framework to parse some JSON data to be used in Objective C project and facing this error :



here is my framework code in Swift in addtion to SwiftyJson library



import Foundation

@objc public class parse : NSObject {
public override init() {
}

var Api = "XXXXXXX"

@objc public func parseJSON(){
print("flag")

let requestURL: NSURL = NSURL(string: Api)!
let urlRequest: URLRequest = URLRequest(url: requestURL as URL)
let session = URLSession.shared

let task = session.dataTask(with: urlRequest as URLRequest) { (data, response, error) -> Void in
if data != nil {
do {
let readableJSON = try JSON(data: data!, options: JSONSerialization.ReadingOptions.mutableContainers)
let Name = readableJSON["data"]["buttonText"].stringValue as String!
let buttonTextColor = readableJSON["data"]["buttonTextColorCode"].stringValue as String!
let buttonBackgroundColorCode = readableJSON["data"]["buttonBackgroundColorCode"].stringValue as String!
let visibility = readableJSON["data"]["visibility"].boolValue
let indexURL = readableJSON["data"]["indexURL"].stringValue as String!
let authURL = readableJSON["data"]["authURL"].stringValue as String!
let module = readableJSON["data"]["module"].stringValue as String!
let alignment = readableJSON["data"]["alignment"].stringValue as String!

print("(Name!) n (buttonTextColor!) n (buttonBackgroundColorCode!) n (indexURL!) n (alignment!)")

print("done")
print("Color value:(buttonBackgroundColorCode!)")
} catch {
print(error)
}
}
}

task.resume()
}
}


and here is my project in Objective C :



#import "ViewController.h"

@import JSONFrameWork;
#import <JSONFrameWork/JSONFrameWork-Swift.h>
@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad {
[super viewDidLoad];

[[parse alloc]init];
[[parse alloc]parseJSON];
}

@end


and when I run the code getting the error below, I am suspecting SwiftyJSON is not functioning well in ObjetiveC



*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[NSURL initWithString:relativeToURL:]: nil string parameter'
*** First throw call stack:
(......) libc++abi.dylib: terminating with uncaught exception of type NSException


Note: This framework works fine in Swift project and here is JSON response from API:



{  
"data":{
"buttonText":"u067eu06ccu0634 u0628u06ccu0646u06cc u06a9u0646!",
"buttonTextColorCode":"#000000",
"buttonBackgroundColorCode":"#7ca2d246",
"visibility":true,
"indexURL":"XXXXXX",
"authURL":"XXXXX",
"module":"MATCH_PREDICTION",
"alignment":"RIGHT_TOP",
"marginTop":"10",
"marginLeft":"10",
"marginRight":"10",
"marginBottom":"10",
"allowChannels":[
"22",
"52",
"10"
]
},
"success":true
}






objective-c swift frameworks swifty-json






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Jan 3 at 15:49









Yannick Loriot

6,37622851




6,37622851










asked Jan 3 at 13:07









UncleJuniorUncleJunior

81110




81110













  • post the json.......

    – Sh_Khan
    Jan 3 at 13:10











  • you mean the json response ?

    – UncleJunior
    Jan 3 at 13:11











  • yes......................

    – Sh_Khan
    Jan 3 at 13:11











  • question updated .........

    – UncleJunior
    Jan 3 at 13:13






  • 1





    [[parse alloc]init]; [[parse alloc]parseJSON]; That's really strange. I'd do: parse *p = [[parse alloc] init]; [parse parseJSON];. But parse should be named Parse with an uppercase.

    – Larme
    Jan 3 at 13:18



















  • post the json.......

    – Sh_Khan
    Jan 3 at 13:10











  • you mean the json response ?

    – UncleJunior
    Jan 3 at 13:11











  • yes......................

    – Sh_Khan
    Jan 3 at 13:11











  • question updated .........

    – UncleJunior
    Jan 3 at 13:13






  • 1





    [[parse alloc]init]; [[parse alloc]parseJSON]; That's really strange. I'd do: parse *p = [[parse alloc] init]; [parse parseJSON];. But parse should be named Parse with an uppercase.

    – Larme
    Jan 3 at 13:18

















post the json.......

– Sh_Khan
Jan 3 at 13:10





post the json.......

– Sh_Khan
Jan 3 at 13:10













you mean the json response ?

– UncleJunior
Jan 3 at 13:11





you mean the json response ?

– UncleJunior
Jan 3 at 13:11













yes......................

– Sh_Khan
Jan 3 at 13:11





yes......................

– Sh_Khan
Jan 3 at 13:11













question updated .........

– UncleJunior
Jan 3 at 13:13





question updated .........

– UncleJunior
Jan 3 at 13:13




1




1





[[parse alloc]init]; [[parse alloc]parseJSON]; That's really strange. I'd do: parse *p = [[parse alloc] init]; [parse parseJSON];. But parse should be named Parse with an uppercase.

– Larme
Jan 3 at 13:18





[[parse alloc]init]; [[parse alloc]parseJSON]; That's really strange. I'd do: parse *p = [[parse alloc] init]; [parse parseJSON];. But parse should be named Parse with an uppercase.

– Larme
Jan 3 at 13:18












0






active

oldest

votes












Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54022930%2fexported-swift-framework-using-swiftyjson-is-facing-terminating-app-due-to-unca%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes
















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54022930%2fexported-swift-framework-using-swiftyjson-is-facing-terminating-app-due-to-unca%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

MongoDB - Not Authorized To Execute Command

How to fix TextFormField cause rebuild widget in Flutter

in spring boot 2.1 many test slices are not allowed anymore due to multiple @BootstrapWith