Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

BRAOfficeDocumentPackage undeclared type

Tags:

ios

swift

xcode7

As a Beginner in swift/ios development I am currently trying to install this library https://github.com/renebigot/XlsxReaderWriter in my swift code I followed the steps indicated there for linking a bridging header to swift however BRAOfficeDocumentPackage is still an undeclared type. Is there something not clear or missing in the instructions?

like image 291
Paul Esteban Milan Avatar asked May 26 '16 06:05

Paul Esteban Milan


1 Answers

Here's my attempt at a solution. I had the same problem and determinted that it was due to the bridging header not being read, and being silently skipped.

I solved it this way: wherever I had added "Release" settings, I added the same "Debug" settings.

My steps and demo project are here: https://github.com/joelparkerhenderson/demo_swift_excel_xlsx_reader_writer

I am copying my README.md here so it's searchable here.


Demo Swift Excel Xlsx Reader Writer

XlsxReaderWriter is an Objective-C library that works with Excel OpenXml files (XLSX).

To create this demo

Create a new project.

Get the repository:

git clone --depth=1 https://github.com/renebigot/XlsxReaderWriter.git

We put the repository in the same folder as our demo project's xcodeproject:

Demo Swift Xsls Reader Writer/XlsxReaderWriter

Add XlsxReaderWriter.xcodeproj to your project.

Add dependency:

  • Targets -> Demo -> Build Phases -> Target Dependencies
  • Add XslxReaderWriter -> XslxReaderWriter

Link binaries:

  • Targets -> Demo -> Build Phases -> Link Binaries With Libraries.
  • Add libXlsxReaderWriter.a.
  • Add libz.tbd. This is more current than what the official doc says, which is to add the older version named libz.dylib.

Linking:

  • Project -> Demo -> Build Settings -> Linking -> Other Linker Flags
  • -> (Debug & Release) -> (+) -> Any Architeture | Any SDK
  • Add: -all_load

Search Paths:

  • Project -> Demo -> Build Settings -> Search Paths -> User Header Search Paths
  • -> (Debug & Release) -> (+) -> Any Architecture
  • Set it to: $(SRCROOT)/XlsxReaderWriter/ not $(SRCROOT)/XlsxReaderWriter/XlsxReaderWriter/.
  • Select "recursive".

Bridging Header:

  • Add a new file to Xcode (File > New > File), then select “Source” and click “Header File“.
  • We like the file name Bridge.h
  • Add this text: #import "XlsxReaderWriter-swift-bridge.h"

Add the bridge:

  • Project -> Demo -> Build Settings -> Swift Compiler - Code Generation -> Objective-C Bridging Header
  • -> (Debug & Release) -> (+) -> Any Architecture | Any SDK -> Add: Bridge.h

Verify:

  • Run the project.
  • It should compile and launch a blank simulator.

To load an Excel file

Create an Excel file by using your own Excel software, or any Excel-compatible software.

  • For example, create DemoWorkbook.xlsx and save it in the repository.
  • For example, in the cell A1, type the word "Alpha".

Edit ViewController.swift:

import UIKit

class ViewController: UIViewController {

  override func viewDidLoad() {
    super.viewDidLoad()
    let documentPath: String = NSBundle.mainBundle().pathForResource("DemoWorkbook", ofType: "xlsx")!
    let spreadsheet: BRAOfficeDocumentPackage = BRAOfficeDocumentPackage.open(documentPath)
    let worksheet: BRAWorksheet = spreadsheet.workbook.worksheets[0] as! BRAWorksheet
    let string: String = worksheet.cellForCellReference("A1").stringValue()
    print(string) // The Xcode console should now show the word "Alpha"
  }

  override func didReceiveMemoryWarning() {
    super.didReceiveMemoryWarning()
  }

}

Verify:

  • Run the project.
  • It should compile and launch a blank simulator.
  • The Xcode console should now show the word "Alpha".
like image 119
joelparkerhenderson Avatar answered Oct 05 '22 23:10

joelparkerhenderson