小编Gru*_*mme的帖子

Realm中的自动增量ID,Swift 3.0

经过很多麻烦后,我终于将我的代码转换为Swift 3.0.

但似乎我的incrementID功能不再起作用了?

有什么建议我可以解决这个问题吗?

我的incrementID和primaryKey函数就像他们现在看起来一样.

override static func primaryKey() -> String? {
    return "id"
}

func incrementID() -> Int{
    let realm = try! Realm()
    let RetNext: NSArray = Array(realm.objects(Exercise.self).sorted(byProperty: "id")) as NSArray
    let last = RetNext.lastObject
    if RetNext.count > 0 {
        let valor = (last as AnyObject).value(forKey: "id") as? Int
        return valor! + 1
    } else {
        return 1
    }
}
Run Code Online (Sandbox Code Playgroud)

xcode realm ios swift

8
推荐指数
1
解决办法
9546
查看次数

如何使用Apache POI读取特定行?

我正在使用Apache POI库,但我有一些我不想读的数据 - 所以我需要程序开始从特定行读取文件.

我想要来自第10行之后的单元格和行的所有数据,直到文档为空.我尝试过以下代码.

Workbook workbook = new XSSFWorkbook(inputStream);
    Sheet firstSheet = workbook.getSheetAt(0);

    Iterator<Row> iterator = firstSheet.iterator();
    Row getSchool = firstSheet.getRow(10);

    Iterator<Cell> cellIterator = getSchool.cellIterator();

    while (iterator.hasNext())
    {
        while (cellIterator.hasNext())
        {
         ...
        }
    }
Run Code Online (Sandbox Code Playgroud)

但它只会从第10行的单元格中获取所有数据.

我很期待收到你的来信:-).

java apache excel apache-poi

4
推荐指数
1
解决办法
2万
查看次数

为什么我的程序没有停止?

任何人都可以告诉我,当我打y/n时 - 为什么我的比赛没有停止,它只会再次开始.我isDone()在跑步之前调用我的方法,但它只是一遍又一遍地运行.

public class Model {
    int numberToGuess = 29;
    int counter;
    boolean isDone;
    Scanner sc = new Scanner(System.in);

    public Model() {
        isDone = false;
        run();
    }

    public void run() {
        welcomeMessage();
        while (true) {
            guessNumber();
        }
    }

    public void welcomeMessage() {
        System.out.println("Welcome to " + '\n' + "***** GUESS THE NUMBER *****");
    }

    public void guessNumber() {
        System.out.println("Please enter number and hit 'Enter'" + '\n');
        if (sc.hasNextInt()) {
            int input = sc.nextInt();
            counter++;
            if (input < …
Run Code Online (Sandbox Code Playgroud)

java java.util.scanner

2
推荐指数
1
解决办法
103
查看次数

集成领域时出错

我正在尝试将Realm集成到我的iOS应用中,以便数据可以保持持久性。

现在我收到此错误:

由于未捕获的异常'RLMException'而终止应用程序,原因:'属性'sections'被声明为'NSArray',这不是受支持的RLMObject属性类型。所有属性都必须是原语,NSString,NSDate,NSData,NSNumber,RLMArray,RLMLinkingObjects或RLMObject的子类。有关更多信息,请参见 https://realm.io/docs/objc/latest/api/Classes/RLMObject.html。首先抛出调用堆栈:...

有人可以告诉我我在做什么错吗?

持有的对象类sections

class Workout: Object {
  dynamic var image: String = ""
  dynamic var name: String = ""
  dynamic var type: String = ""

  dynamic var sections:[String] = []

  var dayOne = List<Exercise>()
  var dayTwo = List<Exercise>()
  var dayThree = List<Exercise>()
  var dayFour = List<Exercise>()
  var dayFive = List<Exercise>()

  func addExerciseToSection(sectionName: String, exerciseName: Exercise) {
      if sectionName == "Day 1" {
        dayOne.append(exerciseName)
      } else if sectionName == "Day 2" {
        dayTwo.append(exerciseName)
      } else …
Run Code Online (Sandbox Code Playgroud)

realm ios swift

2
推荐指数
1
解决办法
3370
查看次数

标签 统计

ios ×2

java ×2

realm ×2

swift ×2

apache ×1

apache-poi ×1

excel ×1

java.util.scanner ×1

xcode ×1