Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- struct JournalDocument: FileDocument {
- static var readableContentTypes: [UTType] { [.plainText] }
- var journal: String
- init(journal: String) {
- self.journal = journal
- }
- init(configuration: ReadConfiguration) throws {
- guard let data = configuration.file.regularFileContents,
- let string = String(data: data, encoding: .utf8)
- else {
- throw CocoaError(.fileReadCorruptFile)
- }
- journal = string
- }
- func fileWrapper(configuration: WriteConfiguration) throws -> FileWrapper {
- return FileWrapper(regularFileWithContents: journal.data(using: .utf8)!)
- }
- }
- struct JournalView: View {
- @State private var document: JournalDocument = JournalDocument(journal: "DART Meadow Articren Journal")
- @State private var isImporting: Bool = false
- @State private var isExporting: Bool = false
- @State var diameter = Double()
- @State var radicalsize = Double()//Input
- @State var radicalcircumference = Double()//Input
- @State var radicalarea = Double()//Input
- @State var radicalvolume = Double()//Input
- @State var circumferencearea = Double()//Input
- @State var quartervolume = Double()//Input
- @State var circumference = Double()
- @State var circlearea = Double()
- @State var volume = Double()
- @State var spheresurface = Double()
- @State var trimorbitlocationsqaured = Double()
- @State var trimorbitlocationcubed = Double()
- @State var orbitlocationexponentsquared = Double()
- @State var orbitlocationareaexponentsqaured = Double()
- @State var radicalsizeedgesq = Double()
- @State var radicalsizeedgecb = Double()
- let formatter: NumberFormatter = {
- let formatter = NumberFormatter()
- formatter.numberStyle = .scientific
- formatter.positiveFormat = "0.###E+0"
- formatter.exponentSymbol = "e"
- return formatter
- }()
- func diameter(diameterresult: Double) -> Double { pow(sqrt(radicalsize * 3), 2) }
- func circumference(circumferenceresult: Double) -> Double { pow(pow(sqrt(radicalcircumference * 3), 2), 2) }
- func circlearea(circlearearesult: Double) -> Double { pow(pow(sqrt(radicalarea * 3), 2), 3) }
- func volume(volumeresult: Double) -> Double { pow(pow(pow(sqrt(radicalvolume * 3), 2), 3), 2) }
- func spheresurface(spheresurfaceresult: Double) -> Double{ pow(pow(pow(sqrt(quartervolume * 3), 2), 3), 2) - pow(pow(sqrt(quartervolume * 3), 2), 3) }
- func trimorbitlocationsqaured(trimorbitlocationsqauredresult: Double) -> Double { (pow(2, sqrt(1 * 0.25)) + radicalsizeedgesq) - 1 }
- func trimorbitlocationcubed(trimorbitlocationcubedresult: Double) -> Double { ((2 / (cbrt(1 * 2))) + radicalsizeedgecb) - 1 }
- var body: some View{
- HStack(alignment: .center) {
- VStack(alignment: .center) {
- Text("Journal")
- .font(.largeTitle)
- .bold()
- //.colorInvert()
- .shadow(radius: 3)
- }
- HStack(alignment: .bottom) {
- VStack(alignment: .center) {
- Image("DARTEdge256")
- .shadow(radius: 3)
- }
- }
- }.padding(.top, 10)
- Divider()
- ScrollView(.vertical) {
- VStack {
- GroupBox(label: Text("Journal Entry:").font(.callout)
- .bold())
- {
- TextEditor(text: $document.journal)
- .frame(width: 690, height: 400, alignment: .center)
- Text("Sigcothian Squared: (Electron | Diameter):")
- .font(.callout)
- .bold()
- // .colorInvert()
- TextField("#", value: self.$radicalsizeedgesq, formatter: formatter)
- //.colorInvert()
- .textFieldStyle(RoundedBorderTextFieldStyle())
- .overlay(
- RoundedRectangle(cornerRadius: 6)
- .stroke(Color.blue, lineWidth: 2)
- )
- Text("Sigcothian Squared Unit(s): \(trimorbitlocationsqaured(trimorbitlocationsqauredresult: radicalsizeedgesq))")
- .font(.callout)
- .bold()
- .frame(width: 150, height: 60, alignment: .leading)
- //.colorInvert()
- }
- GroupBox {
- HStack {
- Spacer()
- Button(action: { isImporting = true }, label: {
- Text("Import")
- })
- Spacer()
- Button(action: { isExporting = true }, label: {
- Text("Export")
- })
- Spacer()
- }
- }
- }
- .padding()
- .fileExporter(
- isPresented: $isExporting,
- document: document,
- contentType: .plainText,
- defaultFilename: "Articren Journal"
- ) { result in
- if case .success = result {
- // Handle success.
- } else {
- // Handle failure.
- }
- }
- .fileImporter(
- isPresented: $isImporting,
- allowedContentTypes: [.plainText],
- allowsMultipleSelection: false
- ) { result in
- do {
- guard let selectedFile: URL = try result.get().first else { return }
- guard let journal = String(data: try Data(contentsOf: selectedFile), encoding: .utf8) else { return }
- document.journal = journal
- } catch {
- // Handle failure.
- }
- }
- }.frame(width: 900, height: 670, alignment: .center).padding(10)
- //.background(Color.white)
- Spacer()
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement