How to access a Cocoa Touch Framework module in the Swift Playground

2

I created a Cocoa Touch Framework module in Xcode 6.0.1 with Class implemented in Swift and I get it imported into my View Controller and use it normally. The problem is that I can not use the same code in the Playground created in the same project.

In Playground the module is recognized but the class contained in it is not.

My class is declared in JSON.swift like this:

public class JSON {
    // meu código Swift 
}
    
asked by anonymous 05.10.2014 / 17:15

2 answers

1

Try this on your% s Playground

import Foundation
let jsonObject: [AnyObject] = [
  ["name": "João", "age": 20],
  ["name": "Pedro", "age": 45],
]
func JSONStringify(jsonObj: AnyObject) -> String {
  var e: NSError?
  let jsonData: NSData! = NSJSONSerialization.dataWithJSONObject(
    jsonObj,
    options: NSJSONWritingOptions(0),
    error: &e)
  if e != nil {
    return ""
  } else {
    return NSString(data: jsonData, encoding: NSUTF8StringEncoding)
  }
}
let jsonString = JSONStringify(jsonObject)
println(jsonString)

It works on Mavericks

This works because you are delegating the serialization job to class Xcode 6.0.1 of standard library

That is, your Swift code is just a Wrapper.

Deserialization can also be done in an analogous way.

    
14.10.2014 / 21:20
-1

By default, classes have internal visibility. It is only necessary to put the class as public and you already have access.

public class Foo {
    public init() {
    }
}
    
09.10.2014 / 14:20