WordPressSwift 0.3.0

WordPressSwift 0.3.0

Ruben Fernandez 维护。



WordPressSwift

Version License Platform

描述

用法

Example 目录运行示例项目,并查看 CategoryViewController.swiftPostViewController.swift

import WordPressSwift

let wordpress = WordPressSwift()

// Get categories

var myCategories: [WPCategory] = []
wordpress.getCategories(blogURL: "http://myBlog.es") { (categories) in

    self.myCategories = categoriesblogURL
    
    // Write here all that you want to execute after load categories.

}

// Get posts

var myPosts: [WPPost] = []

wordpress.getPosts(blogURL: "http://myBlog.es", page: 1, postPerPage: 5) { (posts) in

    /*
    If you have a blog with many posts, the best way to load it quickly on your app is loading posts by pages. You must enter the page to load (you can use a counter to increment it when you want to load more posts) and postPerPage, which is the number of posts that you want load per each page.
    
    Also you need to provide an integer array to categoryID. You can filter the posts by categories, so you can provide here the IDs of categories to filter (you can access to ID on WPCategory.id). If you want to load all posts, put categoryID to [0].
    */

    self.myPosts = postsblogURL
    
    // Write here all that you want to execute after load categories.

}

// Get featured image of a postafter

var myImage: WPFeaturedImage!

wordpress.featuredImage(blogURL: "http://myBlog.es", post: myPost) { (image) in

    /*
    On post parameter you must provide a post of type: WPPostblogURL
    */

    self.myImage = image
    
    // Write here all that you want to execute after load categories.
    
}

数据类型

public struct WPPost: Codable {

    public struct Title: Codable {
        public let text: String
    }

    public struct Content: Codable {
        public let text: String
        public let protected: Bool
    }

    public struct Excerpt: Codable {
        public let text: String
        public let protected: Bool
    }

    public let id: Int
    public let date: String
    public let date_gmt: String
    public let modified: String
    public let modified_gmt: String
    public let slug: String
    public let status: String
    public let type: String
    public let link: String
    public let title: Title
    public let content: Content
    public let excerpt: Excerpt
    public let author: Int
    public let featured_media: Int
    public let comment_status: String
    public let ping_status: String
    public let sticky: Bool
    public let template: String
    public let format: String
    public let categories: [Int]
    public let tags: [Int]

}

public struct WPCategory: Codable {

    public let id: Int
    public let count: Int
    public let description: String
    public let link: String
    public let name: String
    public let slug: String
    public let taxonomy: String
    public let parent: Int

}

public struct WPFeaturedImage: Codable {

    public struct MediaDetails: Codable {
        public let width: Int
        public let height: Int
        public let file: String
    }

    public let id: Int
    public let image: String
    public let type: String
    public let media_type: String
    public let media_details: MediaDetails

}

安装

WordPressSwift可以通过CocoaPods获得。要安装它,只需将以下行添加到您的Podfile中:

pod 'WordPressSwift'

您还可以将文件WordPressSwift.framework复制到您的项目中。

需求

需要iOS 10.0和Swift 4.0。

作者

我是Ruben Fernandez,邮箱:[email protected],Twitter:@RubenApps

许可

WordPressSwift基于MIT许可。有关更多信息,请参阅LICENSE文件。