Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
956 views
in Technique[技术] by (71.8m points)

iphone - Insert a PDF file into Core Data?

I'm using my app to import some PDF files. But I'm trying to insert my PDF file int my database. I'm using Core Data. Is it possible to do this ? If it is, how can I do it ? Which kind of types I have to use (NSData, NSDocument, ... ?)

Thanks you so much! :)

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

To store a PDF (or really any big data blob):

  1. Use the Core Data "binary" type for the attribute, which corresponds to NSData.
  2. In your Core Data model, turn on "Allows External Storage" for the attribute so that Core Data can store the data outside of the persistent store.

It's often better to just write the PDF to a file, and store the filename in your persistent store instead of the whole file.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...